Skip to content

OneOf: Implicit mapping#932

Merged
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
Antonboom:feat/oneof-implicit-mapping
Mar 14, 2023
Merged

OneOf: Implicit mapping#932
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
Antonboom:feat/oneof-implicit-mapping

Conversation

@Antonboom
Copy link
Copy Markdown
Contributor

@Antonboom Antonboom commented Jan 22, 2023

Closes #712


From https://swagger.io/specification/#discriminator-object.

In scenarios where the value of the discriminator field does not match the schema name or implicit mapping is not possible, an optional mapping definition MAY be used:

MyResponseType:
  oneOf:
  - $ref: '#/components/schemas/Cat'
  - $ref: '#/components/schemas/Dog'
  - $ref: '#/components/schemas/Lizard'
  - $ref: 'https://gigantic-server.com/schemas/Monster/schema.json'
  discriminator:
    propertyName: petType
    mapping:
      dog: '#/components/schemas/Dog'
      monster: 'https://gigantic-server.com/schemas/Monster/schema.json'

Here the discriminator value of dog will map to the schema #/components/schemas/Dog, rather than the default (implicit) value of Dog. If the discriminator value does not match an implicit or explicit mapping, no schema can be determined and validation SHOULD fail. Mapping keys MUST be string values, but tooling MAY convert response values to strings for comparison.

@MysterySuperhero
Copy link
Copy Markdown

+1

Comment thread pkg/codegen/schema.go Outdated
@Antonboom Antonboom requested review from Warboss-rus and kbakdev and removed request for Warboss-rus and kbakdev January 27, 2023 19:13
Copy link
Copy Markdown
Contributor

@Warboss-rus Warboss-rus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Antonboom Antonboom requested review from Warboss-rus and kbakdev and removed request for Warboss-rus and kbakdev March 14, 2023 04:48
@Antonboom
Copy link
Copy Markdown
Contributor Author

@deepmap-marcinr
Copy link
Copy Markdown
Contributor

deepmap-marcinr commented Mar 14, 2023

This looks like a very good change, and doesn't appear to break any generated code, but changes to oneOf/anyOf are terrifying to me since they are so riddled with special cases.

@deepmap-marcinr deepmap-marcinr merged commit 7fd8f39 into oapi-codegen:master Mar 14, 2023
@Antonboom
Copy link
Copy Markdown
Contributor Author

@deepmap-marcinr when do you plan to make the new tag? :)

adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
adrianpk added a commit to foorester/oapi-codegen that referenced this pull request May 31, 2024
danicc097 pushed a commit to danicc097/oapi-codegen that referenced this pull request Aug 31, 2024
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

Successfully merging this pull request may close these issues.

The decriminator is set only if the "mapping" field is present

5 participants