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

Pagination properties missing in list responses in OpenAPI schemas #6846

Closed
5 of 6 tasks
reupen opened this issue Jul 29, 2019 · 3 comments
Closed
5 of 6 tasks

Pagination properties missing in list responses in OpenAPI schemas #6846

reupen opened this issue Jul 29, 2019 · 3 comments

Comments

@reupen
Copy link
Contributor

reupen commented Jul 29, 2019

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

  1. Create a generic view set using a pagination class e.g. LimitOffsetPagination
  2. Generate an OpenAPI schema

Expected behavior

  1. The keys that the pagination class wrap the results in appear in the list operation response schema e.g. count, next, previous and results for LimitOffsetPagination

Actual behavior

  1. These properties aren't present. (There doesn't seem to a way for a pagination class to tell AutoSchema about what its responses look like.)

(Additionally, if no pagination class is specified, the response schema should be an array rather than an object.)

@carltongibson
Copy link
Collaborator

Yes, good.

AutoSchema could check if a pagination class was defined. (Then we can see what might need adding to the pagination classes.)

Fancy working on a PR?

In the meantime I think a subclass (that Just Knows) will be required.

@reupen reupen changed the title Pagination properties missing in responses in OpenAPI schemas Pagination properties missing in list responses in OpenAPI schemas Jul 29, 2019
@reupen
Copy link
Contributor Author

reupen commented Jul 29, 2019

Yes, why not.

I'd probably do it in these steps:

  1. Make AutoSchema._get_responses() check if it's a list operation and make the response an array if so.
  2. Give pagination classes a way to tell AutoSchema about their responses (possibly just let them wrap response schemas like they do for the responses themselves).

reupen added a commit to reupen/django-rest-framework that referenced this issue Jul 30, 2019
This is the first part of encode#6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes further modify list responses.

There should be no change for views not determined to be list views.
reupen added a commit to reupen/django-rest-framework that referenced this issue Jul 30, 2019
This is the first part of encode#6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes modify list responses.

There should be no change for views not determined to be list views.
reupen added a commit to reupen/django-rest-framework that referenced this issue Jul 30, 2019
This is the first part of encode#6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes modify list responses.

There should be no change for views not determined to be list views.
reupen added a commit to reupen/django-rest-framework that referenced this issue Jul 30, 2019
This is the first part of encode#6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes modify list responses.

There should be no change for views not determined to be list views.
reupen added a commit to reupen/django-rest-framework that referenced this issue Jul 30, 2019
This is the first part of encode#6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes modify list responses.

There should be no change for views not determined to be list views.
carltongibson pushed a commit that referenced this issue Aug 7, 2019
This is the first part of #6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes modify list responses.

There should be no change for views not determined to be list views.
reupen added a commit to reupen/django-rest-framework that referenced this issue Aug 11, 2019
Refs encode#6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the paginator adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
reupen added a commit to reupen/django-rest-framework that referenced this issue Aug 11, 2019
Refs encode#6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the pagination class adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
reupen added a commit to reupen/django-rest-framework that referenced this issue Aug 11, 2019
Refs encode#6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the pagination class adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
reupen added a commit to reupen/django-rest-framework that referenced this issue Aug 11, 2019
Refs encode#6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the pagination class adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
carltongibson pushed a commit that referenced this issue Sep 3, 2019
Refs #6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the pagination class adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
@carltongibson
Copy link
Collaborator

This is now resolved. Thanks @reupen!

pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this issue Nov 17, 2020
This is the first part of encode#6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes modify list responses.

There should be no change for views not determined to be list views.
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this issue Nov 17, 2020
Refs encode#6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the pagination class adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
sigvef pushed a commit to sigvef/django-rest-framework that referenced this issue Dec 3, 2022
This is the first part of encode#6846.

Previously, the response schema for list views was an object representing a single item. However, list views return a list of items, and hence it should be an array.

Further work will need to be done to support how pagination classes modify list responses.

There should be no change for views not determined to be list views.
sigvef pushed a commit to sigvef/django-rest-framework that referenced this issue Dec 3, 2022
Refs encode#6846

This provides a way for pagination classes to add pagination properties (`count`, `next`, `results` etc.) to OpenAPI response schemas.

A new method `get_paginated_response_schema()` has been added to `BasePagination`. This method is intended to mirror `get_paginated_response()` (which takes a `list` and wraps it in a `dict`). 

Hence, `get_paginated_response_schema()` takes an unpaginated response schema (of type `array`) and wraps that with a schema object of type `object` containing the relevant properties that the pagination class adds to responses.

The default implementation of `BasePagination.get_paginated_response_schema()` simply passes the schema through unmodified, for backwards compatibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants