Welcome to Swagger Parser’s documentation!¶
Contents:
swagger-parser¶
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.
Example Usage¶
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')
Documentation¶
More documentation is available at https://swagger-parser.readthedocs.org/en/latest/.
Setup¶
make install or pip install swagger-parser
License¶
swagger-parser is licensed under http://opensource.org/licenses/MIT.
Installation¶
At the command line:
$ easy_install swagger_parser
Or, if you have virtualenvwrapper installed:
$ mkvirtualenv swagger_parser
$ pip install swagger_parser
Usage¶
To use Swagger Parser in a project:
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')
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/cyprieng/swagger_parser/issues.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “feature” is open to whoever wants to implement it.
Write Documentation¶
Swagger Parser could always use more documentation, whether as part of the official Swagger Parser docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/cyprieng/swagger_parser/issues.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up swagger_parser for local development.
Fork the swagger_parser repo on GitHub.
Clone your fork locally:
$ git clone git@github.com:your_name_here/swagger_parser.git
Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:
$ mkvirtualenv swagger_parser $ cd swagger_parser/ $ python setup.py develop
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:
$ flake8 swagger_parser tests $ python setup.py test $ tox
To get flake8 and tox, just pip install them into your virtualenv.
Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Your detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.rst.
- The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check https://travis-ci.org/cyprieng/swagger_parser/pull_requests and make sure that the tests pass for all supported Python versions.
Credits¶
Development Lead¶
- Cyprien Guillemot <cyprien.guillemot@gmail.com>
Contributors¶
None yet. Why not be the first?
History¶
1.0.0 (2017-6-11)¶
- Drop support for python 2.6, add support for python 3.5, python 3.6 and pypy
- Fix issue #35
- Add file parser tests and fixes for #40, #41, #42, #43, #44, #45, thanks to @mtherieau
- Use isinstance for simple type checking, thanks to @pankaj28843
- Fixes for #31, #32, #33, thanks to @crudo10 and @beanqueen for the review
- Bug fix when dictionary only contains 1 element, thanks to @TenOs
- Add tests for “official” petstore json and yaml, thanks to @beanqueen
0.1.11 (2016-9-25)¶
- Support additionalProperties.
0.1.10 (2016-8-25)¶
- Don’t choke if there are no definitions
- Generate operations without operationId
- Generate example from properties
0.1.9 (2016-7-28)¶
- Support array definitions.
0.1.8 (2016-5-11)¶
- Support type field to be an array.
- Use base path to validate request.
0.1.7 (2016-4-1)¶
- Support UTF-8 in swagger.yaml.
0.1.6 (2016-3-16)¶
- Add support for path-level parameters.
0.1.5 (2016-2-17)¶
- Add support for parameters references in path specs.
0.1.4 (2016-2-10)¶
- Handle string as status_code.
0.1.3 (2016-2-3)¶
- Fix a bug in get_response_example with schema only containing a type field.
0.1.2 (2016-2-3)¶
- Support schema with only a type field.
0.1.1 (2016-1-31)¶
- Change license to MIT.
0.1 (2016-1-28)¶
- First release on PyPI.