From cae74afd5f8c3e26e330ae46b6e1762a5ed9b58e Mon Sep 17 00:00:00 2001 From: Ugtan Date: Sat, 16 Mar 2019 18:50:15 +0530 Subject: [PATCH] Add support for documenting API --- requirements.txt | 1 + src/src/settings.py | 1 + src/src/urls.py | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/requirements.txt b/requirements.txt index 2cea5a60..43ba3ddb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ lxml==4.2.5 social-auth-app-django==2.1.0 #for testing selenium==3.14.1 +drf-yasg==1.14.0 diff --git a/src/src/settings.py b/src/src/settings.py index 38716c8e..02a22c1b 100644 --- a/src/src/settings.py +++ b/src/src/settings.py @@ -50,6 +50,7 @@ 'api', 'rest_framework', 'social_django', + 'drf_yasg', ] MIDDLEWARE = [ diff --git a/src/src/urls.py b/src/src/urls.py index 3a3d7fa7..2253da21 100644 --- a/src/src/urls.py +++ b/src/src/urls.py @@ -33,7 +33,20 @@ from django.conf.urls.static import static from rest_framework import routers from api import views +from rest_framework import permissions +from drf_yasg.views import get_schema_view +from drf_yasg import openapi +schema_view = get_schema_view( + openapi.Info( + title="SPDX Online Tools API", + default_version='v1', + description="API Documentation for SPDX Online Tools used to understand the capabilities of the \ + tools by testing the requests and responses of the various API endpoints." + ), + public=True, + permission_classes=(permissions.AllowAny,), +) router = routers.DefaultRouter() #router.register(r'users', views.UserViewSet) @@ -53,6 +66,9 @@ url(r'^api2/', include(router.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^oauth/', include('social_django.urls', namespace='social')), + url(r'^swagger(?P\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'), + url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), ] urlpatterns += staticfiles_urlpatterns()