Compare commits

...
6 Commits
Author SHA1 Message Date
Sebastián Ramírezandgithub-actions[bot] 7ac0f1b541 🔖 Release version 0.140.4 (#16070)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-07-27 15:45:50 +00:00
github-actions[bot] 44e4eeaa78 📝 Update release notes
[skip ci]
2026-07-27 15:36:07 +00:00
Sebastián Ramírez 7134121a71 ️ Skip unused dependency repeat bookkeeping (#16069) 2026-07-27 15:35:29 +00:00
Sebastián Ramírezandgithub-actions[bot] 415d37fa6f 🔖 Release version 0.140.3 (#16068)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-07-27 15:16:54 +00:00
github-actions[bot] ca353d7215 📝 Update release notes
[skip ci]
2026-07-27 15:09:32 +00:00
Sebastián Ramírez d012979f9a ️ Avoid repeated dependency flattening in OpenAPI (#16067) 2026-07-27 15:08:45 +00:00
4 changed files with 49 additions and 24 deletions

No files matched your search

+12
View File
@@ -7,6 +7,18 @@ hide:
## Latest Changes
## 0.140.4 (2026-07-27)
### Refactors
* ⚡️ Skip unused dependency repeat bookkeeping. PR [#16069](https://github.com/fastapi/fastapi/pull/16069) by [@tiangolo](https://github.com/tiangolo).
## 0.140.3 (2026-07-27)
### Refactors
* ⚡️ Avoid repeated dependency flattening in OpenAPI. PR [#16067](https://github.com/fastapi/fastapi/pull/16067) by [@tiangolo](https://github.com/tiangolo).
## 0.140.2 (2026-07-27)
### Refactors
+1 -1
View File
@@ -1,6 +1,6 @@
"""FastAPI framework, high performance, easy to learn, fast to code, ready for production"""
__version__ = "0.140.2"
__version__ = "0.140.4"
from starlette import status as status
+23 -18
View File
@@ -152,16 +152,20 @@ def get_flat_dependant(
parent_oauth_scopes: list[str] | None = None,
_uses_scopes_cache: _UsesScopesCache | None = None,
) -> Dependant:
if visited is None:
visited = []
if _uses_scopes_cache is None:
_uses_scopes_cache = {}
visited.append(
_get_cache_key(
dependant=dependant,
uses_scopes_cache=_uses_scopes_cache,
)
track_visited = (
skip_repeats or visited is not None or _uses_scopes_cache is not None
)
if track_visited:
if visited is None:
visited = []
if _uses_scopes_cache is None:
_uses_scopes_cache = {}
visited.append(
_get_cache_key(
dependant=dependant,
uses_scopes_cache=_uses_scopes_cache,
)
)
use_parent_oauth_scopes = (parent_oauth_scopes or []) + (
_get_oauth_scopes(dependant=dependant)
)
@@ -187,15 +191,16 @@ def get_flat_dependant(
scope=dependant.scope,
)
for sub_dependant in dependant.dependencies:
if (
skip_repeats
and _get_cache_key(
dependant=sub_dependant,
uses_scopes_cache=_uses_scopes_cache,
)
in visited
):
continue
if skip_repeats:
assert visited is not None
if (
_get_cache_key(
dependant=sub_dependant,
uses_scopes_cache=_uses_scopes_cache,
)
in visited
):
continue
flat_sub = get_flat_dependant(
sub_dependant,
skip_repeats=skip_repeats,
+13 -5
View File
@@ -112,7 +112,7 @@ def get_openapi_security_definitions(
def _get_openapi_operation_parameters(
*,
dependant: Dependant,
flat_dependant: Dependant,
model_name_map: ModelNameMap,
field_mapping: dict[
tuple[ModelField, Literal["validation", "serialization"]], dict[str, Any]
@@ -120,7 +120,6 @@ def _get_openapi_operation_parameters(
separate_input_output_schemas: bool = True,
) -> list[dict[str, Any]]:
parameters = []
flat_dependant = get_flat_dependant(dependant, skip_repeats=True)
path_params = _get_flat_fields_from_params(flat_dependant.path_params)
query_params = _get_flat_fields_from_params(flat_dependant.query_params)
header_params = _get_flat_fields_from_params(flat_dependant.header_params)
@@ -284,12 +283,22 @@ def get_openapi_path(
assert current_response_class, "A response class is needed to generate OpenAPI"
route_response_media_type: str | None = current_response_class.media_type
if route.include_in_schema:
flat_dependant = get_flat_dependant(route.dependant, skip_repeats=True)
all_route_params = [
field
for fields in (
flat_dependant.path_params,
flat_dependant.query_params,
flat_dependant.header_params,
flat_dependant.cookie_params,
)
for field in _get_flat_fields_from_params(fields)
]
for method in route.methods:
operation = get_openapi_operation_metadata(
route=route, method=method, operation_ids=operation_ids
)
parameters: list[dict[str, Any]] = []
flat_dependant = get_flat_dependant(route.dependant, skip_repeats=True)
security_definitions, operation_security = get_openapi_security_definitions(
flat_dependant=flat_dependant
)
@@ -298,7 +307,7 @@ def get_openapi_path(
if security_definitions:
security_schemes.update(security_definitions)
operation_parameters = _get_openapi_operation_parameters(
dependant=route.dependant,
flat_dependant=flat_dependant,
model_name_map=model_name_map,
field_mapping=field_mapping,
separate_input_output_schemas=separate_input_output_schemas,
@@ -458,7 +467,6 @@ def get_openapi_path(
deep_dict_update(openapi_response, process_response)
openapi_response["description"] = description
http422 = "422"
all_route_params = get_flat_params(route.dependant)
if (all_route_params or route.body_field) and not any(
status in operation["responses"]
for status in [http422, "4XX", "default"]