I was wondering if there is a workaround to this problem. I want to use NewType
to define and validate query parameters like this:
DefaultQueryType = NewType("DefaultQueryType", Annotated[list[str], Query()])
@app.get("/items/")
async def read_items(q: DefaultQueryType):
query_items = {"q": q}
return query_items
but I get error 422 Error: Unprocessable Entity
– Input should be a valid list.
Does anyone know a workaround for this problem, so defined new type can be used in multiple places without writing it as function paramater every time?
I checked FastAPI github but it seems to be still an issue https://github.com/fastapi/fastapi/discussions/8214#discussioncomment-5148270.
juhumi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.