Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastapi/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def get_schema_from_model_field(
# This expects that GenerateJsonSchema was already used to generate the definitions
json_schema = field_mapping[(field, override_mode or field.mode)]
if "$ref" not in json_schema:
# TODO remove when deprecating Pydantic v1
# Set title for field when not using reference
# Ref: https://github.com/pydantic/pydantic/blob/d61792cc42c80b13b23e3ffa74bc37ec7c77f7d1/pydantic/schema.py#L207
json_schema["title"] = (
field.field_info.title or field.alias.title().replace("_", " ")
Expand Down
26 changes: 16 additions & 10 deletions fastapi/openapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,22 @@ def get_openapi_path(
if route.status_code is not None:
status_code = str(route.status_code)
else:
# It would probably make more sense for all response classes to have an
# explicit default status_code, and to extract it from them, instead of
# doing this inspection tricks, that would probably be in the future
# TODO: probably make status_code a default class attribute for all
# responses in Starlette
response_signature = inspect.signature(current_response_class.__init__)
status_code_param = response_signature.parameters.get("status_code")
if status_code_param is not None:
if isinstance(status_code_param.default, int):
status_code = str(status_code_param.default)
# Use cached attribute if available, otherwise fall back to inspection
# This improves performance by avoiding repeated signature inspection
if hasattr(current_response_class, "default_status_code"):
Copy link
Contributor

@dolfinus dolfinus Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither FastAPI, not Starlette have Response.default_status_code field. How exactly adding this check will affect the performance?

status_code = str(current_response_class.default_status_code)
else:
response_signature = inspect.signature(
current_response_class.__init__
)
status_code_param = response_signature.parameters.get("status_code")
if status_code_param is not None:
if isinstance(status_code_param.default, int):
status_code = str(status_code_param.default)
else:
status_code = "200"
else:
status_code = "200"
operation.setdefault("responses", {}).setdefault(status_code, {})[
"description"
] = route.response_description
Expand Down
5 changes: 0 additions & 5 deletions fastapi/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,6 @@ def get_websocket_app(
) -> Callable[[WebSocket], Coroutine[Any, Any, Any]]:
async def app(websocket: WebSocket) -> None:
async with AsyncExitStack() as async_exit_stack:
# TODO: remove this scope later, after a few releases
# This scope fastapi_astack is no longer used by FastAPI, kept for
# compatibility, just in case
websocket.scope["fastapi_astack"] = async_exit_stack
solved_result = await solve_dependencies(
request=websocket,
dependant=dependant,
Expand Down Expand Up @@ -520,7 +516,6 @@ def __init__(
# would pass the validation and be returned as is.
# By being a new field, no inheritance will be passed as is. A new model
# will always be created.
# TODO: remove when deprecating Pydantic v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pydantic v1 is not deprecated yet, why removing TODO?

self.secure_cloned_response_field: Optional[ModelField] = (
create_cloned_field(self.response_field)
)
Expand Down
Loading