Drf-yasg doesn't include the "api/" portion of the urls

I'm using drf-yasg to generate a Swagger schema, but it removes the "api/" portion of the url.

schema_view = get_schema_view(
openapi.Info(
    title="My API",
    default_version='v1',
    description="...",
    terms_of_service="https://www.google.com/policies/terms/",
    contact=openapi.Contact(email="hello@mycompany.com"),
    license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=[permissions.AllowAny],
)
router = routers.DefaultRouter()
router.register(r'spaces', SpacesViewSet, basename='spaces')

urlpatterns = [

url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),

path('api/', include(router.urls)),
path('api/search-options', SearchPlacesOptionsView.as_view()),
]

result on /swagger result on /swagger

As you can see for the routes from the drf router, it doesn't include the /api portion of the url. However for the regular api/search-options endpoint it removes the /api portion as well, so I don't think it has something to do with the router.

Back to Top