✨ Allow to have multiple Query parameter models
Currently, it's allowed to have only one model as a query/headers/etc model parameter, in this PR I propose to remove this restriction. This PR should be backward-compatible.
For instance, example below will not work:
from typing import Annotated
from pydantic import BaseModel
from fastapi import FastAPI, Query
app = FastAPI()
class FilterParams(BaseModel):
name: str
age: int
class PageParams(BaseModel):
limit: int
offset: int
@app.get("/")
async def route(
filters: Annotated[FilterParams, Query()],
page: Annotated[PageParams, Query()],
):
return {}
And same here:
from typing import Annotated
from pydantic import BaseModel
from fastapi import FastAPI, Query
app = FastAPI()
class FilterParams(BaseModel):
name: str
age: int
@app.get("/")
async def route(
filters: Annotated[FilterParams, Query()],
limit: Annotated[int, Query()],
offset: Annotated[int, Query()],
):
return {}
WIth this PR both examples above will work as expected. Also, it will generate the correct OpenAPI schema:
Discussion - https://github.com/fastapi/fastapi/discussions/12212
This looks similar to #12481
I agree, It does solve the same issue. I didn't see it when I started working on this PR(
Hope this gets approved and released soon !
This looks awesome! Really looking forward to it! Do we know if/when it'll be approved and released?
Do we know when this will be published? It would make things easier.
Just merged with master and fixed tests, @Kludex any chance you can take a look on this PR? 🙏
@Ale-Cas can you please take a look at this ?
is this merging soon? would be nice to have pagination and query on models in FastAPI, which is blocked on merging this PR ....
This pull request has a merge conflict that needs to be resolved.
Just chiming in that my team are also interested in this feature. :pray:
I've just noticed that the same limitation seems to affect Form(), could this fix be extended to cover form POST as well?
This pull request has a merge conflict that needs to be resolved.