Skip to content

Commit cba8ed4

Browse files
committed
fix: resolve mypy TypedDict errors in OpenAPI response handling
- Fixed type handling for OpenAPIResponseContentSchema and OpenAPIResponseContentModel - Removed variable redefinition in _get_openapi_path method - Improved type safety for model field processing - Addresses remaining type checking issues from make pr
1 parent 88528d5 commit cba8ed4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,13 @@ def _get_openapi_path( # noqa PLR0912
661661
else:
662662
# Need to iterate to transform any 'model' into a 'schema'
663663
for content_type, payload in response["content"].items():
664-
new_payload: OpenAPIResponseContentSchema
665-
666664
# Case 2.1: the 'content' has a model
667665
if "model" in payload:
668666
# Find the model in the dependant's extra models
667+
model_payload_typed = cast(OpenAPIResponseContentModel, payload)
669668
return_field = next(
670669
filter(
671-
lambda model: model.type_ is cast(OpenAPIResponseContentModel, payload)["model"],
670+
lambda model: model.type_ is model_payload_typed["model"],
672671
self.dependant.response_extra_models,
673672
),
674673
)
@@ -682,14 +681,17 @@ def _get_openapi_path( # noqa PLR0912
682681
)
683682

684683
# Preserve existing fields like examples, encoding, etc.
685-
new_payload = {**payload} # Copy all existing fields
684+
new_payload: OpenAPIResponseContentSchema = {}
685+
# Copy all fields except 'model'
686+
for key, value in payload.items():
687+
if key != "model":
688+
new_payload[key] = value # type: ignore[literal-required]
686689
new_payload.update(model_payload) # Add/override with model schema
687-
new_payload.pop("model", None) # Remove the model field itself
688690

689691
# Case 2.2: the 'content' has a schema
690692
else:
691693
# Do nothing! We already have what we need!
692-
new_payload = payload
694+
new_payload = cast(OpenAPIResponseContentSchema, payload)
693695

694696
response["content"][content_type] = new_payload
695697

0 commit comments

Comments
 (0)