Swagger-parser is a python module giving you access to some interesting data about your swagger file. Like getting a dictionary example from a definition name, get the definition of a dictionary, and more.
You may find related libraries to this one:
- https://github.com/Trax-air/swagger-tester: Auto-test your swagger API in your unit tests. All test calls are generated by your swagger file.
- https://github.com/Trax-air/swagger-stub: A stub you can use in your client's unit tests. All the HTTP calls to your swagger API are mocked by default. You can also add your own mocked_calls in your test functions.
- https://github.com/Trax-air/swagger-aggregator: Aggregate several swagger specs into one. Useful for your API gateways!
from swagger_parser import SwaggerParser
parser = SwaggerParser(swagger_path='swagger_path') # Init with file
parser = SwaggerParser(swagger_dict={}) # Init with dictionary
# Get an example of dict for the definition Foo
parser.definitions_example.get('Foo')
# Get the definition of a dictionary
test = {
'foo': 'bar'
}
parser.get_dict_definition(test)
# Validate the definition of a dict
parser.validate_definition('Foo', test)
# Validate that the given data match a path specification
parser.validate_request('/foo', 'post', body=test, query={'foo': 'bar'})
# Get the possible return value of a path
# It will return a dictionary with keys as status_code
# and value as example of return value.
parser.get_request_data('/foo', 'post', body=test)
# Get an example of a correct body for a path
parser.get_send_request_correct_body('/foo', 'post')
More documentation is available at https://swagger-parser-fork.readthedocs.org/en/latest/.
pip install swagger-parser
(only for the original version)
This repository contains my own fork of the package with some basic changes:
- Fix compatibility with recent Python versions and drop Python 2 compatibility code.
- Avoid pinning pyyaml on some old beta version.
- Add CI based upon GitHub Actions to run the tests and linting automatically.
For now, I do not have any direct plans to send a corresponding PR due to the upstream repository not appearing really maintained.
swagger-parser is licensed under http://opensource.org/licenses/MIT.