Skip to content

Commit 3ffb90e

Browse files
committed
update: swagger (drf-spectacular) 추가
1 parent e5fdf73 commit 3ffb90e

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

pyconkr/settings.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
"constance.backends.database",
4545
# apps
4646
"sponsor",
47+
# swagger
48+
"drf_spectacular",
4749
]
4850

4951
MIDDLEWARE = [
@@ -145,3 +147,25 @@
145147
"후원사 변동사항에 대한 알림을 보낼 채널",
146148
),
147149
}
150+
151+
# drf-spectacular
152+
REST_FRAMEWORK = {
153+
# YOUR SETTINGS
154+
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
155+
}
156+
157+
SPECTACULAR_SETTINGS = {
158+
"TITLE": "pyconkr-api-v2",
159+
"DESCRIPTION": "파이콘 한국 웹서비스용 API (2023 ~ )",
160+
"VERSION": "1.0.0",
161+
"SERVE_INCLUDE_SCHEMA": True,
162+
# available SwaggerUI configuration parameters
163+
# https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
164+
"SWAGGER_UI_SETTINGS": {
165+
"deepLinking": True,
166+
"persistAuthorization": True,
167+
"displayOperationId": True,
168+
},
169+
# available SwaggerUI versions: https://github.com/swagger-api/swagger-ui/releases
170+
"SWAGGER_UI_DIST": "//unpkg.com/[email protected]",
171+
}

pyconkr/urls.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,34 @@
1616
from django.contrib import admin
1717
from django.urls import include, path
1818

19+
from drf_spectacular.views import (
20+
SpectacularAPIView,
21+
SpectacularRedocView,
22+
SpectacularSwaggerView,
23+
)
24+
1925
import sponsor.routers
26+
import pyconkr.settings as settings
2027

2128
urlpatterns = [
2229
path("api-auth/", include("rest_framework.urls")),
2330
path("summernote/", include("django_summernote.urls")),
2431
path("admin/", admin.site.urls),
2532
path("sponsors/", include(sponsor.routers.get_router().urls)),
2633
]
34+
35+
if settings.DEBUG is True:
36+
urlpatterns += [
37+
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
38+
# Optional UI:
39+
path(
40+
"api/schema/swagger-ui/",
41+
SpectacularSwaggerView.as_view(url_name="schema"),
42+
name="swagger-ui",
43+
),
44+
path(
45+
"api/schema/redoc/",
46+
SpectacularRedocView.as_view(url_name="schema"),
47+
name="redoc",
48+
),
49+
]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ django-summernote==0.8.20.0
1414
Pillow==9.4.0
1515
django-constance==2.9.1
1616
django-picklefield==3.1
17+
drf-spectacular==0.25.1

0 commit comments

Comments
 (0)