marcgibbons / django-rest-swagger

Swagger Documentation Generator for Django REST Framework: deprecated
https://marcgibbons.com/django-rest-swagger/
BSD 2-Clause "Simplified" License
2.59k stars 599 forks source link

SwaggerSchemaView exclude_from_schema deprecated and removed in drf 3.9 #781

Open Sprungwunder opened 6 years ago

Sprungwunder commented 6 years ago

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

jrd commented 5 years ago

Thanks for the quick fix

opsdisk commented 5 years ago

@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
Sprungwunder commented 5 years ago

@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

opsdisk commented 5 years ago

Thanks for that, I give it a try.