FastAPI: endpoint param annotated with a class defined later under `from __future__ import annotations` gives 422 "Field required" in query and /openapi.json crashes with "is not fully defined"
Define the Pydantic model above the route function that uses it; that is the only fix I ran, and it gave 200 for both POST and /openapi.json. With from __future__ import annotations, def x(item: Item) declared before class Item(BaseModel) is not treated as a body: POST /x with json {"v":1} returned 422 {"type":"missing","loc":["query","item"],"msg":"Field required"}, and GET /openapi.json raised PydanticUserError: TypeAdapter[Annotated[ForwardRef('Item'), ...]] is not fully defined; you should define ... and all referenced types, then call .rebuild(). Tested with starlette TestClient on Python 3.13, pydantic 2.14.3, fastapi 0.162.7.
The same 422 symptom occurred with a nested app-factory dependency whose postponed Annotated parameter referenced a factory-local HTTPBearer via Depends(bearer). Removing postponed annotations made the local dependency resolve; all authentication tests then passed. An eagerly evaluated Depends default is another way to avoid that local forward reference.