django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

SwaggerSchemaView exclude_from_schema deprecated and removed in drf 3.9

Open Sprungwunder opened this issue 5 years ago • 4 comments

DjangoRestFramework removed the exclude_from_schema flag to exclude urls from the api schema. This leads to swagger schema view show up as an api endpoint. Instead a "schema = None" must be set for View classes to exclude from the api endpoints. see https://www.django-rest-framework.org/api-guide/schemas/

quifix for me was to hardcode this like

schema_view = get_swagger_view(title='My API')
schema_view.cls.schema = None

Versions: django 2.1.2 drf 3.9.0 django-rest-swagger 2.2.0

Sprungwunder avatar Oct 24 '18 12:10 Sprungwunder

Thanks for the quick fix

jrd avatar Nov 28 '18 10:11 jrd

@Sprungwunder Can you show me what your whole file looks like? It doesn't work for me with Django 1.11.16 and the code below.

django 1.11.16 drf 3.9.0 django-rest-swagger 2.2.0

from django.conf.urls import url
from rest_framework import routers
from rest_framework_swagger.views import get_swagger_view

router = routers.DefaultRouter(trailing_slash=False)

router.register(r"user", views.UserViewSet)

schema_view = get_swagger_view(title="My API")
schema_view.cls.schema = None

urlpatterns = [url(r"^schema/", schema_view)]

urlpatterns += router.urls

opsdisk avatar Dec 02 '18 20:12 opsdisk

@opsdisk

from django.conf import settings
from django.conf.urls.static import static
from django.urls import path, include

from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='API', url='/' + settings.BASE_URL)
schema_view.cls.schema = None

urlpatterns = [
    path('api/', include('adapter.rest_api.urls')),
    path('auth/', include('keycloak_adapter.urls')),
    path('swagger-ui/', schema_view)
]

Nothing special so far, api contains the django rest framwork views, auth handles authentication via keycloak, swagger settings only contains a login url and sets USE_SESSION_AUTH to True

Sprungwunder avatar Dec 03 '18 11:12 Sprungwunder

Thanks for that, I give it a try.

opsdisk avatar Dec 04 '18 11:12 opsdisk