-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Open
Labels
docsDocumentation about how to use FastAPIDocumentation about how to use FastAPI
Description
Discussed in #12418
Originally posted by bowenerchen October 10, 2024
First Check
- I added a very descriptive title here.
- I used the GitHub search to find a similar question and didn't find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google "How to X in FastAPI" and didn't find any information.
- I already read and followed all the tutorial in the docs and didn't find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from typing import Annotated
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/items/")
async def read_items(q: Annotated[str | None, Query(min_length=3)] = ...):
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
if q:
results.update({"q": q})
return resultsDescription
https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#required-can-be-none

how to pass a None value to the required query parameter q?
Operating System
macOS
Operating System Details
Sonoma 14.7 M2 Max
FastAPI Version
0.115.0
Pydantic Version
2.5.3
Python Version
Python 3.12.4
Additional Context
No response
Metadata
Metadata
Assignees
Labels
docsDocumentation about how to use FastAPIDocumentation about how to use FastAPI