0

In my project i have api/v1 endpoints, which i want to show in separated schema view. The problem is that using additional schema_view with api/v1 url patterns destroys prefix from router. How can I keep it? Here is code for urls.py of main application and screenshots of resulted swaggers:

code of action_fm/urls.py (main application)

from django.contrib import admin
from django.urls import include, path
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

from action.urls import notify_router
from action_fm.views import HealthView, api_root

api_v1_urlpatterns = [
    path("", include([path("", include(notify_router.urls))])),
]


schema_view = get_schema_view(
    openapi.Info(title="Action FM Swagger", default_version="v1", description="API description for Action FM"),
    public=True,
    permission_classes=(permissions.AllowAny,),
    patterns=api_v1_urlpatterns,
)

schema_view_common = get_schema_view(
    openapi.Info(title="Action FM Swagger", default_version="v1", description="API description for Action FM"),
    public=True,
    permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
    path("api/v1/", include(api_v1_urlpatterns)),
    path("", include("django.contrib.auth.urls")),
    path("", api_root),
    path("api-auth", include("rest_framework.urls", namespace="rest_framework")),
    path("health", HealthView.as_view(), name="health"),
    path(
        "swagger/v1", schema_view.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui-v1"
    ),  # for correct logically separated api endpoints to try
    path("swagger/common", schema_view_common.with_ui("swagger", cache_timeout=0), name="schema-swagger-ui-common"),
    path("grappelli/", include("grappelli.urls")),
    path("admin/", admin.site.urls),
]

code of action/urls.py (other application, here i’m storing my router)

from rest_framework import routers

from action.views import NotificationHandlerViewSet

notify_router = routers.DefaultRouter(trailing_slash=True)
notify_router.register(r"notify", NotificationHandlerViewSet, basename="notify")

here is screenshot of correct common swagger, which saves ’notify/' prefix to url

and here is incorrect api/v1 swagger, which lost needed ’notify’ prefix(((

1 Answers1

1

Seems that drf_yasg does not loose 'notify' prefix, its just saved as basePath in swagger schema, so if I add another url to api v1 urlconf, all prefixes will show correctly