As per OAS, when defining discriminator with explicit mapping, should implicit discriminator value still be accepted? #3918
-
Hi, I have not found any information about this in the documentation (potential hint for extension), so I am asking here. Let's say I have the following schema which explicitly defines mapping for Foo:
type: object
discriminator:
propertyName: type
mapping:
BAR: '#/components/schemas/Bar'
BAZ: '#/components/schemas/Baz'
required:
- type
properties:
type:
type: string I know that when a discriminator is not present, an implicit mapping is to be considered to aid (de)serialization, in this case But when I define explicit mapping, should the implicit value still be allowed, or should the API accept only the manually specified options? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
@ondrej-simon
The last example given in the Discriminator Object section actually illustrates this - "Cat" is handled through an implicit mapping, while "dog" is done with an explicit value in |
Beta Was this translation helpful? Give feedback.
-
@ondrej-simon I think you're making this more complicated than it is. The algorithm is very simple:
There are no other checks involved. There's nothing that "masks" based on differences in case. There's nothing preventing multiple values from mapping (implicitly or explicitly) to the same schema. It's just those two steps, nothing else. I've adjusted your scenarios accordingly: Scenario 1 - no mapping specifiedThis scenario is correct as you wrote it (although I'd make similar phrasing changes to the "Result" column as in the next two scenarios. Scenario 2 - partial mapping specifiedSchema definitionFoo:
type: object
discriminator:
propertyName: type
mapping:
BAR: '#/components/schemas/Bar'
required:
- type
properties:
type:
type: string
Bar:
type: object
allOf:
- $ref: '#/components/schemas/Foo'
Baz:
type: object
allOf:
- $ref: '#/components/schemas/Foo' Execution matrix
There is nothing in the Discriminator Object specification that prevents two values ( Scenario 3 - exhaustive mapping specifiedSchema definitionFoo:
type: object
discriminator:
propertyName: type
mapping:
BAR: '#/components/schemas/Bar'
BAZ: '#/components/schemas/Baz'
required:
- type
properties:
type:
type: string
Bar:
type: object
allOf:
- $ref: '#/components/schemas/Foo'
Baz:
type: object
allOf:
- $ref: '#/components/schemas/Foo' Execution matrix
|
Beta Was this translation helpful? Give feedback.
-
Closing as answered |
Beta Was this translation helpful? Give feedback.
@ondrej-simon I think you're making this more complicated than it is. The algorithm is very simple:
There are no other checks involved. There's nothing that "masks" based on differences in case. There's nothing preventing multiple values from mapping (implicitly or explicitly) to the same schema. It's just those two steps, nothing else.
I've adjusted your scenarios accordingly:
Scenario 1 - no mapping specified
This scenario is correct as you wrote it (altho…