mirror of https://github.com/jumpserver/jumpserver
perf: swagger auth required
parent
94ed26e115
commit
ea59677b13
|
@ -91,7 +91,7 @@ cache_kwargs = {
|
||||||
}
|
}
|
||||||
# docs 路由
|
# docs 路由
|
||||||
urlpatterns += [
|
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/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'),
|
re_path('api/redoc/?', views.get_swagger_view().with_ui('redoc', **cache_kwargs), name='redoc'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
from drf_yasg import openapi
|
from drf_yasg import openapi
|
||||||
from drf_yasg.generators import OpenAPISchemaGenerator
|
from drf_yasg.generators import OpenAPISchemaGenerator
|
||||||
from drf_yasg.inspectors import SwaggerAutoSchema
|
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 ..urls import api_v1
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
patterns = [
|
patterns = [
|
||||||
path('api/v1/', include(api_v1))
|
path('api/v1/', include(api_v1))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
with_auth = os.environ.get('DOC_AUTH', '1') == '1'
|
||||||
if with_auth:
|
if with_auth:
|
||||||
permission_classes = (permissions.IsAuthenticated,)
|
permission_classes = (permissions.IsAuthenticated,)
|
||||||
public = False
|
public = False
|
||||||
|
|
Loading…
Reference in New Issue