Package: drf-yasg2
DRF - Yet another Swagger generator 2Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST
Framework code.NoticeThe originaldrf-yasgrepository is now maintained again. This repo will be left as is to serve those still using it.Please migrate back to the using the origional repository and for submitting contributions.StatusSourceShieldsProjectPublishersDownloadsRaisedCompatibilityReleasePythonDjangoDjango REST Framework1.18.x2.71.113.8 - 3.91.18.x3.6 - 3.82.2 - 3.03.8 - 3.121.19.x3.6 - 3.92.2 - 3.13.8 - 3.12FeaturesFull support for nested Serializers and SchemasResponse schemas and descriptionsModel definitions compatible with codegen toolsCustomization hooks at all points in the spec generation processJSON and YAML format for specBundles latest version ofswagger-uiandredocfor viewing the generated documentationSchema view is cacheable out of the boxGenerated Swagger schema can be automatically validated byswagger-spec-validatorSupports Django REST Framework API versioning withURLPathVersioningandNamespaceVersioning; other DRF or custom versioning schemes are not currently
supportedScreenshotsFully nested request and response schemasChoose between redoc and swagger-uiModel definitionsInstallingInstalling the package from pypi:pipinstalldrf-yasg2Given the numerous methods to manually customize the generated schema, it makes sense to validate the result to ensure it still conforms to OpenAPI 2.0. To this end, validation is provided at the generation point using Python Swagger libraries, and can be activated by passingvalidators=['ssv']toget_schema_view; if the generated schema is not valid, aSwaggerValidationErroris raised by the handling codec.To provide the built-in validation mechanisms you can install the extra requirements:pipinstalldrf-yasg2[validation]UsageCheckout thelive demo!Add the package to INSTALLED_APPS:INSTALLED_APPS=[...'drf_yasg2',...]Add the endpoints to urlpatterns:fromdjango.urlsimportpath,re_pathfromrest_frameworkimportpermissionsfromdrf_yasg2.viewsimportget_schema_viewfromdrf_yasg2importopenapi...schema_view=get_schema_view(openapi.Info(title="Snippets API",default_version='v1',description="Test description",terms_of_service="https://www.google.com/policies/terms/",contact=openapi.Contact(email="contact@snippets.local"),license=openapi.License(name="BSD License"),),public=True,permission_classes=(permissions.AllowAny,),)urlpatterns=[re_path(r'^swagger(?P<format>\.json|\.yaml)$',schema_view.without_ui(cache_timeout=0),name='schema-json'),path('swagger/',schema_view.with_ui('swagger',cache_timeout=0),name='schema-swagger-ui'),path('redoc/',schema_view.with_ui('redoc',cache_timeout=0),name='schema-redoc'),...]This exposes 4 endpoints:A JSON view of your API specification at/swagger.jsonA YAML view of your API specification at/swagger.yamlA swagger-ui view of your API specification at/swagger/A ReDoc view of your API specification at/redoc/DocsAdditional details are available in thefull documentationand thechangelog.To generate the documentation locally:scripts/docs.shTestsTo run tests:toxContributingPlease readCONTRIBUTING.mdfor details on our code of conduct, and the process for submitting pull requests.VersioningSemVeris used for versioning. For a list of versions available, see the tags on this repository.AuthorsThis project forked fromdrf-yasg.
Credit is given toCristi Vîjdeaand the original contributors.Cristi Vîjdea-Initial work-Cristi VîjdeaJoel Lefkowitz-This fork's maintainer-Joel LefkowitzHuge thank you to the contributors who've participated in this project. Have a look at thecontributions!LicenseThis project is licensed under the BSD 3-Clause License - see theLICENSE.mdfile for details