You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
In our OAS3.1 specifications we make use of the polymorphism and inheritance feature. As you describe in your documentation on how to use discriminator, there are mainly two strategies:
oneOf/anyOf in combination with discriminator understood as a 'super schema'
discriminator in the 'parent schema' combined with allOf in the 'child schema'
We prefer the allOf approach since it is more suitable with code generators in our context. However in the latter case the properties of the child schemas (Dog and Cat) are not validated. We understand that from a JsonSchema point of view the discriminator is not not/limited supported. Do you have this on the road map to support discriminator based validation of child schema in the allOf context or do you have any other suggestion on how this could be achieved in combination with redocly lint?
Here are two samples of the szenario which both contain an error in the Dog property 'barkSound' (The value is not a member of the enum):
The first implements the oneOf/discriminator strategy with a SuperSchema (PetSuper) and validates the error correctly (Warning was generated by the no-invalid-media-type-examples rule.)
The second implements our preferred discriminator/allOf strategy but does not create an error on validation.
Both were validated with redocly lint and no configuration file.
Example with oneOf/discriminator
openapi: 3.1.0info:
title: Example APIversion: 1.0.0license:
name: Apache 2.0url: https://www.apache.org/licenses/LICENSE-2.0.htmlservers:
- description: Sample Server URLurl: https://api.usz.chsecurity: []tags: []paths:
/pet:
get:
summary: This is a summarydescription: This is a description.operationId: getPetresponses:
'200':
description: Get petcontent:
application/json:
schema:
$ref: '#/components/schemas/PetSuper'examples:
Cat:
value:
id: id-of-catpetType: CatmotherPet:
id: id-of-mother-catpetType: CatwhiskersLength: 12Dog:
value:
id: id-of-dogpetType: DogmotherPet:
id: id-of-mother-dogpetType: DogbarkSound: QuietbarkSound: VeryLoud'400':
description: Unexpected errorcontent:
application/json:
schema:
type: stringcomponents:
schemas:
Pet:
type: objectproperties:
id:
type: stringpetType:
$ref: '#/components/schemas/PetType'motherPet:
$ref: '#/components/schemas/PetSuper'required:
- id
- petTypePetSuper:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'discriminator:
propertyName: petTypemapping:
Dog: '#/components/schemas/Dog'Cat: '#/components/schemas/Cat'Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: objectproperties:
whiskersLength:
type: integerdescription: Length of cat's whiskersDog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: objectproperties:
barkSound:
type: stringdescription: Sound of dog's barkenum:
- Loud
- QuietPetType:
type: stringdescription: Type of the Petenum:
- Cat
- Dog
Example with discriminator/allOf
openapi: 3.1.0info:
title: Pet Polymorph APIversion: 1.0.0license:
name: Apache 2.0url: https://www.apache.org/licenses/LICENSE-2.0.htmlservers:
- description: Sample Server URLurl: https://api.sampleurl.chsecurity: []tags: []paths:
/pet:
get:
summary: This is a summarydescription: This is a description.operationId: getPetresponses:
'200':
description: Get petcontent:
application/json:
schema:
$ref: '#/components/schemas/Pet'examples:
Cat:
value:
id: id-of-catpetType: CatmotherPet:
id: id-of-mother-catpetType: CatwhiskersLength: 12Dog:
value:
id: id-of-dogpetType: DogmotherPet:
id: id-of-mother-dogpetType: DogbarkSound: QuietbarkSound: VeryLoud'400':
description: Unexpected errorcontent:
application/json:
schema:
type: stringcomponents:
schemas:
Pet:
type: objectproperties:
id:
type: stringpetType:
$ref: '#/components/schemas/PetType'motherPet:
$ref: '#/components/schemas/Pet'required:
- id
- petTypediscriminator:
propertyName: petTypemapping:
Dog: '#/components/schemas/Dog'Cat: '#/components/schemas/Cat'Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: objectproperties:
whiskersLength:
type: integerdescription: Length of cat's whiskersDog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: objectproperties:
barkSound:
type: stringdescription: Volume of sound of dog's barkenum:
- Loud
- QuietPetType:
type: stringdescription: Type of the Petenum:
- Cat
- Dog
Describe the solution you'd like
We would love redocly lint to validate child schemas based on the discriminator property.
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
In our OAS3.1 specifications we make use of the polymorphism and inheritance feature. As you describe in your documentation on how to use discriminator, there are mainly two strategies:
We prefer the allOf approach since it is more suitable with code generators in our context. However in the latter case the properties of the child schemas (Dog and Cat) are not validated. We understand that from a JsonSchema point of view the discriminator is not not/limited supported. Do you have this on the road map to support discriminator based validation of child schema in the allOf context or do you have any other suggestion on how this could be achieved in combination with redocly lint?
Here are two samples of the szenario which both contain an error in the Dog property 'barkSound' (The value is not a member of the enum):
The first implements the oneOf/discriminator strategy with a SuperSchema (PetSuper) and validates the error correctly (Warning was generated by the no-invalid-media-type-examples rule.)
The second implements our preferred discriminator/allOf strategy but does not create an error on validation.
Both were validated with
redocly lint
and no configuration file.Example with oneOf/discriminator
Example with discriminator/allOf
Describe the solution you'd like
We would love
redocly lint
to validate child schemas based on the discriminator property.Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: