Fix flattening of query/header/cookie param models with sibling params#15130
Fix flattening of query/header/cookie param models with sibling params#15130maksimzayats wants to merge 6 commits intofastapi:masterfrom
Conversation
|
Hi folks! Could somebody please take a look? |
|
Hi @maksimzayats, this seems to be a duplicate of #12481. Could you checkout that branch and report back whether it solves things for your use-case? |
|
Orb Code Review (powered by GLM 5.1 on Orb Cloud) Review of PR #15130: Fix flattening of query/header/cookie param models with sibling paramsThis is a significant enhancement that removes a long-standing limitation where Pydantic parameter models (e.g., What looks good ✅
Concerns 🟡
SummarySolid feature enhancement with excellent test coverage. The main improvement opportunity is reducing the duplicated OpenAPI parameter-building code. The name collision edge case should be considered, even if the current behavior is documented as undefined. Assessment: comment (code duplication, edge cases worth discussing) |
Summary
Fix Pydantic query/header/cookie models so they still flatten when there are sibling params in the same location.
Problem
FastAPI only flattened these models when they were the only param there:
Annotated[MyModel, Query()]Annotated[MyModel, Header()]Annotated[MyModel, Cookie()]If you added a sibling param like
extra: Query()orextra: Header(), the model stopped flattening. That broke request parsing, validation errors, and OpenAPI docs.Fix
Model-backed query/header/cookie params now flatten consistently, even with sibling params.
This keeps existing behavior for the single-model case and preserves:
Old vs New
Before:
FastAPI could treat
mlike one query param instead of flattening it intolimitandq.After:
limit,q, andextraare all handled as separate query paramsmSame fix applies to
Header()andCookie().