-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get the StringConstraints directly from the Identifier type #10322
Comments
What the OP wants is this: from typing import Annotated
from fastapi import FastAPI, Path
from pydantic import StringConstraints
Identifier = Annotated[str, StringConstraints(pattern=r"^[a-fA-F0-9]+$")]
app = FastAPI()
@app.get("/{some_id}")
async def get_something(some_id: Identifier):
return some_id A similar feature request is to use |
It is because missing the matadata when none of Annotated args is |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: