swagger-api / swagger-api/swagger.io-docs

suggested supplement to docs on polymorphism

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

Nobody has claimed this yet.

triaged
Dominant language
Astro
Stars
1.6k
Forks
407
Avg merge
2m
Merged PRs (30d)
2

Description

Documentation at https://swagger.io/docs/specification/v3_0/data-models/inheritance-and-polymorphism/ includes this text:

Mapping Type Names

It is implied, that the property to which discriminator refers, contains the name of the target schema. In the example above, the objectType property should contain either simpleObject, or complexObject string. If the property values do not match the schema names, you can map the values to the names. To do this, use the discriminator/mapping keyword:

It seems to me that the docs should point out that this can and should be enforced using enum: like this:

            simpleObject:
              type: object       
              required:
                - objectType       
              properties:
                objectType:
                  type: string
                  enum: [simpleObject]
            complexObject:
              type: object       
              required:
                - objectType       
              properties:
                objectType:
                  type: string
                  enum: [complexObject]

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 with the “Mapping Type Names” section at the Swagger documentation URL in the issue and review how the discriminator examples describe matching property values. Add guidance that matching can be enforced with an enum and include the supplied schema example. The documentation is done when the recommendation and example are clear and consistent with the surrounding polymorphism guidance.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.