openedx / openedx/api-doc-tools

Handle paginated responses better

Open
#32 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.