Disable pagination inspector on drf_yasg

795 Views Asked by At

I'm using drf_yasg to create my swagger document but I have an issue with PaginationInspector. In one of my views I declare a paginator and in swagger, is shown as the default pagination for 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)

enter image description here

I would like that the swagger ignore that pagination but haven’t found any info related to it.

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. 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
1

There are 1 best solutions below

0
On

Just override get_paginated_response_schema method.

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