According to the docs it is possible to pass a list of values https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#query-parameter-list-multiple-values .
I have tried on my end and the endpoint http://localhost:8000/items/?q=foo&q=bar correctly process the values as a list:
{"q":["foo","bar"]}
But the docs do not, and interpret it as a string and do not render multiple options:
Here is my main.py:
from db import engine,get_db
from models import Example,ExampleModel,Base,Color,Item
from fastapi import FastAPI,Depends,Query,Path
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import select
from contextlib import asynccontextmanager
from typing import Annotated,Union,List
from fastapi.responses import HTMLResponse
@asynccontextmanager
async def lifespan(app: FastAPI):
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
yield
app = FastAPI(lifespan=lifespan) # type: ignore
@app.get("/items/")
async def read_items(q: Annotated[List[str] | None, Query()] = None):
query_items = {"q": q}
return query_items

Annotated, as demonstrated here?Annotatedis preferred way now because of pydantic2.0.Annotated[List[str], Query()] = Nonedoes the thing. But it looks incorrect:')async def read_items(q: list[str] | None = Query(default=None)):tried but didn't workAnnotated[list[str],Query()] = None):but pylance complains about typing