Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange extend_schema behaviour with pagination and custom action #183

Closed
LesPrimus opened this issue Oct 29, 2020 · 3 comments
Closed

Strange extend_schema behaviour with pagination and custom action #183

LesPrimus opened this issue Oct 29, 2020 · 3 comments

Comments

@LesPrimus
Copy link

Hi

Let's say i have a view like this one:

class BookViewSet(viewsets.ModelViewSet):
    queryset = Book.objects.all()
    serializer_class = serializers.BookSerializer

    @extend_schema(
        responses={200: inline_serializer(
            name='TitleSerializer',
            fields={'title': rest_serializers.CharField()},
            many=True
        )}
    )
    @action(methods=["GET"], detail=True)
    def get_title(self, request, *args, **kwargs):
        return Response()

    @extend_schema(
        responses={200: inline_serializer(
            name='GenreSerializer',
            fields={'genre': rest_serializers.CharField()},
            many=True
        )}
    )
    @action(methods=["GET"], detail=True)
    def get_genre(self, request, *args, **kwargs):
        return Response()

Here the schema is correct:
image
But here is not:
image

Must be:

{
  "count": 123,
  "next": "http://api.example.org/accounts/?offset=400&limit=100",
  "previous": "http://api.example.org/accounts/?offset=200&limit=100",
  "results": [
    {
      "genre": "string"
    }
  ]
}

Settings:

REST_FRAMEWORK = {
    'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
}
SPECTACULAR_SETTINGS = {
    'SWAGGER_UI_SETTINGS': {
            'filter': True,
            "displayOperationId": True,
        },
    'TITLE': 'MY PROJECT SETTINGS',
    'VERSION': '1.1.1',
}

Can you help me? or I'm missing something?

@tfranzel
Copy link
Owner

hi @LesPrimus. your example looks fine. it looks like a bug that happens only with pagination. i'll investigate.

@tfranzel
Copy link
Owner

that should fix it. small oversight in name generation for many=True aka ListSerializer

please confirm and close issue if resolved.

@LesPrimus
Copy link
Author

Confirm... Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants