Skip to main content

Inject a swagger style yaml data to the django-rest-swagger's data

Project description

CircleCI Status CodeCov Status

Django REST Swagger 2.0 has changed drastically. For example, you may not put a return code in YAML files. This package provides functions to inject a swagger style yaml data to the django-rest-swagger’s data.

How to use it

  1. Add rest_framework_swagger to your INSTALLED_APPS setting

  2. You create a swagger style yaml file.

    This YAML file is swagger style.


      description: test document
          description: success
          description: bad request
            type: json
            Content-Type: application/json
  3. You create api view function or ViewClass.

    The swaggerdoc decorator to specify the relative path from the file the view callable is defined.

    from rest_framework.decorators import api_view
    from rest_framework.views import APIView
    from django_rest_swagger_swaggerdoc import swaggerdoc
    def example_view(request):
    class ExampleView(APIView):
        def get(self, request):
  4. You create document schema view.

    Use django_rest_swagger_swaggerdoc.renderers.SwaggerAdditinalDocRenderer. DO NOT USE rest_framework_swagger.renderers.OpenAPIRenderer.

    from rest_framework_swagger.renderers import SwaggerUIRenderer
    from rest_framework.decorators import api_view, renderer_classes
    from rest_framework import response, schemas
    from django_rest_swagger_swaggerdoc.renderers import SwaggerAdditinalDocRenderer
    @renderer_classes([SwaggerUIRenderer, SwaggerAdditinalDocRenderer])
    def schema_view(request):
        generator = schemas.SchemaGenerator(title='Pastebin API')
        return response.Response(generator.get_schema(request=request))

See example project:


$ pip install django-rest-swagger-swaggerdoc

It is depends on djangorestframework(>= 3.4.7). If older than version 3.7.4, it may not be able to correctly resolve the YAML path.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page