Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use drf_yasg to generate swagger #1930

Merged
merged 4 commits into from
Mar 21, 2018

Conversation

davcamer
Copy link
Contributor

@davcamer davcamer commented Feb 28, 2018

Fixes:

#1853
#1855
https://github.com/digitalocean/go-netbox/issues/26

drf_yasg provides more complete swagger output, allowing for generation of usable clients. As explained in drf_yasg's README, the django rest framework is based on coreapi, which doesn't include response schemas. drf_yasg instead approaches the swagger with openapi, allowing it to generate full response schemas.

Some custom work was needed to accommodate Netbox's custom field serializers, and to provide x-nullable attributes where appropriate. x-nullable is an extension to OpenAPI v2, but is understood by the golang swagger generator I was targeting. I have not tried it with other generators.

This also replaces the api documentation at /api/docs with similar documentation, also based off of the swagger UI. There is alternative documentation at /api/redoc/ included only because it is by default part of drf_yasg. That could easily be removed if it isn't desired.

One other note: I was not able to get old_requirements.txt to work as expected with more than a single line in it. It simply errors out when the pycrypto is not installed, because of the previous upgrade.

$ pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
$ pip3 uninstall -r old_requirements.txt -y
Uninstalling psycopg2-2.7.4:
  Successfully uninstalled psycopg2-2.7.4
Cannot uninstall requirement pycrypto, not installed

Based on what you've done with psycopg2, I've moved django-rest-swagger to the top of that file.

@davcamer
Copy link
Contributor Author

@jeremystretch I believe this is now complete. I've worked through the problems with the generated client that people identified so far in the https://github.com/digitalocean/go-netbox repository.

drf_yasg provides more complete swagger output, allowing for generation
of usable clients.

Some custom work was needed to accommodate Netbox's custom field
serializers, and to provide x-nullable attributes where appropriate.
drf_yasg is interpreting it as a number because NumericInFilter inherits
from django's NumberFilter which explicitly identifies as being a
DecimalField.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants