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

Response schemas from serializers will optionally be paginated #499

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

PaulWay
Copy link
Contributor

@PaulWay PaulWay commented Nov 22, 2019

At the moment, if a non-default response serializer is set via responses in swagger_auto_schema, it will not pick up any pagination schema that might apply from any paginator inspectors.

This patch will take any serializers provided in the responses section and apply a pagination schema to them if the view should be paged. This does not apply to the default serializer from get_default_responses because that is already converted into a schema.

Signed-off-by: Paul Wayper paulway@redhat.com

Signed-off-by: Paul Wayper <paulway@redhat.com>
@nicholasgcoles
Copy link

@axnsan12 wondering if it is possible to merge this PR?

@nicholasgcoles
Copy link

@PaulWay do you have a workaround for this?

@PaulWay
Copy link
Contributor Author

PaulWay commented Aug 3, 2020

Yeah, unfortunately the workaround is to subclass the view inspector and copy the get_response_schemas method, using my version of the code.

@axnsan12 What's your take on this?

@sondrewb
Copy link

sondrewb commented Aug 13, 2020

Yeah, unfortunately the workaround is to subclass the view inspector and copy the get_response_schemas method, using my version of the code.

@axnsan12 What's your take on this?

Could you please provide an example with code (the workaround) that works for this use-case? Thanks.

@kavdev
Copy link

kavdev commented Oct 2, 2020

@axnsan12 this would be very helpful to have (assuming it's fixed)

kavdev added a commit to kavdev/drf-yasg that referenced this pull request Oct 2, 2020
@@ -264,9 +264,12 @@ def get_response_schemas(self, response_serializers):
)
else:
serializer = force_serializer_instance(serializer)
schema = self.serializer_to_schema(serializer)
if self.should_page():
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.should_page():
if self.has_list_response():
schema = openapi.Schema(type=openapi.TYPE_ARRAY, items=schema)
if self.should_page():

This needs another step to work with current code.

kavdev added a commit to kavdev/drf-yasg that referenced this pull request Oct 2, 2020
@nicholasgcoles
Copy link

Any chance there is an update on this? Such a useful feature.

@PaulWay
Copy link
Contributor Author

PaulWay commented Jan 30, 2021

Sorry, have had this on the back burner - will update this soon!

kavdev added a commit to kavdev/drf-yasg that referenced this pull request Feb 25, 2021
kavdev added a commit to kavdev/drf-yasg that referenced this pull request Feb 25, 2021
@gabrieldev525
Copy link

Some update about this issue? What's missing to finish and release it?

JoelLefkowitz and others added 3 commits July 15, 2022 19:48
Fix old spelling errors and add a cspell configuration.
…-arbitrary-references

Allow specifying response as a reference
@JoelLefkowitz JoelLefkowitz changed the base branch from master to 1.21.x July 17, 2022 17:19
@JoelLefkowitz JoelLefkowitz added 1.21.x Release target in 1.21.x Incomplete help wanted Help wanted and removed 1.21.x Release target in 1.21.x labels Jul 17, 2022
Copy link

@lopezvit lopezvit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exact same changes need to be done as well to line 259, so it also work when you want to add a description to the method:

                    schema = self.serializer_to_schema(serializer)
                    if self.has_list_response():
                        schema = openapi.Schema(type=openapi.TYPE_ARRAY, items=schema)

                    if self.should_page():
                        schema = self.get_paginated_response(schema) or schema
                    response.schema = schema

lopezvit added a commit to lopezvit/drf-yasg that referenced this pull request Aug 31, 2022
This relays on axnsan12#730 and axnsan12#499 but with the newest code, as I need to implement it in my own project
lopezvit added a commit to lopezvit/drf-yasg that referenced this pull request Aug 31, 2022
This relays on axnsan12#730 and axnsan12#499 but with the newest code, as I need to implement it in my own project.
@lopezvit lopezvit mentioned this pull request Aug 31, 2022
lopezvit added a commit to lopezvit/drf-yasg that referenced this pull request Aug 31, 2022
This relays on axnsan12#730 and axnsan12#499 but with the newest code, as I need to implement it in my own project
@JoelLefkowitz JoelLefkowitz deleted the branch axnsan12:master October 17, 2024 11:55
@JoelLefkowitz JoelLefkowitz reopened this Oct 17, 2024
@JoelLefkowitz JoelLefkowitz changed the base branch from 1.21.x to master October 17, 2024 12:08
@JoelLefkowitz JoelLefkowitz added 1.23.x Release target in 1.23.x and removed Incomplete help wanted Help wanted labels Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.23.x Release target in 1.23.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.