Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview: Add Spectacular to expose API documentation #253

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading