diff --git a/aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py b/aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py index ff24e908d1a..b8ef9c08045 100644 --- a/aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py +++ b/aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py @@ -112,11 +112,11 @@ def resource(self) -> str: @property def multi_value_headers(self) -> Dict[str, List[str]]: - return self["multiValueHeaders"] + return self.get("multiValueHeaders") or {} @property - def multi_value_query_string_parameters(self) -> Optional[Dict[str, List[str]]]: - return self.get("multiValueQueryStringParameters") + def multi_value_query_string_parameters(self) -> Dict[str, List[str]]: + return self.get("multiValueQueryStringParameters") or {} @property def resolved_query_string_parameters(self) -> Dict[str, List[str]]: diff --git a/tests/functional/event_handler/test_openapi_validation_middleware.py b/tests/functional/event_handler/test_openapi_validation_middleware.py index a9396644b98..da83f6f92f1 100644 --- a/tests/functional/event_handler/test_openapi_validation_middleware.py +++ b/tests/functional/event_handler/test_openapi_validation_middleware.py @@ -1108,3 +1108,23 @@ def my_path( # THEN the handler should be invoked and return 200 result = app(gw_event_http, {}) assert result["statusCode"] == 200 + + +def test_validate_with_minimal_event(): + # GIVEN an APIGatewayRestResolver with validation enabled + app = APIGatewayRestResolver(enable_validation=True) + + # WHEN a handler is defined with a default scalar parameter + @app.get("/users/") + def handler(user_id: int = 123): + print(user_id) + + minimal_event = { + "path": "/users/123", + "httpMethod": "GET", + "requestContext": {"requestId": "227b78aa-779d-47d4-a48e-ce62120393b8"}, # correlation ID + } + + # THEN the handler should be invoked and return 200 + result = app(minimal_event, {}) + assert result["statusCode"] == 200