This is a django app which you can modify and improve your autogenerated swagger documentation from your drf API.
The full documentation is at https://drf-swagger-customization.readthedocs.io.
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),
...
]
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:
{
"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}/"
}
}
[
{
"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}/"
}
}
]
- Add an example
- Command for doc_file customization, in order to remove redundant executions.
- Improve the settings options.