为什么 drf-yasg openapi 文档不起作用?
Why don't work drf-yasg openapi documentation?
为什么 drf-yasg 文档不起作用。我只看到默认设置。
api_patterns = [
url(r'^api/v1/users/', include('apps.users.urls')),
]
schema_view = get_schema_view(
openapi.Info("PlasticJam", 'v1'),
patterns=api_patterns,
public=True,
)
urlpatterns += [
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
观看次数
@method_decorator(swagger_auto_schema(
manual_parameters=[openapi.Parameter(
name='users_count', in_=openapi.IN_QUERY, type='int', description='Count of users'
)],
responses={'200': 'ok'}), name='list'
)
class UserListApiView(ListAPIView):
"""
list:
Users detail statistic
Get dates range for statistic
"""
queryset = User.objects.all()
serializer_class = UserListSerializer
在 UserListApiView class 中,您应该覆盖 get 并将装饰器放在它的顶部。
@method_decorator(swagger_auto_schema(manual_parameters=[openapi.Parameter( name='users_count', in_=openapi.IN_QUERY, type='int', description='Count of users')],responses={'200': 'ok'}), name='list')
def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)
为什么 drf-yasg 文档不起作用。我只看到默认设置。
api_patterns = [
url(r'^api/v1/users/', include('apps.users.urls')),
]
schema_view = get_schema_view(
openapi.Info("PlasticJam", 'v1'),
patterns=api_patterns,
public=True,
)
urlpatterns += [
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
观看次数
@method_decorator(swagger_auto_schema(
manual_parameters=[openapi.Parameter(
name='users_count', in_=openapi.IN_QUERY, type='int', description='Count of users'
)],
responses={'200': 'ok'}), name='list'
)
class UserListApiView(ListAPIView):
"""
list:
Users detail statistic
Get dates range for statistic
"""
queryset = User.objects.all()
serializer_class = UserListSerializer
在 UserListApiView class 中,您应该覆盖 get 并将装饰器放在它的顶部。
@method_decorator(swagger_auto_schema(manual_parameters=[openapi.Parameter( name='users_count', in_=openapi.IN_QUERY, type='int', description='Count of users')],responses={'200': 'ok'}), name='list')
def get(self, request, *args, **kwargs):
return super().get(request, *args, **kwargs)