新功能(dvadmin): 接入drf-yasg,进行swagger形式的api展示
parent
959faf6ec4
commit
e17e5cc513
|
@ -46,6 +46,7 @@ INSTALLED_APPS = [
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
'captcha',
|
'captcha',
|
||||||
'django_celery_beat',
|
'django_celery_beat',
|
||||||
|
'drf_yasg', # swagger 接口
|
||||||
# 自定义app
|
# 自定义app
|
||||||
'apps.vadmin.permission',
|
'apps.vadmin.permission',
|
||||||
'apps.vadmin.op_drf',
|
'apps.vadmin.op_drf',
|
||||||
|
@ -332,4 +333,4 @@ CELERYBEAT_SCHEDULER = 'django_celery_beat.schedulers.DatabaseScheduler' # Back
|
||||||
# 接口权限
|
# 接口权限
|
||||||
INTERFACE_PERMISSION = locals().get("INTERFACE_PERMISSION", False)
|
INTERFACE_PERMISSION = locals().get("INTERFACE_PERMISSION", False)
|
||||||
DJANGO_CELERY_BEAT_TZ_AWARE = False
|
DJANGO_CELERY_BEAT_TZ_AWARE = False
|
||||||
CELERY_TIMEZONE = 'Asia/Shanghai' # celery 时区问题
|
CELERY_TIMEZONE = 'Asia/Shanghai' # celery 时区问题
|
||||||
|
|
|
@ -23,7 +23,21 @@ from django.views.static import serve
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from apps.vadmin.op_drf.response import SuccessResponse
|
from apps.vadmin.op_drf.response import SuccessResponse
|
||||||
|
from rest_framework import permissions
|
||||||
|
from drf_yasg.views import get_schema_view
|
||||||
|
from drf_yasg import openapi
|
||||||
|
schema_view = get_schema_view(
|
||||||
|
openapi.Info(
|
||||||
|
title="Snippets API",
|
||||||
|
default_version='v1',
|
||||||
|
description="Test description",
|
||||||
|
terms_of_service="https://www.google.com/policies/terms/",
|
||||||
|
contact=openapi.Contact(email="contact@snippets.local"),
|
||||||
|
license=openapi.License(name="BSD License"),
|
||||||
|
),
|
||||||
|
public=True,
|
||||||
|
permission_classes=[permissions.AllowAny],
|
||||||
|
)
|
||||||
|
|
||||||
class CaptchaRefresh(APIView):
|
class CaptchaRefresh(APIView):
|
||||||
authentication_classes = []
|
authentication_classes = []
|
||||||
|
@ -42,4 +56,8 @@ class CaptchaRefresh(APIView):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
re_path(r'media/(?P<path>.*)', serve, {"document_root": settings.MEDIA_ROOT}),
|
re_path(r'media/(?P<path>.*)', serve, {"document_root": settings.MEDIA_ROOT}),
|
||||||
re_path(r'^admin/', include('apps.vadmin.urls')),
|
re_path(r'^admin/', include('apps.vadmin.urls')),
|
||||||
|
re_path(r'^$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
||||||
|
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'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -44,7 +44,6 @@ class CaptchaRefresh(APIView):
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
re_path('api-token-auth/', LoginView.as_view(), name='api_token_auth'),
|
re_path('api-token-auth/', LoginView.as_view(), name='api_token_auth'),
|
||||||
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||||
url(r'docs/', include_docs_urls(title='接口文档')),
|
|
||||||
re_path(r'^login/$', LoginView.as_view()),
|
re_path(r'^login/$', LoginView.as_view()),
|
||||||
re_path(r'^logout/$', LogoutView.as_view()),
|
re_path(r'^logout/$', LogoutView.as_view()),
|
||||||
re_path(r'^getInfo/$', GetUserProfileView.as_view()),
|
re_path(r'^getInfo/$', GetUserProfileView.as_view()),
|
||||||
|
|
Loading…
Reference in New Issue