openedx / openedx/api-doc-tools
Handle paginated responses better
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
Sometimes, drf-yasg can't figure out the appropriate serializer for a class. That's not a problem if we have a serializer on hand to pass to schema:
@schema(responses={200: MySerializer})
def get(...):
""" My view """
For paginated views, this becomes a problem, because we don't have a paginated serializer to give schema.
I see two solutions to this:
1. Help drf-yasg figure out paginated serializers better
Why can't drf-yasg generate a correct paginated response schema? Are we missing a class variable on our views? Are we using DRF wrong?
2. Provide a manual paginate_serializer function as a fall-back
In the case where drf-yasg just can't figure out the response schema, it'd be great to be able to do something like:
@schema(responses={200: paginate_serializer(MySerializer, MyPaginationClass)})
def get(...):
""" My paginated view """
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the drf-yasg schema handling described in the issue, focusing on how paginated serializers are inferred and how schema accepts response serializers. Compare the two proposed approaches involving paginate_serializer, MySerializer, and MyPaginationClass; done requires an agreed solution that produces a correct paginated response schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100