Skip to content

Commit 694952f

Browse files
Addressing Heitor's feedback
1 parent 6a61446 commit 694952f

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

aws_lambda_powertools/event_handler/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ class _FrozenListDict(List[Dict[str, List[str]]]):
3636
"""
3737

3838
def __hash__(self):
39-
return hash(frozenset({_FrozenDict({key: frozenset(self) for key, self in item.items()}) for item in self}))
39+
hashable_items = []
40+
for item in self:
41+
hashable_items.extend((key, frozenset(value)) for key, value in item.items())
42+
return hash(frozenset(hashable_items))
4043

4144

4245
def extract_origin_header(resolver_headers: Dict[str, Any]):

tests/functional/event_handler/test_openapi_security.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def handler():
3232
def test_openapi_top_level_security_missing():
3333
# GIVEN an APIGatewayRestResolver instance
3434
app = APIGatewayRestResolver()
35+
app.enable_swagger()
3536

3637
@app.get("/")
3738
def handler():
@@ -48,17 +49,14 @@ def handler():
4849
def test_openapi_operation_security():
4950
# GIVEN an APIGatewayRestResolver instance
5051
app = APIGatewayRestResolver()
52+
security_schemes = {"apiKey": APIKey(name="X-API-KEY", description="API Key", in_=APIKeyIn.header)}
5153

5254
@app.get("/", security=[{"apiKey": []}])
5355
def handler():
5456
raise NotImplementedError()
5557

5658
# WHEN the get_openapi_schema method is called with security defined at the operation level
57-
schema = app.get_openapi_schema(
58-
security_schemes={
59-
"apiKey": APIKey(name="X-API-KEY", description="API Key", in_=APIKeyIn.header),
60-
},
61-
)
59+
schema = app.get_openapi_schema(security_schemes=security_schemes)
6260

6361
# THEN the resulting schema should have security defined at the operation level, not the top level
6462
top_level_security = schema.security
@@ -71,6 +69,7 @@ def test_openapi_operation_security_with_router():
7169
# GIVEN an APIGatewayRestResolver instance with a Router
7270
app = APIGatewayRestResolver()
7371
router = Router()
72+
security_schemes = {"apiKey": APIKey(name="X-API-KEY", description="API Key", in_=APIKeyIn.header)}
7473

7574
@router.get("/", security=[{"apiKey": []}])
7675
def handler():
@@ -79,11 +78,7 @@ def handler():
7978
app.include_router(router)
8079

8180
# WHEN the get_openapi_schema method is called with security defined at the operation level in the Router
82-
schema = app.get_openapi_schema(
83-
security_schemes={
84-
"apiKey": APIKey(name="X-API-KEY", description="API Key", in_=APIKeyIn.header),
85-
},
86-
)
81+
schema = app.get_openapi_schema(security_schemes=security_schemes)
8782

8883
# THEN the resulting schema should have security defined at the operation level
8984
top_level_security = schema.security

0 commit comments

Comments
 (0)