Skip to content

Commit a948eac

Browse files
authored
Merge pull request #27 from golony6449/feature/golony/swagger
swagger (drf-spectacular) 추가
2 parents 136f577 + c3c8c81 commit a948eac

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
1. Import the include() function: from django.urls import include, path
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
16+
from django.conf import settings
1617
from django.contrib import admin
1718
from django.urls import include, path
19+
from drf_spectacular.views import (
20+
SpectacularAPIView,
21+
SpectacularRedocView,
22+
SpectacularSwaggerView,
23+
)
1824

1925
import sponsor.routers
2026

@@ -24,3 +30,19 @@
2430
path("admin/", admin.site.urls),
2531
path("sponsors/", include(sponsor.routers.get_router().urls)),
2632
]
33+
34+
if settings.DEBUG is True:
35+
urlpatterns += [
36+
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
37+
# Optional UI:
38+
path(
39+
"api/schema/swagger-ui/",
40+
SpectacularSwaggerView.as_view(url_name="schema"),
41+
name="swagger-ui",
42+
),
43+
path(
44+
"api/schema/redoc/",
45+
SpectacularRedocView.as_view(url_name="schema"),
46+
name="redoc",
47+
),
48+
]

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)