From 4025f6acf2756c7f94dd7997bab8676f82b8a882 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Thu, 28 May 2026 10:07:58 +0545 Subject: [PATCH] feat(src/djinit/templates/config): replace drf_spectacular with drf_yasg for API schema generation - New Features - Switched to drf_yasg and updated schema configuration. - Enhancements - Updated DEFAULT_SCHEMA_CLASS to rest_framework.schemas.coreapi.AutoSchema. - Refactored URL patterns to use drf_yasg schema views. - Bug Fixes - No bug fixes included. --- .../templates/config/settings/base.py-tpl | 14 ++------------ src/djinit/templates/config/urls.py-tpl | 17 +++++++++++------ 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/djinit/templates/config/settings/base.py-tpl b/src/djinit/templates/config/settings/base.py-tpl index 29547fd..2611123 100644 --- a/src/djinit/templates/config/settings/base.py-tpl +++ b/src/djinit/templates/config/settings/base.py-tpl @@ -25,7 +25,7 @@ THIRD_PARTY_APPS = [ "rest_framework_simplejwt", "rest_framework_simplejwt.token_blacklist", "corsheaders", - "drf_spectacular", + "drf_yasg", "django_tailwind_cli", # @IF use_tailwind "django_htmx", # @IF use_htmx ] @@ -138,21 +138,11 @@ REST_FRAMEWORK = { "rest_framework_simplejwt.authentication.JWTAuthentication", "rest_framework.authentication.SessionAuthentication", ), - "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", + "DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema", "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination", "PAGE_SIZE": 20, } -# DRF Spectacular settings -SPECTACULAR_SETTINGS = { - "TITLE": "[[ project_name ]] API", - "DESCRIPTION": "API documentation for [[ project_name ]]", - "VERSION": "1.0.0", - "SERVE_INCLUDE_SCHEMA": False, - "COMPONENT_SPLIT_REQUEST": True, - "SCHEMA_PATH_PREFIX": "/api/", -} - # JWT Settings SIMPLE_JWT = { "ACCESS_TOKEN_LIFETIME": timedelta(days=1), diff --git a/src/djinit/templates/config/urls.py-tpl b/src/djinit/templates/config/urls.py-tpl index 574294f..40a26b3 100644 --- a/src/djinit/templates/config/urls.py-tpl +++ b/src/djinit/templates/config/urls.py-tpl @@ -8,10 +8,8 @@ from django.urls import include # @ENDIF # @IF include_api from django.conf import settings -from drf_spectacular.views import ( - SpectacularAPIView, - SpectacularSwaggerView, -) +from drf_yasg.views import get_schema_view +from drf_yasg import openapi from rest_framework_simplejwt.views import ( TokenObtainPairView, TokenRefreshView, @@ -44,9 +42,16 @@ urlpatterns = [ # Don't show schema in production if settings.DEBUG: + schema_view = get_schema_view( + openapi.Info( + title="[[ project_name ]] API", + default_version="v1", + ), + public=True, + ) urlpatterns += [ - path("schema/", SpectacularAPIView.as_view(), name="schema"), - path("docs/", SpectacularSwaggerView.as_view(url_name="schema")), + path("docs/", schema_view.with_ui("swagger", cache_timeout=0)), + path("schema/", schema_view.with_ui("redoc", cache_timeout=0)), ] # @ENDIF # @ENDIF