How do I assign a different pydantic.Field() to each type within a union? In the example below, the Field(pattern=...) should only apply to the str.
class Foo(BaseModel):
bar: str | FooDetail = Field(pattern=r'[bar]+') # but this should only apply to str
class FooDetail(BaseModel):
baz: int
fob: float
You can use
Annotatedto specify both the type and theField, and then still create a union from that withFooDetail: