我希望根据特定条件动态分配字段数据类型。以下是我的模型:
class Connection(BaseModel):
name: str
# type can be GCS or ORACLE
type: str
details: GCSDetails/OracleDetails
class GCSDetails(BaseModel):
bucket: str
folderName: str
class OracleDetails(BaseModel):
host: str
port: int
user: str
那么,基于“类型”,即GCS或ORACLE,如何在验证期间动态更改“详细信息”数据类型
Pydantic
可以通过Union
类型because执行此操作,而无需使用额外的type
字段输出:
相关问题 更多 >
编程相关推荐