1

I'm documenting my Django application using get_schema_view() method, but when I open the Swagger UI all the URLs are placed under the same group.

My urls.py look like:

router = routers.DefaultRouter()
router.register(r'stores', StoreViewSet)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include(router.urls)),
    path('api/register/', UserRegistrationView.as_view(), name='register'),
    path('api/login/', views.obtain_auth_token, name='login'),

    # Documentation
    path('openapi/', get_schema_view(
        title='Title API',
        description='Some description goes here...',
        version='v0.1'
    ), name='openapi-schema'),
    path('docs/', TemplateView.as_view(
        template_name='documentation.html',
        extra_context={'schema_url': 'openapi-schema'}
    ), name='docs')
]

All the endpoints are placed under a group called api in the Swagger UI.

How can I specify the api/ prefix while generating the schema in order to group the endpoints by model?

Thanks.

  • Does this answer your question? [Custom Grouping on OpenAPI endpoints with Django Rest Framework](https://stackoverflow.com/questions/62830171/custom-grouping-on-openapi-endpoints-with-django-rest-framework) – Tomerikoo Oct 12 '21 at 11:53

1 Answers1

1

I had the same problem. The simple solution is to define prefix in settings.

SPECTACULAR_SETTINGS = {
    'SCHEMA_PATH_PREFIX': r'/api/v[0-9]',
}

Answered here : Custom Grouping on OpenAPI endpoints with Django Rest Framework

  • Welcome to Stack Overflow! If you think this question has an answer somewhere else in this site - [flag it as duplicate](https://stackoverflow.com/help/privileges/flag-posts) instead of posting a link to an answer as an answer... – Tomerikoo Oct 12 '21 at 11:53