drf-swagger-customization

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


Keywords
drf-swagger-customization
License
MIT
Install
pip install drf-swagger-customization==0.1.5

Documentation

drf-swagger-customization

https://travis-ci.org/androiz/drf-swagger-customization.svg?branch=master

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/update/remove information to our EXTENSION_PATH json file, we have available these operations:

Create:

{

"operation": "create", "swagger-data": {

"paths|/v1/travels/|get|parameters": [
{
"name": "Field1", "in": "query", "required": true, "type": "string"

}, {

"name": "Field2", "in": "path", "required": true, "type": "integer"

}

]

}

}

Update:

{

"operation": "update", "swagger-data": {

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

}

}

}

Remove:

{
"operation": "delete", "swagger-data": "paths|/v1/travels/|get|parameters|field1"

}

Completed Sample

[
{

"operation": "create", "swagger-data": {

"paths|/v1/travels/|get|parameters": [
{
"name": "Field1", "in": "query", "required": true, "type": "string"

}, {

"name": "Field2", "in": "path", "required": true, "type": "integer"

}

]

}

}, {

"operation": "update", "swagger-data": {

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

}

}

}, {

"operation": "delete", "swagger-data": "paths|/v1/travels/|get|parameters|field1"

}

]

Future Work

  • Add an example
  • Command for doc_file customization, in order to remove redundant executions.
  • Improve the settings options.