-
Describe the bug To Reproduce
Expected behavior Actual behavior
Environment:
Additional context It's also noteworthy that the problem doesn't exist for all kinds of typing syntax. Doing a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
@wozniakty
from fastapi import FastAPI, Query
app = FastAPI()
@app.get("/items/")
async def read_items(q: str = Query(..., min_length=3)):
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
if q:
results.update({"q": q})
return results
So you can just use It goes on to say:
Personally, I more frequently want to handle any kind of list as JSON than as a query parameter, but I think it could make sense to handle lists of primitive types (float, int, str, bool and optional varieties) as query parameters by default. But this would be a breaking change, so unclear whether it's worth it. |
Beta Was this translation helpful? Give feedback.
-
Ok thanks, I apparently missed some of the nuance in the documentation, my bad. From my first read through the documentation, I would say that it feels a bit weird for a string list (fairly common query param type) is assumed to be a body. However, I can see why that might be harder to differentiate from a list containing a more complex object. I'll close this out. Was a bit of a hard to understand nuance but it's obviously not a bug. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Thanks @dmontagu for your help! 🚀 🍰 🌮 Thanks @wozniakty for reporting back and closing the issue. |
Beta Was this translation helpful? Give feedback.
@wozniakty
This is discussed in the query parameters and string validation docs:
So you can just use
Query(...)
if you want it to be required with no default and no other keyword arguments. (This is also consisten…