From fce1703f82dfbca071e7226afbe53b958bd88103 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 27 Mar 2020 14:20:53 +0900 Subject: [PATCH] Add API document generator, resolves #299, resolves #646 --- app/api/urls.py | 2 +- app/api/views.py | 2 ++ app/app/settings.py | 1 + app/app/urls.py | 16 +++++++++++++++- app/requirements.txt | 1 + requirements.txt | 1 + 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/api/urls.py b/app/api/urls.py index b65d87a0..dc1baee6 100644 --- a/app/api/urls.py +++ b/app/api/urls.py @@ -46,4 +46,4 @@ urlpatterns = [ RoleMappingDetail.as_view(), name='rolemapping_detail'), ] -urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'xml']) +# urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'xml']) diff --git a/app/api/views.py b/app/api/views.py index 94cb017f..02c13521 100644 --- a/app/api/views.py +++ b/app/api/views.py @@ -170,6 +170,7 @@ class DocumentDetail(generics.RetrieveUpdateDestroyAPIView): class AnnotationList(generics.ListCreateAPIView): pagination_class = None permission_classes = [IsAuthenticated & IsInProjectOrAdmin] + swagger_schema = None def get_serializer_class(self): project = get_object_or_404(Project, pk=self.kwargs['project_id']) @@ -197,6 +198,7 @@ class AnnotationList(generics.ListCreateAPIView): class AnnotationDetail(generics.RetrieveUpdateDestroyAPIView): lookup_url_kwarg = 'annotation_id' permission_classes = [IsAuthenticated & (((IsAnnotator | IsAnnotationApprover) & IsOwnAnnotation) | IsProjectAdmin)] + swagger_schema = None def get_serializer_class(self): project = get_object_or_404(Project, pk=self.kwargs['project_id']) diff --git a/app/app/settings.py b/app/app/settings.py index 52d1e1d0..b55abca0 100644 --- a/app/app/settings.py +++ b/app/app/settings.py @@ -61,6 +61,7 @@ INSTALLED_APPS = [ 'polymorphic', 'webpack_loader', 'corsheaders', + 'drf_yasg' ] CLOUD_BROWSER_APACHE_LIBCLOUD_PROVIDER = env('CLOUD_BROWSER_LIBCLOUD_PROVIDER', None) diff --git a/app/app/urls.py b/app/app/urls.py index 4576ebd5..a71ac815 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -15,10 +15,23 @@ Including another URLconf """ from django.conf import settings from django.contrib import admin -from django.urls import path, include, re_path +from django.urls import path, include from django.contrib.auth.views import PasswordResetView, LogoutView +from drf_yasg.views import get_schema_view +from drf_yasg import openapi + from server.views import LoginView +# TODO: adds AnnotationList and AnnotationDetail endpoint. +schema_view = get_schema_view( + openapi.Info( + title="doccano API", + default_version='v1', + description="doccano API description", + license=openapi.License(name="MIT License"), + ), + public=True, +) urlpatterns = [ path('', include('authentification.urls')), @@ -30,6 +43,7 @@ urlpatterns = [ path('password_reset/', PasswordResetView.as_view(), name='password_reset'), path('api-auth/', include('rest_framework.urls')), path('v1/', include('api.urls')), + path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), ] if 'cloud_browser' in settings.INSTALLED_APPS: diff --git a/app/requirements.txt b/app/requirements.txt index c7b67cfc..74643b1b 100644 --- a/app/requirements.txt +++ b/app/requirements.txt @@ -17,6 +17,7 @@ django-rest-polymorphic==0.1.8 djangorestframework==3.10 djangorestframework-csv==2.1.0 djangorestframework-filters==0.10.2 +drf-yasg==1.17.1 environs==4.1.0 djangorestframework-xml==1.4.0 Faker==0.9.1 diff --git a/requirements.txt b/requirements.txt index ba014025..f0dca5aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ djangorestframework-csv==2.1.0 djangorestframework-filters==0.10.2 environs==4.1.0 djangorestframework-xml==1.4.0 +drf-yasg==1.17.1 Faker==0.9.1 flake8==3.6.0 furl==2.0.0