You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
FastAPI does not validate custom string build using Annotated[str, StringConstraints(...)]
Temporary solution My solution is to annotate the constrained type with Path again, then it seems to work:
fromtypingimportAnnotatedfromfastapiimportFastAPI, PathfrompydanticimportStringConstraints# In my case this is imported from a lib with pydantic but without fastapi,# so it can't be changed to Annotated[str, Path(pattern=r"^[a-fA-F0-9]+$")]Identifier=Annotated[str, StringConstraints(pattern=r"^[a-fA-F0-9]+$")]
app=FastAPI()
@app.get("/{some_id}")asyncdefget_something(some_id: Annotated[Identifier, Path()]):
returnsome_id
Feature request
Would be nice if fastapi would be able to get the constraint directly from the Identifier type without being required to add Annotated[Identifier, Path()].
Problem:
FastAPI does not validate custom string build using
Annotated[str, StringConstraints(...)]
Temporary solution
My solution is to annotate the constrained type with Path again, then it seems to work:
Feature request
Would be nice if fastapi would be able to get the constraint directly from the
Identifier
type without being required to addAnnotated[Identifier, Path()]
.Originally posted by @JasperJuergensen in #10105 (comment)
The text was updated successfully, but these errors were encountered: