Skip to content

Commit 259950c

Browse files
authored
Replace coreapi by drf-spectacular for API docs (#107)
1 parent f4063d7 commit 259950c

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

requirements.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ djangorestframework==3.16.1
22
Django==5.2.12
33
Pygments==2.19.1
44
Markdown==3.10.2
5-
coreapi==2.3.3
65
inflection==0.5.1
76
psycopg[binary]==3.3.3
87
dj-database-url==3.1.2
98
gunicorn==25.1.0
109
whitenoise==6.12.0
1110
PyYAML==6.0.3
12-
# Needed by copreapi on Python 3.13+
13-
legacy-cgi; python_version>='3.13'
14-
# coreapi depends on pkg_resources which was part of setuptools until v82
15-
setuptools<82
11+
drf-spectacular==0.29.0

tutorial/settings.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'whitenoise.runserver_nostatic',
3939
'django.contrib.staticfiles',
4040
'rest_framework',
41+
'drf_spectacular',
4142
'snippets.apps.SnippetsConfig',
4243
]
4344

@@ -127,7 +128,15 @@
127128
'PAGE_SIZE': 10,
128129
'DEFAULT_PAGINATION_CLASS':
129130
'rest_framework.pagination.PageNumberPagination',
130-
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
131+
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
132+
}
133+
134+
# DRF Spectacular settings
135+
SPECTACULAR_SETTINGS = {
136+
'TITLE': 'Pastebin API',
137+
'DESCRIPTION': 'A Web API for creating and viewing highlighted code snippets.',
138+
'VERSION': '1.0.0',
139+
'SERVE_INCLUDE_SCHEMA': False,
131140
}
132141

133142
if ENVIRONMENT == 'production':

tutorial/urls.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
from django.urls import include, path
2-
from rest_framework.schemas import get_schema_view
3-
from rest_framework.documentation import include_docs_urls
4-
5-
API_TITLE = 'Pastebin API'
6-
API_DESCRIPTION = 'A Web API for creating and viewing highlighted code snippets.'
7-
schema_view = get_schema_view(title=API_TITLE)
2+
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
83

94
urlpatterns = [
105
path('', include('snippets.urls')),
116
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
12-
path('schema/', schema_view),
13-
path('docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
7+
path('schema/', SpectacularAPIView.as_view(), name='schema'),
8+
path('docs/', SpectacularSwaggerView.as_view(url_name='schema'))
149
]

0 commit comments

Comments
 (0)