|
|
@@ -13,10 +13,49 @@ Including another URLconf
|
|
|
1. Import the include() function: from django.urls import include, path
|
|
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
|
|
"""
|
|
|
+from rest_framework import permissions
|
|
|
from django.contrib import admin
|
|
|
-from django.urls import path, include
|
|
|
+from django.urls import path, include, re_path
|
|
|
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
|
|
|
|
|
|
+from drf_yasg import openapi
|
|
|
+from drf_yasg.views import get_schema_view
|
|
|
+from drf_yasg.inspectors import CoreAPICompatInspector, FieldInspector, NotHandled, SwaggerAutoSchema
|
|
|
+
|
|
|
+schema_view = get_schema_view(
|
|
|
+ openapi.Info(
|
|
|
+ title="云飞监控API文档",
|
|
|
+ default_version="v1",
|
|
|
+ description="""
|
|
|
+<strong>HTTP状态码</strong>:
|
|
|
+ 200 表示成功
|
|
|
+ 400 表示请求失败
|
|
|
+ 403 表示无权限访问
|
|
|
+ 500 表示服务器异
|
|
|
+
|
|
|
+<strong>接口返回格式统一为</strong>:
|
|
|
+
|
|
|
+{
|
|
|
+ "msg": "", 错误描述信息,正常响应下此为空字符串,只有错误异常情况下才有内容
|
|
|
+ "code": 0, 响应状态码:0表示正确,400表示请求错误,403表示无权限访问,500表示服务器异常。
|
|
|
+ "result": {
|
|
|
+ "data": {}, 后端返回的数据, 格式为对象或者数组,没有数据返回为空对象
|
|
|
+ "paging": { # 分页信息,如果没有分页,则为空对象
|
|
|
+ 'next': 1, # 下一页页码
|
|
|
+ 'previous': 1, # 上一页页码
|
|
|
+ 'total': 10, # 总页数
|
|
|
+ 'page': 1, # 当前页
|
|
|
+ 'page_size': 5, # 每页条目数
|
|
|
+ 'total_page': 10 # 总页数
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+"""
|
|
|
+ ),
|
|
|
+ public=True,
|
|
|
+ permission_classes=(permissions.AllowAny, )
|
|
|
+)
|
|
|
+
|
|
|
|
|
|
api_urlpatterns = [
|
|
|
path('', include('monitor_app.urls'))
|
|
|
@@ -29,4 +68,7 @@ urlpatterns = [
|
|
|
path('api/schema/', SpectacularAPIView.as_view(), name='schema'),
|
|
|
path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'),
|
|
|
path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'),
|
|
|
+
|
|
|
+ re_path(r'doc/swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
|
|
|
+ re_path(r'doc/redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
|
|
|
]
|