Open Safrone opened 5 years ago
A hacky workaround for now:
from rest_framework import permissions
from drf_yasg.generators import OpenAPISchemaGenerator
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
import os
class SchemaGenerator(OpenAPISchemaGenerator):
def get_schema(self, request=None, public=False):
schema = super(SchemaGenerator, self).get_schema(request, public)
schema.basePath = os.path.join(schema.basePath, 'api/')
return schema
schema_view = get_schema_view(
openapi.Info(
title="Management Server API",
default_version='v1',
contact=openapi.Contact(email="itadmin@enertiv.com"),
),
public=False,
permission_classes=(permissions.IsAuthenticated,),
urlconf="management_server.api.urls",
generator_class=SchemaGenerator,
)
@Safrone Thanks for the hack!
Hack works great. Would be even greater to have a clean way however :)
Noticed this PR though I'm not sure if it fixes this issue: https://github.com/axnsan12/drf-yasg/pull/682
well after all the issues i went through this is still an issue cause if you use one include inside urlpatterns it doesnt work, but if you have multiple it works 😒so again i stuck here!
its not working??!!?!? `urlpatterns = [
path("admin/", admin.site.urls),
# config app urls
path("", include("farm_config.urls")),
}`
it is working! `urlpatterns = [
path("admin/", admin.site.urls),
# config app urls
path("", include("farm_config.urls")),
# access control app urls
path("access-control/", include("access_control.urls")),
}`
I've been trying to expose my api via swagger schema view.
When I set the urlconf to the api urls:
get_schema_view(..., urlconf='management_server.api.urls)'
the basePath for those urls does not get set so the urls incorrectly show:http://localhost:8800/client/
instead of the correcthttp://localhost:8800/api/client
before, I was able to set
get_schema_view(..., url='/api')
and the baseUrl correctly included/api
but it looks like now the url requires a fully qualified url and the path portion is dropped anyway.The docs seem to imply that the proper way is to use the
FORCE_SCRIPT_NAME
django setting to set the base url but this then affects the entirety of the django site by injecting/api
in every path which feels wrong for setting the api path in this specific view.api/views.py
api/urls.py