1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
# generated by datamodel-codegen:
# filename: discriminator_allof.yaml
# timestamp: 2019-07-26T00:00:00+00:00
from __future__ import annotations
from typing import Annotated, Literal
from pydantic import BaseModel, Field
class Pet(BaseModel):
pet_type: Annotated[str, Field(alias='petType')]
class Cat(Pet):
name: str | None = None
pet_type: Literal['cat'] = Field(..., alias='petType')
class Dog(Pet):
bark: str | None = None
pet_type: Literal['dog'] = Field(..., alias='petType')
class Lizard(Pet):
loves_rocks: Annotated[bool | None, Field(alias='lovesRocks')] = None
pet_type: Literal['lizard'] = Field(..., alias='petType')
class PetContainer(BaseModel):
pet: Annotated[Cat | Dog | Lizard, Field(discriminator='pet_type')]
|