Skip to main content

django-rest-swagger-swaggerdoc

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

    settings.py:

    INSTALLED_APPS = (
        ...
       'rest_framework_swagger',
    )
  2. You create a swagger style yaml file.

    This YAML file is swagger style.

    ./api_test_doc.yml:

    get:
      description: test document
      responses:
        200:
          description: success
        400:
          description: bad request
          schema:
            type: json
          headers:
            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.

    views.py:

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

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

    views.py:

    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
    
    
    @api_view()
    @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: https://github.com/TakesxiSximada/django-rest-swagger-swaggerdoc/examples

Install

$ 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.

Other

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

File details

Details for the file django-rest-swagger-swaggerdoc-1.0.post1.tar.gz.

File metadata

File hashes

Hashes for django-rest-swagger-swaggerdoc-1.0.post1.tar.gz
Algorithm Hash digest
SHA256 ed4b8a740089d24f761ca6944b27f5bd663024228ec9fd25c78aab0f7fad36d9
MD5 add1472b7a8d0150116e552e55f399b2
BLAKE2b-256 4f7d355522da04c3929b93c4cbfb9aa9703fcf75e4e53e4efcec8a7326dce9bc

See more details on using hashes here.

File details

Details for the file django_rest_swagger_swaggerdoc-1.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_rest_swagger_swaggerdoc-1.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 c77c434f390878656e05964eba9b709a27bd70361ac0628b9bdfc5534cfc5678
MD5 c1695dac562f7d72ef988051c54274b6
BLAKE2b-256 b1b1a46bcd2270d26d6a764c7993c47d7f5039529905cff29e275573d6d92278

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page