[Fixed]-Django-rest-swagger: how to group endpoints?

2πŸ‘

βœ…

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.

πŸ‘€baldr

0πŸ‘

You can have a urls.py in your tasks app (I assume there is one), and declare them in your /tasks urls.

One of this for each of your endpoints

url(r'^ tasks/(?P<task_id>\w+)$',
    YourTaskView,
    name='task'),

And this in your api root urls.py

url(r'^api/', include('api.tasks.urls'), name='my-api-root'),

BUT, looks like you could use DRF routers

0πŸ‘

What about that setting?

SPECTACULAR_SETTINGS = {
    'SCHEMA_PATH_PREFIX': '/api/tasks',
}

Or, not tested, but it seems that you can use the tags param from @extend_schema to customize the grouping of the endpoints.

πŸ‘€mailivres

Leave a comment