Skip to content

Commit d1f1137

Browse files
authored
Merge pull request #76 from darjeeling/swagger_drf_spectacular
add swagger using drf-spectacular
2 parents 5df136b + 9e9190f commit d1f1137

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

pyconweb2022/pyconweb2022/settings.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"content",
4848
"zappa_django_utils",
4949
"martor",
50+
"drf_spectacular",
5051
]
5152

5253
MIDDLEWARE = [
@@ -146,7 +147,8 @@
146147
REST_FRAMEWORK = {
147148
"DEFAULT_PERMISSION_CLASSES": [
148149
"rest_framework.permissions.IsAuthenticated",
149-
]
150+
],
151+
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
150152
}
151153

152154
# Amazon SES

pyconweb2022/pyconweb2022/urls.py

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

19+
from drf_spectacular.views import (
20+
SpectacularAPIView,
21+
SpectacularRedocView,
22+
SpectacularSwaggerView,
23+
)
24+
1925
import pyconemailer.routers
2026
import sponsor.routers
2127
import program.routers
@@ -30,6 +36,19 @@
3036
path("api/news/", include("news.urls")),
3137
path("api/program/", include(program.routers.get_router().urls)),
3238
path("api/content/", include(content.routers.get_router().urls)),
39+
# swagger
40+
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
41+
# Optional UI:
42+
path(
43+
"api/schema/swagger-ui/",
44+
SpectacularSwaggerView.as_view(url_name="schema"),
45+
name="swagger-ui",
46+
),
47+
path(
48+
"api/schema/redoc/",
49+
SpectacularRedocView.as_view(url_name="schema"),
50+
name="redoc",
51+
),
3352
# PyConEmailer
3453
path("pyconemailer/", include("pyconemailer.urls")),
3554
path("api/pyconemailer/", include(pyconemailer.routers.get_router().urls)),

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ Pillow
1515
boto3
1616
Werkzeug
1717
zappa-django-utils
18-
martor
18+
martor
19+
drf-spectacular

0 commit comments

Comments
 (0)