From b07179f121584be308fb528394ee25daf0713797 Mon Sep 17 00:00:00 2001 From: sosokker Date: Sun, 5 Nov 2023 22:15:25 +0700 Subject: [PATCH 1/2] Add Swagger Doc --- backend/core/settings.py | 11 ++++++++++- backend/core/urls.py | 4 ++++ requirements.txt | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/core/settings.py b/backend/core/settings.py index 84cd4c5..34f56d0 100644 --- a/backend/core/settings.py +++ b/backend/core/settings.py @@ -54,6 +54,7 @@ INSTALLED_APPS = [ 'authentications', 'corsheaders', + 'drf_spectacular', 'allauth', 'allauth.account', @@ -76,7 +77,15 @@ REST_FRAMEWORK = { 'rest_framework.authentication.TokenAuthentication', 'rest_framework_simplejwt.authentication.JWTAuthentication', 'dj_rest_auth.jwt_auth.JWTCookieAuthentication', - ] + ], + 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', +} + +SPECTACULAR_SETTINGS = { + 'TITLE': 'Your Project API', + 'DESCRIPTION': 'Your project description', + 'VERSION': '1.0.0', + 'SERVE_INCLUDE_SCHEMA': False, } REST_USE_JWT = True diff --git a/backend/core/urls.py b/backend/core/urls.py index 418903f..a02869c 100644 --- a/backend/core/urls.py +++ b/backend/core/urls.py @@ -16,6 +16,7 @@ Including another URLconf """ from django.contrib import admin from django.urls import path, include +from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView urlpatterns = [ path('admin/', admin.site.urls), @@ -23,4 +24,7 @@ urlpatterns = [ path('api/', include('tasks.urls')), path('api/', include('authentications.urls')), path('accounts/', include('allauth.urls')), + path('api/schema/', SpectacularAPIView.as_view(), name='schema'), + path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), + path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'), ] \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2f9a5c4..98f2a15 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,5 @@ google_api_python_client>=2.1 google_auth_oauthlib>=1.1 google-auth-httplib2>=0.1 django-storages[s3]>=1.14 -Pillow>=10.1 \ No newline at end of file +Pillow>=10.1 +drf-spectacular>=0.26 \ No newline at end of file From 194fdc3dbc4bec817c0f29d53f88314c51d64e76 Mon Sep 17 00:00:00 2001 From: sosokker Date: Sun, 5 Nov 2023 22:19:29 +0700 Subject: [PATCH 2/2] Update swagger settings --- backend/core/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/core/settings.py b/backend/core/settings.py index 34f56d0..5c01d05 100644 --- a/backend/core/settings.py +++ b/backend/core/settings.py @@ -82,8 +82,8 @@ REST_FRAMEWORK = { } SPECTACULAR_SETTINGS = { - 'TITLE': 'Your Project API', - 'DESCRIPTION': 'Your project description', + 'TITLE': 'TurTask API', + 'DESCRIPTION': 'API documentation for TurTask', 'VERSION': '1.0.0', 'SERVE_INCLUDE_SCHEMA': False, }