I am using Django REST Framework and django-rest-swagger library for building an API endpoints. I would like to group some API urls by custom attribute instead of URL.
For example I have API endpoints and would like to group them by functions:
# task list management
GET /api/tasks/known - get known tasks list with their parameters
GET /api/tasks - get last tasks list with their statuses
# Tasks by ID management
GET /api/task/12345 - get task result/status
DELETE /api/task/12345 - Revoke task
# Task by name management:
# MyTask123
GET /api/tasks/MyTask123 - get task info (parameters, etc)
POST /api/tasks/MyTask123 - async start new task
# MySuperShinyTask777
GET /api/tasks/MySuperShinyTask777 - get task info (parameters, etc)
POST /api/tasks/MySuperShinyTask777 - async start new task
# scheduled tasks management
GET /api/tasks/scheduled - get list of scheduled tasks
# manage exact scheduled tasks
POST /api/tasks/scheduled/MyTask123 - schedule new task
GET /api/tasks/scheduled/12345 - get scheduled task details
PUT /api/tasks/scheduled/12345 - change scheduled task
DELETE /api/tasks/scheduled/12345 - delete scheduled task
So I would like to show them grouped by roles. Now they grouped all only '/api/' and that's it.
In urls.py
I include it like this:
url(r'^api/', include('api.urls'), name='my-api-root'),
How can I do custom grouping for django-rest-swagger?
I see that people keep visiting this question and upvote it. This means the question is actual. I can describe what I ended up with with similar task recently.
I created a YAML representation of API endpoints according to OpenAPI spec. I had to keep the same API endpoints on the backend too and this is a drawback as this is not auto-generated docs.
I installed Swagger-UI with docker and it uses my YAML spec to represent Swagger page.
It is easy to separate endpoints by custom groups and even have one endpoint in two groups.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With