Browse Source

HOT-FIX: altera inclusão de drf-yasg

Configura urls drf-yasg se ele está presente na lista de apps do projeto
pull/2758/head
Leandro Roberto 5 years ago
parent
commit
cf4c5509d9
  1. 15
      sapl/api/urls.py

15
sapl/api/urls.py

@ -1,7 +1,5 @@
from django.conf import settings from django.conf import settings
from django.conf.urls import include, url from django.conf.urls import include, url
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions from rest_framework import permissions
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
@ -29,8 +27,11 @@ for app, built_sets in SaplApiViewSetConstrutor._built_sets.items():
urlpatterns_router = router.urls urlpatterns_router = router.urls
urlpatterns_api_doc = []
schema_view = get_schema_view( if 'drf_yasg' in settings.INSTALLED_APPS:
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
schema_view = get_schema_view(
openapi.Info( openapi.Info(
title="Sapl API - docs", title="Sapl API - docs",
default_version='v1', default_version='v1',
@ -39,16 +40,16 @@ schema_view = get_schema_view(
url=settings.SITE_URL, url=settings.SITE_URL,
public=True, public=True,
permission_classes=(permissions.AllowAny,), permission_classes=(permissions.AllowAny,),
) )
urlpatterns_api_doc = [ urlpatterns_api_doc = [
url(r'^docs/swagger(?P<format>\.json|\.yaml)$', url(r'^docs/swagger(?P<format>\.json|\.yaml)$',
schema_view.without_ui(cache_timeout=0), name='schema-json'), schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^docs/swagger/$', url(r'^docs/swagger/$',
schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^docs/redoc/$', url(r'^docs/redoc/$',
schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
] ]
# TODO: refatorar para customização da api automática # TODO: refatorar para customização da api automática
deprecated_urlpatterns_api = [ deprecated_urlpatterns_api = [

Loading…
Cancel
Save