FastAPI 0.140.6 has been released, focusing on a behind-the-scenes refactor that improves OpenAPI schema generation. The key change, introduced in PR #16073 by @tiangolo, avoids flattening dependencies that are used as request parameters.
Previously, when a dependency returned a Pydantic model or similar object that was then used as a request parameter (e.g., via Depends()), FastAPI would flatten that model's fields into the endpoint's parameter list in the OpenAPI schema. This could lead to overly verbose or inaccurate API documentation, especially when dependencies are shared across multiple endpoints.
With 0.140.6, FastAPI no longer flattens such dependencies by default. Instead, the dependency is treated as a single parameter object in the OpenAPI spec, preserving its structure and making the API documentation cleaner and more accurate.
- Core change: Avoid flattening dependencies for request parameters in OpenAPI generation (PR #16073).
- Impact: Endpoints using
Depends()with a Pydantic model will now show that model as a single schema object in OpenAPI rather than listing its individual fields. - Improvement: This refactor does not affect runtime behavior; it only changes how the OpenAPI schema is generated.
For developers, this means that if you are using dependencies to define reusable request parameter groups (like common query parameters), the generated OpenAPI docs will now reflect your intended structure more precisely. This can improve client code generation and API documentation clarity.
Source: https://github.com/fastapi/fastapi/releases/tag/0.140.6