Optional Query Parameters Don't Generate Correct OpenAPI Schema #10481
-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
from fastapi import Query
app = FastAPI()
@app.get("/works")
async def works(x: int = Query(default=None)):
return {"test": x}
@app.get("/does_not_work")
async def does_not_work(x: int | None):
return {"test": x}Description
Operating SystemWindows Operating System DetailsNo response FastAPI Version0.104.0 Pydantic Version2.4.2 Python Version3.10.10 (Also was seeing this on 3.11) Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
|
I tried this with |
Beta Was this translation helpful? Give feedback.
-
|
Hi @pythonweb2 in order to avoid the @app.get("/does_not_work")
async def does_not_work(x: int | None = None):
return {"test": x}
|
Beta Was this translation helpful? Give feedback.
-
|
I'm also getting the validation error as expected when trying to pass a non-integer value |
Beta Was this translation helpful? Give feedback.
-
|
The fix seems to be in progress here: #9873 |
Beta Was this translation helpful? Give feedback.






The fix seems to be in progress here: #9873