1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 04:06:47 +00:00

feat(api): migrate API documentation from drf-yasg to drf-spectacular

- Replace abandoned drf-yasg with drf-spectacular and drf-spectacular-sidecar
- Configure OpenAPI 3.0 schema generation and offline sidecar assets in settings
- Update schema, Swagger UI, and ReDoc routes in webvirtcloud/urls.py
- Add backwards-compatible AutoSchema fallback for existing settings installations
- Remove 130 obsolete legacy drf-yasg static assets
- Update upgrade instructions in README.md and project documentation
This commit is contained in:
catborise 2026-09-25 08:08:36 +03:00
parent 6d8a62a95e
commit 67364e2a05
136 changed files with 44 additions and 15995 deletions

View file

@ -33,7 +33,8 @@ INSTALLED_APPS = [
"django_bootstrap_icons",
"django_otp",
"django_otp.plugins.otp_totp",
"drf_yasg",
"drf_spectacular",
"drf_spectacular_sidecar",
"accounts",
"admin",
"appsettings",
@ -269,6 +270,21 @@ OTP_ENABLED = False
LOGIN_REQUIRED_IGNORE_VIEW_NAMES = ["accounts:login", "accounts:email_otp"]
# REST Framework & OpenAPI (drf-spectacular)
REST_FRAMEWORK = {
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
SPECTACULAR_SETTINGS = {
"TITLE": "Webvirtcloud REST-API",
"DESCRIPTION": "Webvirtcloud REST API",
"VERSION": "v1",
"SERVE_INCLUDE_SCHEMA": False,
"SWAGGER_UI_DIST": "SIDECAR",
"SWAGGER_UI_FAVICON_HREF": "SIDECAR",
"REDOC_DIST": "SIDECAR",
}
# EMAIL Config
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'

View file

@ -1,25 +1,24 @@
from django.conf import settings
from django.urls import include, path, re_path
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from drf_spectacular.views import (
SpectacularAPIView,
SpectacularRedocView,
SpectacularSwaggerView,
)
from appsettings.views import appsettings
from console.views import console
from instances.views import index
# Fallback for existing installations where REST_FRAMEWORK.DEFAULT_SCHEMA_CLASS is not configured in settings.py
user_rf = getattr(settings, "REST_FRAMEWORK", None)
if not user_rf or "DEFAULT_SCHEMA_CLASS" not in user_rf:
try:
from rest_framework.settings import api_settings
from drf_spectacular.openapi import AutoSchema
schema_view = get_schema_view(
openapi.Info(
title="Webvirtcloud REST-API",
default_version='v1',
description="Webvirtcloud REST API",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="catborise@gmail.com"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
api_settings.DEFAULT_SCHEMA_CLASS = AutoSchema
except (ImportError, AttributeError):
pass
urlpatterns = [
path("", index, name="index"),
@ -34,9 +33,10 @@ urlpatterns = [
path("logs/", include("logs.urls")),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
path('api/v1/', include("webvirtcloud.urls-api")),
re_path(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
path("api/schema/", SpectacularAPIView.as_view(), name="schema"),
re_path(r"^swagger\.(?P<format>json|yaml)$", SpectacularAPIView.as_view(), name="schema-json"),
path("swagger/", SpectacularSwaggerView.as_view(url_name="schema"), name="schema-swagger-ui"),
path("redoc/", SpectacularRedocView.as_view(url_name="schema"), name="schema-redoc"),
]
if settings.DEBUG: