Skip to main content
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/tree/master/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

Metadata

Release files for django-rest-swagger-swaggerdoc 1.0.post2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-rest-swagger-swaggerdoc 1.0.post2
File Size Uploaded
django-rest-swagger-swaggerdoc-1.0.post2.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-rest-swagger-swaggerdoc 1.0.post2
File Interpreter ABI Platform
django_rest_swagger_swaggerdoc-1.0.post2-py3-none-any.whl Python 3 none any Details

Total release size: 19.5 kB

Release files / django-rest-swagger-swaggerdoc-1.0.post2.tar.gz

Download URL django-rest-swagger-swaggerdoc-1.0.post2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8381cae839213dd87ee3dd777849add9b666e741eb7198b95367a55d47a42c12
BLAKE2b-256 checksum
How to use checksums
b9aff44a360ec58594d9e460c0c1254856349010c37121f6c389c387e3362617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_rest_swagger_swaggerdoc-1.0.post2-py3-none-any.whl

Download URL django_rest_swagger_swaggerdoc-1.0.post2-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93af9dde39625441c4139df6a5073b1ccb5edf21d49135aa6df97c880e53a207
BLAKE2b-256 checksum
How to use checksums
41b21d2648614906f4c3691ba5b3487684b5f9267e9b6afaf262938377b96106
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.post2 This release

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page