Skip to content

Commit 5134c36

Browse files
Merge remote-tracking branch 'upstream/develop' into tracer
2 parents 7fc17b3 + 16bdeaf commit 5134c36

File tree

5 files changed

+85
-53
lines changed

5 files changed

+85
-53
lines changed

CHANGELOG.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
## Code Refactoring
1212

13+
* **logger:** add type annotation for append_keys method ([#3988](https://github.com/aws-powertools/powertools-lambda-python/issues/3988))
1314
* **parameters:** improve typing for get_secret method ([#3910](https://github.com/aws-powertools/powertools-lambda-python/issues/3910))
1415

1516
## Documentation
@@ -19,57 +20,61 @@
1920

2021
## Features
2122

23+
* **batch:** add flag in SqsFifoProcessor to enable continuous message processing ([#3954](https://github.com/aws-powertools/powertools-lambda-python/issues/3954))
2224
* **data_classes:** Add CloudWatchAlarmEvent data class ([#3868](https://github.com/aws-powertools/powertools-lambda-python/issues/3868))
2325
* **event-handler:** add compress option when serving Swagger HTML ([#3946](https://github.com/aws-powertools/powertools-lambda-python/issues/3946))
2426
* **event_handler:** define exception_handler directly from the router ([#3979](https://github.com/aws-powertools/powertools-lambda-python/issues/3979))
2527
* **tracer:** auto-disable tracer when for AWS SAM and Chalice environments ([#3949](https://github.com/aws-powertools/powertools-lambda-python/issues/3949))
2628

2729
## Maintenance
2830

29-
* **deps:** bump squidfunk/mkdocs-material from `3678304` to `6c81a89` in /docs ([#3973](https://github.com/aws-powertools/powertools-lambda-python/issues/3973))
30-
* **deps:** bump redis from 5.0.2 to 5.0.3 ([#3929](https://github.com/aws-powertools/powertools-lambda-python/issues/3929))
3131
* **deps:** bump actions/checkout from 4.1.1 to 4.1.2 ([#3939](https://github.com/aws-powertools/powertools-lambda-python/issues/3939))
3232
* **deps:** bump datadog-lambda from 5.89.0 to 5.90.0 ([#3941](https://github.com/aws-powertools/powertools-lambda-python/issues/3941))
33+
* **deps:** bump squidfunk/mkdocs-material from `3678304` to `6c81a89` in /docs ([#3973](https://github.com/aws-powertools/powertools-lambda-python/issues/3973))
3334
* **deps:** bump the layer-balancer group in /layer/scripts/layer-balancer with 3 updates ([#3972](https://github.com/aws-powertools/powertools-lambda-python/issues/3972))
34-
* **deps:** bump pypa/gh-action-pypi-publish from 1.8.12 to 1.8.14 ([#3918](https://github.com/aws-powertools/powertools-lambda-python/issues/3918))
3535
* **deps:** bump aws-encryption-sdk from 3.1.1 to 3.2.0 ([#3983](https://github.com/aws-powertools/powertools-lambda-python/issues/3983))
36+
* **deps:** bump pypa/gh-action-pypi-publish from 1.8.12 to 1.8.14 ([#3918](https://github.com/aws-powertools/powertools-lambda-python/issues/3918))
37+
* **deps:** bump redis from 5.0.2 to 5.0.3 ([#3929](https://github.com/aws-powertools/powertools-lambda-python/issues/3929))
3638
* **deps:** bump docker/setup-buildx-action from 3.1.0 to 3.2.0 ([#3955](https://github.com/aws-powertools/powertools-lambda-python/issues/3955))
39+
* **deps:** bump actions/dependency-review-action from 4.1.3 to 4.2.3 ([#3993](https://github.com/aws-powertools/powertools-lambda-python/issues/3993))
3740
* **deps:** bump datadog-lambda from 5.90.0 to 5.91.0 ([#3958](https://github.com/aws-powertools/powertools-lambda-python/issues/3958))
38-
* **deps-dev:** bump mkdocs-material from 9.5.13 to 9.5.14 ([#3978](https://github.com/aws-powertools/powertools-lambda-python/issues/3978))
39-
* **deps-dev:** bump the boto-typing group with 1 update ([#3964](https://github.com/aws-powertools/powertools-lambda-python/issues/3964))
41+
* **deps-dev:** bump coverage from 7.4.3 to 7.4.4 ([#3959](https://github.com/aws-powertools/powertools-lambda-python/issues/3959))
4042
* **deps-dev:** bump aws-cdk from 2.132.1 to 2.133.0 ([#3963](https://github.com/aws-powertools/powertools-lambda-python/issues/3963))
41-
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.89 to 0.1.90 ([#3957](https://github.com/aws-powertools/powertools-lambda-python/issues/3957))
42-
* **deps-dev:** bump the boto-typing group with 1 update ([#3956](https://github.com/aws-powertools/powertools-lambda-python/issues/3956))
43+
* **deps-dev:** bump the boto-typing group with 1 update ([#3964](https://github.com/aws-powertools/powertools-lambda-python/issues/3964))
4344
* **deps-dev:** bump types-python-dateutil from 2.8.19.20240311 to 2.9.0.20240315 ([#3966](https://github.com/aws-powertools/powertools-lambda-python/issues/3966))
44-
* **deps-dev:** bump coverage from 7.4.3 to 7.4.4 ([#3959](https://github.com/aws-powertools/powertools-lambda-python/issues/3959))
4545
* **deps-dev:** bump black from 24.2.0 to 24.3.0 ([#3968](https://github.com/aws-powertools/powertools-lambda-python/issues/3968))
46+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.89 to 0.1.90 ([#3957](https://github.com/aws-powertools/powertools-lambda-python/issues/3957))
47+
* **deps-dev:** bump the boto-typing group with 1 update ([#3956](https://github.com/aws-powertools/powertools-lambda-python/issues/3956))
48+
* **deps-dev:** bump aws-cdk-lib from 2.132.1 to 2.133.0 ([#3965](https://github.com/aws-powertools/powertools-lambda-python/issues/3965))
49+
* **deps-dev:** bump ruff from 0.3.2 to 0.3.3 ([#3967](https://github.com/aws-powertools/powertools-lambda-python/issues/3967))
50+
* **deps-dev:** bump the boto-typing group with 2 updates ([#3974](https://github.com/aws-powertools/powertools-lambda-python/issues/3974))
4651
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.88 to 0.1.89 ([#3952](https://github.com/aws-powertools/powertools-lambda-python/issues/3952))
4752
* **deps-dev:** bump sentry-sdk from 1.41.0 to 1.42.0 ([#3951](https://github.com/aws-powertools/powertools-lambda-python/issues/3951))
4853
* **deps-dev:** bump the boto-typing group with 1 update ([#3950](https://github.com/aws-powertools/powertools-lambda-python/issues/3950))
49-
* **deps-dev:** bump aws-cdk-lib from 2.132.1 to 2.133.0 ([#3965](https://github.com/aws-powertools/powertools-lambda-python/issues/3965))
50-
* **deps-dev:** bump ruff from 0.3.2 to 0.3.3 ([#3967](https://github.com/aws-powertools/powertools-lambda-python/issues/3967))
54+
* **deps-dev:** bump sentry-sdk from 1.42.0 to 1.43.0 ([#3992](https://github.com/aws-powertools/powertools-lambda-python/issues/3992))
55+
* **deps-dev:** bump types-python-dateutil from 2.9.0.20240315 to 2.9.0.20240316 ([#3977](https://github.com/aws-powertools/powertools-lambda-python/issues/3977))
5156
* **deps-dev:** bump the boto-typing group with 2 updates ([#3940](https://github.com/aws-powertools/powertools-lambda-python/issues/3940))
5257
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.87 to 0.1.88 ([#3942](https://github.com/aws-powertools/powertools-lambda-python/issues/3942))
5358
* **deps-dev:** bump pytest from 8.0.2 to 8.1.1 ([#3943](https://github.com/aws-powertools/powertools-lambda-python/issues/3943))
5459
* **deps-dev:** bump aws-cdk-aws-lambda-python-alpha from 2.131.0a0 to 2.132.1a0 ([#3944](https://github.com/aws-powertools/powertools-lambda-python/issues/3944))
55-
* **deps-dev:** bump pytest-asyncio from 0.23.5.post1 to 0.23.6 ([#3984](https://github.com/aws-powertools/powertools-lambda-python/issues/3984))
60+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.90 to 0.1.91 ([#3975](https://github.com/aws-powertools/powertools-lambda-python/issues/3975))
5661
* **deps-dev:** bump aws-cdk from 2.132.0 to 2.132.1 ([#3938](https://github.com/aws-powertools/powertools-lambda-python/issues/3938))
5762
* **deps-dev:** bump aws-cdk-lib from 2.131.0 to 2.132.1 ([#3936](https://github.com/aws-powertools/powertools-lambda-python/issues/3936))
58-
* **deps-dev:** bump the boto-typing group with 2 updates ([#3974](https://github.com/aws-powertools/powertools-lambda-python/issues/3974))
63+
* **deps-dev:** bump mypy from 1.8.0 to 1.9.0 ([#3921](https://github.com/aws-powertools/powertools-lambda-python/issues/3921))
5964
* **deps-dev:** bump aws-cdk from 2.131.0 to 2.132.0 ([#3928](https://github.com/aws-powertools/powertools-lambda-python/issues/3928))
6065
* **deps-dev:** bump types-redis from 4.6.0.20240218 to 4.6.0.20240311 ([#3931](https://github.com/aws-powertools/powertools-lambda-python/issues/3931))
6166
* **deps-dev:** bump types-python-dateutil from 2.8.19.20240106 to 2.8.19.20240311 ([#3932](https://github.com/aws-powertools/powertools-lambda-python/issues/3932))
6267
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.83 to 0.1.87 ([#3930](https://github.com/aws-powertools/powertools-lambda-python/issues/3930))
63-
* **deps-dev:** bump types-python-dateutil from 2.9.0.20240315 to 2.9.0.20240316 ([#3977](https://github.com/aws-powertools/powertools-lambda-python/issues/3977))
68+
* **deps-dev:** bump mkdocs-material from 9.5.13 to 9.5.14 ([#3978](https://github.com/aws-powertools/powertools-lambda-python/issues/3978))
6469
* **deps-dev:** bump ruff from 0.3.0 to 0.3.2 ([#3925](https://github.com/aws-powertools/powertools-lambda-python/issues/3925))
65-
* **deps-dev:** bump mypy from 1.8.0 to 1.9.0 ([#3921](https://github.com/aws-powertools/powertools-lambda-python/issues/3921))
66-
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.90 to 0.1.91 ([#3975](https://github.com/aws-powertools/powertools-lambda-python/issues/3975))
6770
* **deps-dev:** bump aws-cdk-aws-lambda-python-alpha from 2.132.1a0 to 2.133.0a0 ([#3976](https://github.com/aws-powertools/powertools-lambda-python/issues/3976))
71+
* **deps-dev:** bump bandit from 1.7.7 to 1.7.8 ([#3920](https://github.com/aws-powertools/powertools-lambda-python/issues/3920))
72+
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.91 to 0.1.94 ([#3985](https://github.com/aws-powertools/powertools-lambda-python/issues/3985))
6873
* **deps-dev:** bump pytest-asyncio from 0.23.5 to 0.23.5.post1 ([#3923](https://github.com/aws-powertools/powertools-lambda-python/issues/3923))
69-
* **deps-dev:** bump the boto-typing group with 2 updates ([#3982](https://github.com/aws-powertools/powertools-lambda-python/issues/3982))
74+
* **deps-dev:** bump pytest-asyncio from 0.23.5.post1 to 0.23.6 ([#3984](https://github.com/aws-powertools/powertools-lambda-python/issues/3984))
7075
* **deps-dev:** bump the boto-typing group with 2 updates ([#3919](https://github.com/aws-powertools/powertools-lambda-python/issues/3919))
71-
* **deps-dev:** bump cdklabs-generative-ai-cdk-constructs from 0.1.91 to 0.1.94 ([#3985](https://github.com/aws-powertools/powertools-lambda-python/issues/3985))
72-
* **deps-dev:** bump bandit from 1.7.7 to 1.7.8 ([#3920](https://github.com/aws-powertools/powertools-lambda-python/issues/3920))
76+
* **deps-dev:** bump the boto-typing group with 1 update ([#3991](https://github.com/aws-powertools/powertools-lambda-python/issues/3991))
77+
* **deps-dev:** bump the boto-typing group with 2 updates ([#3982](https://github.com/aws-powertools/powertools-lambda-python/issues/3982))
7378

7479

7580
<a name="v2.35.1"></a>

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,18 @@ def _get_openapi_path(
503503
if request_body_oai:
504504
operation["requestBody"] = request_body_oai
505505

506+
# Validation failure response (422) will always be part of the schema
507+
operation_responses: Dict[int, OpenAPIResponse] = {
508+
422: {
509+
"description": "Validation Error",
510+
"content": {
511+
"application/json": {
512+
"schema": {"$ref": COMPONENT_REF_PREFIX + "HTTPValidationError"},
513+
},
514+
},
515+
},
516+
}
517+
506518
# Add the response to the OpenAPI operation
507519
if self.responses:
508520
for status_code in list(self.responses):
@@ -549,45 +561,34 @@ def _get_openapi_path(
549561

550562
response["content"][content_type] = new_payload
551563

552-
operation["responses"] = self.responses
564+
# Merge the user provided response with the default responses
565+
operation_responses[status_code] = response
553566
else:
554567
# Set the default 200 response
555-
responses = operation.setdefault("responses", {})
556-
success_response = responses.setdefault(200, {})
557-
success_response["description"] = self.response_description or _DEFAULT_OPENAPI_RESPONSE_DESCRIPTION
558-
success_response["content"] = {"application/json": {"schema": {}}}
559-
json_response = success_response["content"].setdefault("application/json", {})
560-
561-
# Add the response schema to the OpenAPI 200 response
562-
json_response.update(
563-
self._openapi_operation_return(
564-
param=dependant.return_param,
565-
model_name_map=model_name_map,
566-
field_mapping=field_mapping,
567-
),
568+
response_schema = self._openapi_operation_return(
569+
param=dependant.return_param,
570+
model_name_map=model_name_map,
571+
field_mapping=field_mapping,
568572
)
569573

570-
# Add validation failure response (422)
571-
operation["responses"][422] = {
572-
"description": "Validation Error",
573-
"content": {
574-
"application/json": {
575-
"schema": {"$ref": COMPONENT_REF_PREFIX + "HTTPValidationError"},
576-
},
577-
},
574+
# Add the response schema to the OpenAPI 200 response
575+
operation_responses[200] = {
576+
"description": self.response_description or _DEFAULT_OPENAPI_RESPONSE_DESCRIPTION,
577+
"content": {"application/json": response_schema},
578578
}
579579

580-
# Add the validation error schema to the definitions, but only if it hasn't been added yet
581-
if "ValidationError" not in definitions:
582-
definitions.update(
583-
{
584-
"ValidationError": validation_error_definition,
585-
"HTTPValidationError": validation_error_response_definition,
586-
},
587-
)
588-
580+
operation["responses"] = operation_responses
589581
path[self.method.lower()] = operation
590582

583+
# Add the validation error schema to the definitions, but only if it hasn't been added yet
584+
if "ValidationError" not in definitions:
585+
definitions.update(
586+
{
587+
"ValidationError": validation_error_definition,
588+
"HTTPValidationError": validation_error_response_definition,
589+
},
590+
)
591+
591592
# Generate the response schema
592593
return path, definitions
593594

aws_lambda_powertools/event_handler/openapi/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"type": "array",
2929
"items": {"anyOf": [{"type": "string"}, {"type": "integer"}]},
3030
},
31-
"msg": {"title": "Message", "type": "string"},
31+
# For security reasons, we hide **msg** details (don't leak Python, Pydantic or filenames)
3232
"type": {"title": "Error Type", "type": "string"},
3333
},
3434
"required": ["loc", "msg", "type"],

tests/functional/event_handler/test_openapi_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def handler():
5252

5353
assert JSON_CONTENT_TYPE in response.content
5454
json_response = response.content[JSON_CONTENT_TYPE]
55-
assert json_response.schema_ == Schema()
55+
assert json_response.schema_ is None
5656
assert not json_response.examples
5757
assert not json_response.encoding
5858

tests/functional/event_handler/test_openapi_responses.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,34 @@ def handler():
5050
assert 202 in responses.keys()
5151
assert responses[202].description == "Custom response"
5252

53-
assert 200 not in responses.keys()
54-
assert 422 not in responses.keys()
53+
assert 200 not in responses.keys() # 200 was not added due to custom responses
54+
assert 422 in responses.keys() # 422 is always added due to potential data validation errors
55+
56+
57+
def test_openapi_422_default_response():
58+
app = APIGatewayRestResolver(enable_validation=True)
59+
60+
@app.get("/")
61+
def handler():
62+
return {"message": "hello world"}
63+
64+
schema = app.get_openapi_schema()
65+
responses = schema.paths["/"].get.responses
66+
assert 422 in responses.keys()
67+
assert responses[422].description == "Validation Error"
68+
69+
70+
def test_openapi_422_custom_response():
71+
app = APIGatewayRestResolver(enable_validation=True)
72+
73+
@app.get("/", responses={422: {"description": "Custom validation response"}})
74+
def handler():
75+
return {"message": "hello world"}
76+
77+
schema = app.get_openapi_schema()
78+
responses = schema.paths["/"].get.responses
79+
assert 422 in responses.keys()
80+
assert responses[422].description == "Custom validation response"
5581

5682

5783
def test_openapi_200_custom_schema():

0 commit comments

Comments
 (0)