From 5c3f6c597afface623d5fe92b9e5d73eea809496 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 30 Sep 2022 14:44:35 +0200 Subject: [PATCH 1/2] fix(apigateway): honour docstrings and set content_type/body to be optional --- aws_lambda_powertools/event_handler/api_gateway.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws_lambda_powertools/event_handler/api_gateway.py b/aws_lambda_powertools/event_handler/api_gateway.py index ae02a659359..4fdce465dab 100644 --- a/aws_lambda_powertools/event_handler/api_gateway.py +++ b/aws_lambda_powertools/event_handler/api_gateway.py @@ -143,8 +143,8 @@ class Response: def __init__( self, status_code: int, - content_type: Optional[str], - body: Union[str, bytes, None], + content_type: Optional[str] = None, + body: Union[str, bytes, None] = None, headers: Optional[Dict] = None, ): """ From 3134fa4ae48fbe7132a4402a51c28cc260c8d0c1 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Fri, 30 Sep 2022 15:24:52 +0200 Subject: [PATCH 2/2] chore(apigateway): add test to ensure status_code is the only required --- tests/functional/event_handler/test_api_gateway.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/functional/event_handler/test_api_gateway.py b/tests/functional/event_handler/test_api_gateway.py index 4b1d7c1ee32..145d435688a 100644 --- a/tests/functional/event_handler/test_api_gateway.py +++ b/tests/functional/event_handler/test_api_gateway.py @@ -1289,3 +1289,10 @@ def handler(event: APIGatewayProxyEventV2, context): # THEN result = handler(load_event("apiGatewayProxyV2Event.json"), None) assert result["statusCode"] == 200 + + +def test_response_with_status_code_only(): + ret = Response(status_code=204) + assert ret.status_code == 204 + assert ret.body is None + assert ret.headers == {}