Add: swagger

This commit is contained in:
2023-08-12 02:32:31 +09:00
parent 94640a70fa
commit 2ae385b941
6 changed files with 1148 additions and 7 deletions

View File

@@ -36,6 +36,7 @@ INSTALLED_APPS = [
'collector.apps.CollectorConfig', # main app
'rest_framework',
'django_filters',
'drf_spectacular',
"crispy_forms",
"crispy_bootstrap5",
'django_cleanup.apps.CleanupConfig', # required bottom
@@ -149,6 +150,18 @@ REST_FRAMEWORK = {
'rest_framework.parsers.MultiPartParser'
],
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend', ], # noqa:E501
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
# 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', # noqa:E501
# 'PAGE_SIZE': 3,
}
# https://drf-spectacular.readthedocs.io/en/latest/readme.html
# TODO: set environ vars config!
SPECTACULAR_SETTINGS = {
'TITLE': 'Logs collector API',
'DESCRIPTION': 'Collector of archives with log files for further analysis',
'VERSION': '0.1.0',
'SERVE_INCLUDE_SCHEMA': True,
'SERVE_PUBLIC': False,
'SERVERS': [{'url': 'https://example.com/v1', 'description': 'Text'},],
}

View File

@@ -18,6 +18,13 @@ from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from drf_spectacular.views import (
SpectacularAPIView,
SpectacularRedocView,
SpectacularSwaggerView
)
from logs_collector import settings
@@ -26,6 +33,21 @@ urlpatterns = [
path('', include('collector.urls', namespace='collector')),
]
urlpatterns += [
# API PATTERNS
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
# Optional UI:
path(
'api/schema/swagger-ui/',
SpectacularSwaggerView.as_view(url_name='schema'),
name='swagger-ui'
),
path(
'api/schema/redoc/',
SpectacularRedocView.as_view(url_name='schema'),
name='redoc'
),
]
if settings.DEBUG:
urlpatterns += static(