diff --git a/backend/ciso_assistant/settings.py b/backend/ciso_assistant/settings.py index a81f56bef..4574b4d27 100644 --- a/backend/ciso_assistant/settings.py +++ b/backend/ciso_assistant/settings.py @@ -147,6 +147,7 @@ def set_ciso_assistant_url(_, __, event_dict): "library", "serdes", "rest_framework", + "drf_spectacular", ] MIDDLEWARE = [ @@ -205,6 +206,7 @@ def set_ciso_assistant_url(_, __, event_dict): "DEFAULT_FILTER_CLASSES": ["django_filters.rest_framework.DjangoFilterBackend"], "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", "PAGE_SIZE": PAGINATE_BY, + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", } if DEBUG: @@ -319,3 +321,11 @@ def set_ciso_assistant_url(_, __, event_dict): "django.contrib.auth.hashers.BCryptSHA256PasswordHasher", "django.contrib.auth.hashers.ScryptPasswordHasher", ] + +SPECTACULAR_SETTINGS = { + 'TITLE': 'CISO Assistant API', + 'DESCRIPTION': 'CISO Assistant - API Documentation', + 'VERSION': '1.0.0', + 'SERVE_INCLUDE_SCHEMA': False, + # OTHER SETTINGS +} diff --git a/backend/ciso_assistant/urls.py b/backend/ciso_assistant/urls.py index ec544b2bd..62b53e3cf 100644 --- a/backend/ciso_assistant/urls.py +++ b/backend/ciso_assistant/urls.py @@ -14,12 +14,16 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.urls import include, path - from ciso_assistant import settings +from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView + # beware of the order of url patterns, this can change de behavior in case of multiple matches and avoid giving identical paths that could cause conflicts urlpatterns = [ path("api/", include("core.urls")), path("serdes/", include("serdes.urls")), path("i18n/", include("django.conf.urls.i18n")), + path('api/schema/', SpectacularAPIView.as_view(), name='schema'), + path('api/schema/swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger'), + path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'), ] diff --git a/backend/requirements.txt b/backend/requirements.txt index 1ffaaebda..78867d692 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -16,3 +16,4 @@ pyyaml==6.0.1 django-structlog==8.0.0 structlog==24.1.0 python-dotenv==1.0.1 +drf-spectacular==0.27.2