[Schema Inaccuracy] Consider using discriminator properties for union types

Open
#2,974 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reviewing the OpenAPI definition for GET /repos/{owner}/{repo}/contents/{path} and its content-directory, content-file, content-symlink, and content-submodule schemas. Determine whether an existing property can support the discriminator or whether a new one is needed, then verify that the union maps each response type and improves client deserialization.

Written by the indexing model from the issue text.

Description

content feature P3 rest-schema

Schema Inaccuracy

GET /repos/{owner}/{repo}/contents/{path}

Was recently updated from a single "object" schema to

application/json:
              schema:
                oneOf:
                - "$ref": "#/components/schemas/content-directory"
                - "$ref": "#/components/schemas/content-file"
                - "$ref": "#/components/schemas/content-symlink"
                - "$ref": "#/components/schemas/content-submodule"

While this is great to #650 's point as it more accurately describes the possible values, it also makes deserialization work on client applications much harder.

Expected

Consider adding something along the lines of

discriminator:
            propertyName: newPropertyName
            mapping:
              content-file: "#/components/schemas/content-file"
              content-submodule: "#/components/schemas/content-submodule"
              content-symlink: "#/components/schemas/content-symlink"

(this would require introducing a new property if one with the mapping values doesn't already exist)

This way client applications can match the discrimator mapping value with the object type during deserialization.

Reproduction Steps

Dominant language
No language data
Stars
1.6k
Forks
342
Avg merge
3h 33m
Merged PRs (30d)
51

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.

More from github/rest-api-description

All issues in github/rest-api-description

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.