one "nice to have" (but definitely not mandatory) feature here is a BeforeValidator that casts a simple string to {"type": "thing"}
def _str_to_type_dict(obj: Any) -> Any:
if isinstance(obj, str):
return {"type": obj}
return obj
AnyController = Annotated[..., BeforeValidator(_str_to_type_dict), Field(discriminator="type")]
then you can
Camera(controller="orbit")
but again, not mandatory, and anyone familiar with pydantic also knows they can do
Camera(controller={"type": "orbit"})
Originally posted by @tlambert03 in #42 (comment)
one "nice to have" (but definitely not mandatory) feature here is a BeforeValidator that casts a simple string to
{"type": "thing"}then you can
but again, not mandatory, and anyone familiar with pydantic also knows they can do
Originally posted by @tlambert03 in #42 (comment)