Discriminator
Generate pydantic classes with discriminators based on OpenAPI discriminators. The original OpenAPI specification must have the propertyName
and mapping
fields.
Example
For OpenAPI schema
DiscriminatedOneOfResp:
title: All Of Resp
type: object
required: ['required_discriminated_animal']
properties:
discriminated_animal:
discriminator:
mapping: {cat: '#/components/schemas/CatWithKind', dog: '#/components/schemas/DogWithKind'}
propertyName: kind
oneOf:
- {$ref: '#/components/schemas/CatWithKind'}
- {$ref: '#/components/schemas/DogWithKind'}
title: Animal
required_discriminated_animal:
discriminator:
mapping: {cat: '#/components/schemas/CatWithKind', dog: '#/components/schemas/DogWithKind'}
propertyName: kind
oneOf:
- {$ref: '#/components/schemas/CatWithKind'}
- {$ref: '#/components/schemas/DogWithKind'}
title: Animal