0

为什么不使用 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

4

1 回答 1

1

在 UserListApiView 类中,您应该重写 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)
于 2020-01-26T08:25:07.200 回答