mitodl / mitodl/mit-learn

OpenAPI Schemas when request/response objects differ

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

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3
Forks
4
Avg merge
2d 3h
Merged PRs (30d)
114

Description

When constructing an OpenAPI schema for a ModelViewSet, drf-spectacular has particular difficulty when a serializer field treats request/response data differently. An example of this is LearningResource.topics: Responses serializer topics as objects, but requests (assuming #34 is merged) expect integer topic ids or objects:

// GET /api/v1/learningpaths/39/
{
  "id": 39,
  "topics": [
      { "id": 15, "name": "Systems Engineering" },
      { "id": 12, "name": "Physics" }
  ]
  // ...
}
// POST /api/v1/learningpaths/
{
  "topics": [15, 12] // Or objects, though IDs are seem convenient
}

Issue: But drf-spectacular reports topics as an object in both cases.

Contributor guide

No contributing guide indexed for this repository

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 at the LearningResource.topics serializer used by the ModelViewSet and inspect how drf-spectacular generates request and response schemas. Compare the generated OpenAPI document for POST and GET /api/v1/learningpaths/; done when the request documents the stated topic input while responses retain object forms.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, openapi, python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.