-
Hello, I have some types I reuse in multiple models, but I need to repeat the MyID = Annotated[str, StringConstraints(pattern=r"^ABC\d{3}$")]
class Foo(BaseModel):
id: MyID = Field(examples=["ABC123"])
class Bar(BaseModel):
foo_id: MyID = Field(examples=["ABC123"]) I can’t find a way to move the examples on the annotated type instead, although it would make sense because these exemples are inherent to the type itself and not where the fields are defined. Is there some way to factorize this, so I can use Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's should be possible to use field on annotated level: MyID = Annotated[
str,
StringConstraints(pattern=r"^ABC\d{3}$"),
Field(examples=["ABC123"]),
]
class Foo(BaseModel):
id: MyID
class Bar(BaseModel):
foo_id: MyID |
Beta Was this translation helpful? Give feedback.
It's should be possible to use field on annotated level: