Skip to content

suggested supplement to docs on polymorphism #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jehrlich opened this issue Feb 25, 2025 · 0 comments
Open

suggested supplement to docs on polymorphism #388

jehrlich opened this issue Feb 25, 2025 · 0 comments

Comments

@jehrlich
Copy link

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant