简体   繁体   English

在 drf_yasg 上禁用分页检查器

[英]Disable pagination inspector on drf_yasg

I'm using drf_yasg to create my swagger document but I have an issue with PaginationInspector .我正在使用drf_yasg创建我的 swagger 文档,但我遇到了PaginationInspector的问题。 In one of my views I declare a paginator and in swagger, is shown as the default pagination for swagger.在我的一个观点中,我声明了一个分页器,并在 swagger 中显示为 swagger 的默认分页。

Something like this:像这样:

count*  integer #This info is generated automatically by swagger
next    string($uri) #This info is generated automatically by swagger
x-nullable: true #This info is generated automatically by swagger
previous:   string($uri) #This info is generated automatically by swagger
            x-nullable: trueç

results: (THE BODY I ACTUALLY WANT TO SHOW)

在此处输入图像描述

I would like that the swagger ignore that pagination but haven't found any info related to it.我希望 swagger 忽略该分页,但没有找到与之相关的任何信息。

I try using the decorator, initially I though it could be something like @swagger_auto_schema(paginator_inspectors=False) but it doesn't work and I can't find anything useful on the docs.我尝试使用装饰器,最初我虽然它可能类似于@swagger_auto_schema(paginator_inspectors=False)但它不起作用而且我在文档中找不到任何有用的东西。 Thanks in advance提前致谢

oh and just in case this is my view:哦,以防万一这是我的观点:

class CharacterView(ListChView):
    class OutputSerializer(serializers.Serializer):
        id = serializers.CharField(source="external_id")
        created_at = serializers.DateTimeField()

    pagination_class = CustomPagination

Just override get_paginated_response_schema method.只需覆盖get_paginated_response_schema方法。

class CustomPagination(PageNumberPagination):
    ...
    # add
    def get_paginated_response_schema(self, schema):
        return {
            'type': 'object',
            'properties': {
                'results': schema,
            },
        }
    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM