Skip to content

Commit b33c912

Browse files
committed
Add Swagger documentation for the live functionalities
1 parent 51e10eb commit b33c912

8 files changed

Lines changed: 485 additions & 8 deletions

File tree

atv/settings.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
API_KEY_CUSTOM_HEADER=(str, "HTTP_X_API_KEY"),
4545
FIELD_ENCRYPTION_KEYS=(list, []),
4646
ENABLE_AUTOMATIC_ATTACHMENT_FILE_DELETION=(bool, True),
47+
ENABLE_SWAGGER_UI=(bool, True),
4748
)
4849
if os.path.exists(env_file):
4950
env.read_env(env_file)
@@ -118,6 +119,7 @@
118119
"corsheaders",
119120
"encrypted_fields",
120121
"guardian",
122+
"drf_spectacular",
121123
# Local apps
122124
"users",
123125
"services",
@@ -159,7 +161,9 @@
159161
REST_FRAMEWORK = {
160162
"DEFAULT_PERMISSION_CLASSES": [
161163
"rest_framework.permissions.IsAdminUser",
162-
]
164+
],
165+
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
166+
"DEFAULT_PARENT_LOOKUP_KWARG_NAME_PREFIX": "",
163167
}
164168

165169
ATTACHMENT_MEDIA_DIR = "attachments"
@@ -193,6 +197,15 @@
193197
if not DEBUG and DEBUG_FIELD_ENCRYPTION_KEY in FIELD_ENCRYPTION_KEYS:
194198
raise ImproperlyConfigured("Cannot use the debug encryption key in production")
195199

200+
# API Documentation
201+
ENABLE_SWAGGER_UI = env("ENABLE_SWAGGER_UI")
202+
203+
SPECTACULAR_SETTINGS = {
204+
"TITLE": " Asiointitietovaranto ",
205+
"DESCRIPTION": "Asiointitietovaranto REST API",
206+
"VERSION": "0.0.1",
207+
}
208+
196209
LOGGING = {
197210
"version": 1,
198211
"disable_existing_loggers": False,

atv/urls.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
from django.conf import settings
12
from django.contrib import admin
23
from django.http import HttpResponse
34
from django.urls import include, path
5+
from drf_spectacular.views import (
6+
SpectacularAPIView,
7+
SpectacularRedocView,
8+
SpectacularSwaggerView,
9+
)
410
from rest_framework_extensions.routers import ExtendedSimpleRouter
511

612
from documents.api import AttachmentViewSet, DocumentViewSet
@@ -11,7 +17,7 @@
1117
r"attachments",
1218
AttachmentViewSet,
1319
basename="documents-attachments",
14-
parents_query_lookups=["document"],
20+
parents_query_lookups=["document_id"],
1521
)
1622

1723

@@ -21,9 +27,26 @@
2127
]
2228

2329

30+
if settings.ENABLE_SWAGGER_UI:
31+
urlpatterns += [
32+
path("v1/schema/", SpectacularAPIView.as_view(), name="schema"),
33+
path(
34+
"v1/schema/swagger/",
35+
SpectacularSwaggerView.as_view(url_name="schema"),
36+
name="swagger",
37+
),
38+
path(
39+
"v1/schema/redoc/",
40+
SpectacularRedocView.as_view(url_name="schema"),
41+
name="redoc",
42+
),
43+
]
44+
2445
#
2546
# Kubernetes liveness & readiness probes
2647
#
48+
49+
2750
def healthz(*args, **kwargs):
2851
return HttpResponse(status=200)
2952

documents/api/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .viewsets import AttachmentViewSet, DocumentViewSet
2+
3+
__all__ = [
4+
"AttachmentViewSet",
5+
"DocumentViewSet",
6+
]

0 commit comments

Comments
 (0)