diff --git a/pyconkr/settings.py b/pyconkr/settings.py index 2b193e8..d2c7ff1 100644 --- a/pyconkr/settings.py +++ b/pyconkr/settings.py @@ -44,6 +44,8 @@ "constance.backends.database", # apps "sponsor", + # swagger + "drf_spectacular", ] MIDDLEWARE = [ @@ -145,3 +147,25 @@ "후원사 변동사항에 대한 알림을 보낼 채널", ), } + +# drf-spectacular +REST_FRAMEWORK = { + # YOUR SETTINGS + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", +} + +SPECTACULAR_SETTINGS = { + "TITLE": "pyconkr-api-v2", + "DESCRIPTION": "파이콘 한국 웹서비스용 API (2023 ~ )", + "VERSION": "1.0.0", + "SERVE_INCLUDE_SCHEMA": True, + # available SwaggerUI configuration parameters + # https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/ + "SWAGGER_UI_SETTINGS": { + "deepLinking": True, + "persistAuthorization": True, + "displayOperationId": True, + }, + # available SwaggerUI versions: https://github.com/swagger-api/swagger-ui/releases + "SWAGGER_UI_DIST": "//unpkg.com/swagger-ui-dist@3.35.1", +} diff --git a/pyconkr/urls.py b/pyconkr/urls.py index d00d408..7f70d1c 100644 --- a/pyconkr/urls.py +++ b/pyconkr/urls.py @@ -13,8 +13,14 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf import settings from django.contrib import admin from django.urls import include, path +from drf_spectacular.views import ( + SpectacularAPIView, + SpectacularRedocView, + SpectacularSwaggerView, +) import sponsor.routers @@ -24,3 +30,19 @@ path("admin/", admin.site.urls), path("sponsors/", include(sponsor.routers.get_router().urls)), ] + +if settings.DEBUG is True: + urlpatterns += [ + path("api/schema/", SpectacularAPIView.as_view(), name="schema"), + # Optional UI: + 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", + ), + ] diff --git a/requirements.txt b/requirements.txt index 895cfb4..523fdff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ django-summernote==0.8.20.0 Pillow==9.4.0 django-constance==2.9.1 django-picklefield==3.1 +drf-spectacular==0.25.1