diff --git a/HISTORY.rst b/HISTORY.rst index 320badd27e..f048e7a9bb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -21,7 +21,9 @@ * Show entire sys trace when an App import exception is raised. * Remove Django suit from requirements. * Remove development URLs from main URL file. - +* Move API documentation generation from the root URLs module + to the API app's URLs module. + 3.1.11 (2019-04-XX) =================== * Fix multiple tag selection wizard step. diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 770b886464..9af04d6946 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -46,6 +46,8 @@ Other changes * Change how the HOME_VIEW setting is defined. HOME_VIEW is now COMMON_HOME_VIEW. * Split trashed document views into their own module. * Remove Django suit from requirements. +* Move API documentation generation from the root URLs module + to the API app's URLs module. Removals -------- diff --git a/mayan/apps/rest_api/api_views.py b/mayan/apps/rest_api/api_views.py index ee1dd41c94..bf1bf89d34 100644 --- a/mayan/apps/rest_api/api_views.py +++ b/mayan/apps/rest_api/api_views.py @@ -1,6 +1,8 @@ from __future__ import unicode_literals -from rest_framework import renderers +from drf_yasg.views import get_schema_view + +from rest_framework import permissions, renderers from rest_framework.authtoken.views import ObtainAuthToken from rest_framework.views import APIView from rest_framework.response import Response @@ -8,6 +10,7 @@ from rest_framework.schemas.generators import EndpointEnumerator from .classes import Endpoint from .serializers import EndpointSerializer +from .schemas import openapi_info class APIRoot(APIView): @@ -33,3 +36,11 @@ class BrowseableObtainAuthToken(ObtainAuthToken): Obtain an API authentication token. """ renderer_classes = (renderers.BrowsableAPIRenderer, renderers.JSONRenderer) + + +schema_view = get_schema_view( + openapi_info, + validators=['flex', 'ssv'], + public=True, + permission_classes=(permissions.AllowAny,), +) diff --git a/mayan/apps/rest_api/links.py b/mayan/apps/rest_api/links.py index efd5443ab3..dc728a5241 100644 --- a/mayan/apps/rest_api/links.py +++ b/mayan/apps/rest_api/links.py @@ -15,10 +15,10 @@ link_api = Link( ) link_api_documentation = Link( icon_class=icon_api_documentation, tags='new_window', - text=_('API Documentation (Swagger)'), view='schema-swagger-ui' + text=_('API Documentation (Swagger)'), view='rest_api:schema-swagger-ui' ) link_api_documentation_redoc = Link( icon_class=icon_api_documentation_redoc, tags='new_window', - text=_('API Documentation (ReDoc)'), view='schema-redoc' + text=_('API Documentation (ReDoc)'), view='rest_api:schema-redoc' ) diff --git a/mayan/apps/rest_api/urls.py b/mayan/apps/rest_api/urls.py index 33a3a7bed8..eac7976458 100644 --- a/mayan/apps/rest_api/urls.py +++ b/mayan/apps/rest_api/urls.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from django.conf.urls import include, url -from .api_views import APIRoot, BrowseableObtainAuthToken +from .api_views import APIRoot, BrowseableObtainAuthToken, schema_view api_urls = [ @@ -14,5 +14,21 @@ api_urls = [ ] urlpatterns = [ + url( + regex=r'^auth/token/obtain/$', name='auth_token_obtain', + view=BrowseableObtainAuthToken.as_view() + ), + url( + regex=r'^swagger(?P.json|.yaml)$', name='schema-json', + view=schema_view.without_ui(cache_timeout=None), + ), + url( + regex=r'^swagger/$', name='schema-swagger-ui', + view=schema_view.with_ui('swagger', cache_timeout=None) + ), + url( + regex=r'^redoc/$', name='schema-redoc', + view=schema_view.with_ui('redoc', cache_timeout=None) + ), url(r'^', include(api_urls)), ] diff --git a/mayan/urls/base.py b/mayan/urls/base.py index 0838a37396..b22478bb64 100644 --- a/mayan/urls/base.py +++ b/mayan/urls/base.py @@ -3,24 +3,10 @@ from __future__ import unicode_literals from django.conf.urls import url from django.contrib import admin -from drf_yasg.views import get_schema_view -from rest_framework import permissions - -from mayan.apps.rest_api.schemas import openapi_info - __all__ = ('urlpatterns',) admin.autodiscover() -schema_view = get_schema_view( - openapi_info, - validators=['flex', 'ssv'], - public=True, - permission_classes=(permissions.AllowAny,), -) urlpatterns = [ url(r'^admin/', admin.site.urls), - url(r'^swagger(?P.json|.yaml)$', schema_view.without_ui(cache_timeout=None), name='schema-json'), - url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=None), name='schema-swagger-ui'), - url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=None), name='schema-redoc'), ]