Skip to content
This is a django app which you can modify and improve your autogenerated swagger documentation from your drf API.
Python Makefile HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
docs
drf_swagger_customization
tests
.coveragerc
.editorconfig
.gitignore
.travis.yml
AUTHORS.rst
CONTRIBUTING.rst
HISTORY.rst
LICENSE
MANIFEST.in
Makefile
README.rst
__init__.py
manage.py
requirements.txt
requirements_dev.txt
requirements_test.txt
runtests.py
setup.cfg
setup.py
tox.ini

README.rst

drf-swagger-customization

https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat

This is a django app which you can modify and improve your autogenerated swagger documentation from your drf API.

Documentation

The full documentation is at https://drf-swagger-customization.readthedocs.io.

Quickstart

Install drf-swagger-customization:

pip install drf-swagger-customization

Add these global variables to your settings.py:

EXTENSION_PATH = os.path.join(PROJECT_DIR, 'docs/doc_extension.json') # Path to your extension file
EXTERNAL_DOC_FOLDER = os.path.join(PROJECT_DIR, 'docs/external/') # Path to your external documentation folder

Add drf-swagger-customization's URL patterns:

from drf_swagger_customization.views import get_swagger_view

schema_view = get_swagger_view(title='Pastebin API')

urlpatterns = [
    ...
    url(r'^docs/$', schema_view),
    ...
]

Usage

With this package we can increase the auto-generated documentation from django-swagger. That way, we can add documentation from external APIs or add more information to our drf API methods such as fields, remove endpoints, update attributes, and so on.

In order to add information to our EXTENSION_PATH json file, we have available these operations:

Create

{
    "action": "create",
    "operation": {
        "paths|/v1/travels/|get|parameters": [
            {
              "name": "Field1",
              "in": "query",
              "required": true,
              "type": "string"
            },
            {
              "name": "Field2",
              "in": "path",
              "required": true,
              "type": "integer"
            }
        ]
    }
}

Update

{
    "action": "update",
    "operation": {
        "paths|/v1/travels/|get|parameters|field1": {
            "name": "Field1",
            "in": "query",
            "required": true,
            "type": "string"
        }
    }
}

Remove

{
    "action": "delete",
    "operation": "paths|/v1/travels/|get|parameters|field1"
}

Rename

{
    "action": "rename",
    "operation": {
        "paths|/v1/travels/": "/travels/",
        "paths|/v1/travels/{id}/": "/travels/{id}/"
    }
}

Completed Sample

[
  {
    "action": "create",
    "operation": {
      "paths|/v1/travels/|get|parameters": [
        {
          "name": "Field1",
          "in": "query",
          "required": true,
          "type": "string"
        },
        {
          "name": "Field2",
          "in": "path",
          "required": true,
          "type": "integer"
        }
      ]
    }
  },
  {
    "action": "update",
    "operation": {
      "paths|/v1/travels/|get|parameters|field1": {
        "name": "Field1",
        "in": "query",
        "required": true,
        "type": "string"
      }
    }
  },
  {
    "action": "delete",
    "operation": "paths|/v1/travels/|get|parameters|field1"
  },
  {
    "action": "rename",
    "operation": {
        "paths|/v1/travels/": "/travels/",
        "paths|/v1/travels/{id}/": "/travels/{id}/"
    }
  }
]

Future Work

  • Add an example
  • Command for doc_file customization, in order to remove redundant executions.
  • Improve the settings options.
You can’t perform that action at this time.