I want to assign field data type dynamically based on specific conditions. Below are my models:
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
So, based on "type" i.e. GCS or ORACLE how do I dynamically change the "details" data type during validation?
Pydantic
could do this without using an additionaltype
field by means of theUnion
type, becauseOutput: