perf: swagger auth required

pull/15529/head^2
ibuler 2025-06-06 14:12:41 +08:00 committed by 老广
parent 94ed26e115
commit ea59677b13
2 changed files with 5 additions and 2 deletions

View File

@ -91,7 +91,7 @@ cache_kwargs = {
}
# docs 路由
urlpatterns += [
path('api/swagger.<format>', views.get_swagger_view(False).without_ui(**cache_kwargs), name='schema-json'),
path('api/swagger.<format>', views.get_swagger_view().without_ui(**cache_kwargs), name='schema-json'),
re_path('api/docs/?', views.get_swagger_view().with_ui('swagger', **cache_kwargs), name="docs"),
re_path('api/redoc/?', views.get_swagger_view().with_ui('redoc', **cache_kwargs), name='redoc'),
]

View File

@ -1,3 +1,5 @@
import os
from drf_yasg import openapi
from drf_yasg.generators import OpenAPISchemaGenerator
from drf_yasg.inspectors import SwaggerAutoSchema
@ -149,13 +151,14 @@ api_info = openapi.Info(
)
def get_swagger_view(with_auth=True):
def get_swagger_view():
from ..urls import api_v1
from django.urls import path, include
patterns = [
path('api/v1/', include(api_v1))
]
with_auth = os.environ.get('DOC_AUTH', '1') == '1'
if with_auth:
permission_classes = (permissions.IsAuthenticated,)
public = False