-
Notifications
You must be signed in to change notification settings - Fork 32
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
OpenAPI Discriminator support #31
Comments
There is an open PR #18 and several issues on vertx-web repo, like vert-x3/vertx-web#1820 (some from the old vertx-web-api-contract). |
So Optional keywordFirst and foremost, the
From this spec sentence, my understanding is that, when using discriminator together with
Schema nameNow, the real issue with MyResponseType:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Lizard'
discriminator:
propertyName: petType components:
schemas:
Pet:
type: object
required:
- petType
properties:
petType:
type: string
discriminator:
propertyName: petType
mapping:
dog: Dog
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Cat`
properties:
name:
type: string
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Dog`
properties:
bark:
type: string
Lizard:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Lizard`
properties:
lovesRocks:
type: boolean And also there is a keyword in json schema called Inside
|
Hello, we really would like to use Our use case: components:
schemas:
Spec:
type: object
properties:
specType:
type: string
enum:
- "SPEC_A"
- "SPEC_B"
required:
- specType
discriminator:
propertyName: specType
mapping:
SPEC_A: '#/components/schemas/SpecA'
SPEC_B: '#/components/schemas/SpecB'
SpecA:
allOf:
- $ref: '#/components/schemas/Spec'
- type: object
properties:
someAdditionalProperty:
type: string
required:
- someAdditionalProperty
SpecB:
allOf:
- $ref: '#/components/schemas/Spec'
- type: object
properties:
someOtherAdditionalProperty:
type: integer
minimum: 0
required:
- someOtherAdditionalProperty So that the following bodies are considered valid:
But these are considered invalid:
|
You can easily achieve the same result without
You can keep the discriminator, definition if you want to, because it will be just ignored by the schema parser. The case you proposed is exactly one of those really hard situations we can't easily implement #31 (comment) |
One of the use case I see of discriminator+oneOf is when reporting validation errors to the user. If none of the schema match, you probably want to report only why the discriminator-specified schema didn't match. |
This issue is intended to collect thoughts about an eventual
discriminator
support. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#schemaObjectThe text was updated successfully, but these errors were encountered: