Skip to content

Commit

Permalink
Alpha: Add Spectacular to expose API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-smith committed Apr 14, 2024
1 parent 239be9e commit 2231b7c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions backend/ciso_assistant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def set_ciso_assistant_url(_, __, event_dict):
"library",
"serdes",
"rest_framework",
"drf_spectacular",
]

MIDDLEWARE = [
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion backend/ciso_assistant/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2231b7c

Please sign in to comment.