i have model like this:
class Foo(BaseModel): protocol: str protocol_params: Union[ProtoclOneParam, ProtocolTwoParam]
ProtoclOneParam
and ProtocolTwoParam
have no same field with distinguishable value so I can use them as Discriminator
and the only way that I can understand which model should be used for protocol_params
is through the value of protocol
which can either be "protocol1"
or "protocol2"
.
if protocol == "protocol1"
then protocol_params
should be deserialized using the ProtoclOneParam
model and so on.
in actual use cases, there are more than 5 protocols without any distinguishable field among them.
is there any way in pedantic to achieve what I need?