Предположим, у нас есть следующая настройка пидантических моделей:
Код: Выделить всё
class ParametersA(BaseModel):
param_a: str = Field(
default=...,
allow_mutation=False,
exclude=False,
description="some description.",
extra={
"additional_bool": False
}
)
param_b: bool = Field(
default=False,
allow_mutation=True,
exclude=False,
description="some description.",
extra={
"additional_bool": False
}
)
# many more parameters of all types with additional constaints (le, gt, max_items,...)
class ParametersB(BaseModel):
param_c: float = Field(
default=-22.0,
exclude=False,
allow_mutation=True,
description="some floaty description",
gt=-180.0,
le=0.0,
extra={
"additional_bool": False,
"unit": "degree"
}
)
param_d: List[str] = Field(
default=["auto"],
exclude=False,
allow_mutation=True,
min_items=1,
max_items=4,
unique_items=True,
description="Some listy description.",
extra={
"auto_mode_available": False
}
)
# many more parameters of all types with additional constaints (le, gt, max_items,...)
Код: Выделить всё
class FullModelX(BaseModel):
parameters_A: ParametersA
parameters_B: ParametersB
Код: Выделить всё
class FullModelY(BaseModel):
parameters_A: ParametersA
parameters_B: ParametersB
Пока мое единственное решение — дублировать параметрыA и параметрыB каждый раз, когда мне нужны какие-то другие ограничения проверки.
Подробнее здесь: https://stackoverflow.com/questions/762 ... -basemodel
Мобильная версия