Skip to content

Commit 6ec11b8

Browse files
committed
fix(event-handler): prevent OpenAPI schema bleed when reusing response dictionaries
Fixes #7711 When multiple routes shared the same response dictionary object, the OpenAPI schema generator was mutating the shared dictionary by directly modifying it. This caused schema bleeding where one route's return type would incorrectly appear in another route's OpenAPI schema. The fix uses copy.deepcopy() to create independent copies of response dictionaries before mutation, ensuring each route gets its own correct OpenAPI schema based on its return type annotation.
1 parent c9afa5d commit 6ec11b8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import base64
4+
import copy
45
import json
56
import logging
67
import re
@@ -666,7 +667,8 @@ def _get_openapi_path( # noqa PLR0912
666667
# Add the response to the OpenAPI operation
667668
if self.responses:
668669
for status_code in list(self.responses):
669-
response = self.responses[status_code]
670+
# Create a deep copy to prevent mutation of the shared dictionary
671+
response = copy.deepcopy(self.responses[status_code])
670672

671673
# Case 1: there is not 'content' key
672674
if "content" not in response:

0 commit comments

Comments
 (0)