Skip to content

Commit 8a97520

Browse files
Merge branch 'develop' into openapi/doc
2 parents dad816b + e34f719 commit 8a97520

26 files changed

+278
-187
lines changed

.github/workflows/dependency-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
- name: 'Checkout Repository'
2020
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2121
- name: 'Dependency Review'
22-
uses: actions/dependency-review-action@01bc87099ba56df1e897b6874784491ea6309bc4 # v3.1.4
22+
uses: actions/dependency-review-action@c74b580d73376b7750d3d2a50bfb8adc2c937507 # v3.1.5

.github/workflows/dispatch_analytics.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ jobs:
5151
- name: Invoke Lambda function
5252
run: |
5353
payload=$(echo -n '{"githubToken": "${{ secrets.GITHUB_TOKEN }}"}' | base64)
54-
aws lambda invoke \
55-
--function-name ${{ secrets.AWS_ANALYTICS_DISPATCHER_ARN }} \
56-
--payload "$payload" response.json
57-
cat response.json
54+
response=$(aws lambda invoke \
55+
--function-name "${{ secrets.AWS_ANALYTICS_DISPATCHER_ARN }}" \
56+
--payload "$payload" \
57+
response.json \
58+
--query 'FunctionError' \
59+
--output text)
60+
61+
cat response.json ; echo # add newline at the end
62+
63+
if [ "$response" != "None" ]; then
64+
echo "Error invoking lambda function: $response. Aborting."
65+
exit 1
66+
fi

.github/workflows/quality_check_pydanticv2.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ name: Code quality - Pydanticv2
1414
#
1515
# Always triggered on new PRs, PR changes and PR merge.
1616

17-
1817
on:
1918
pull_request:
2019
paths:
@@ -48,18 +47,16 @@ jobs:
4847
env:
4948
PYTHON: "${{ matrix.python-version }}"
5049
permissions:
51-
contents: read # checkout code only
50+
contents: read # checkout code only
5251
steps:
53-
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
52+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
5453
- name: Install poetry
5554
run: pipx install poetry
5655
- name: Set up Python ${{ matrix.python-version }}
5756
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
5857
with:
5958
python-version: ${{ matrix.python-version }}
6059
cache: "poetry"
61-
- name: Removing dev dependencies locked to Pydantic v1
62-
run: poetry remove cfn-lint
6360
- name: Replacing Pydantic v1 with v2 > 2.0.3
6461
run: poetry add "pydantic=^2.0.3"
6562
- name: Install dependencies

CHANGELOG.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,25 @@
44
<a name="unreleased"></a>
55
# Unreleased
66

7+
## Maintenance
8+
9+
* **deps-dev:** bump cfn-lint from 0.83.7 to 0.83.8 ([#3603](https://github.com/aws-powertools/powertools-lambda-python/issues/3603))
10+
11+
12+
<a name="v2.31.0"></a>
13+
## [v2.31.0] - 2024-01-05
14+
## Bug Fixes
15+
16+
* **ci:** fail dispatch analytics job when Lambda call fails ([#3579](https://github.com/aws-powertools/powertools-lambda-python/issues/3579))
17+
718
## Code Refactoring
819

920
* **parameters:** add overload signatures for get_parameter and get_parameters ([#3534](https://github.com/aws-powertools/powertools-lambda-python/issues/3534))
21+
* **parser:** Improve error message when parsing models and envelopes ([#3587](https://github.com/aws-powertools/powertools-lambda-python/issues/3587))
22+
23+
## Documentation
24+
25+
* **middleware-factory:** Fix and improve typing ([#3569](https://github.com/aws-powertools/powertools-lambda-python/issues/3569))
1026

1127
## Features
1228

@@ -16,10 +32,23 @@
1632

1733
## Maintenance
1834

35+
* version bump
36+
* **ci:** Remove dev dependencies locked to Pydantic v1 within the Pydantic v2 workflow. ([#3582](https://github.com/aws-powertools/powertools-lambda-python/issues/3582))
37+
* **deps:** bump squidfunk/mkdocs-material from `9af3b7e` to `2f29d71` in /docs ([#3559](https://github.com/aws-powertools/powertools-lambda-python/issues/3559))
38+
* **deps:** bump the layer-balancer group in /layer/scripts/layer-balancer with 4 updates ([#3593](https://github.com/aws-powertools/powertools-lambda-python/issues/3593))
1939
* **deps:** bump actions/setup-node from 4.0.0 to 4.0.1 ([#3535](https://github.com/aws-powertools/powertools-lambda-python/issues/3535))
2040
* **deps:** bump zgosalvez/github-actions-ensure-sha-pinned-actions from 3.0.2 to 3.0.3 ([#3536](https://github.com/aws-powertools/powertools-lambda-python/issues/3536))
41+
* **deps:** bump actions/dependency-review-action from 3.1.4 to 3.1.5 ([#3592](https://github.com/aws-powertools/powertools-lambda-python/issues/3592))
2142
* **deps:** bump the layer-balancer group in /layer/scripts/layer-balancer with 2 updates ([#3544](https://github.com/aws-powertools/powertools-lambda-python/issues/3544))
43+
* **deps:** bump fastjsonschema from 2.19.0 to 2.19.1 ([#3567](https://github.com/aws-powertools/powertools-lambda-python/issues/3567))
2244
* **deps-dev:** bump ruff from 0.1.8 to 0.1.9 ([#3550](https://github.com/aws-powertools/powertools-lambda-python/issues/3550))
45+
* **deps-dev:** bump aws-cdk from 2.115.0 to 2.116.1 ([#3553](https://github.com/aws-powertools/powertools-lambda-python/issues/3553))
46+
* **deps-dev:** bump aws-cdk from 2.117.0 to 2.118.0 ([#3589](https://github.com/aws-powertools/powertools-lambda-python/issues/3589))
47+
* **deps-dev:** bump cfn-lint from 0.83.6 to 0.83.7 ([#3554](https://github.com/aws-powertools/powertools-lambda-python/issues/3554))
48+
* **deps-dev:** bump ruff from 0.1.9 to 0.1.10 ([#3583](https://github.com/aws-powertools/powertools-lambda-python/issues/3583))
49+
* **deps-dev:** bump pytest from 7.4.3 to 7.4.4 ([#3576](https://github.com/aws-powertools/powertools-lambda-python/issues/3576))
50+
* **deps-dev:** bump aws-cdk from 2.116.1 to 2.117.0 ([#3565](https://github.com/aws-powertools/powertools-lambda-python/issues/3565))
51+
* **deps-dev:** bump ruff from 0.1.10 to 0.1.11 ([#3588](https://github.com/aws-powertools/powertools-lambda-python/issues/3588))
2352

2453

2554
<a name="v2.30.2"></a>
@@ -4205,7 +4234,8 @@
42054234
* Merge pull request [#5](https://github.com/aws-powertools/powertools-lambda-python/issues/5) from jfuss/feat/python38
42064235

42074236

4208-
[Unreleased]: https://github.com/aws-powertools/powertools-lambda-python/compare/v2.30.2...HEAD
4237+
[Unreleased]: https://github.com/aws-powertools/powertools-lambda-python/compare/v2.31.0...HEAD
4238+
[v2.31.0]: https://github.com/aws-powertools/powertools-lambda-python/compare/v2.30.2...v2.31.0
42094239
[v2.30.2]: https://github.com/aws-powertools/powertools-lambda-python/compare/v2.30.1...v2.30.2
42104240
[v2.30.1]: https://github.com/aws-powertools/powertools-lambda-python/compare/v2.30.0...v2.30.1
42114241
[v2.30.0]: https://github.com/aws-powertools/powertools-lambda-python/compare/v2.29.1...v2.30.0

aws_lambda_powertools/event_handler/api_gateway.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ def swagger_handler():
16271627

16281628
openapi_servers = servers or [Server(url=(base_path or "/"))]
16291629

1630-
spec = self.get_openapi_json_schema(
1630+
spec = self.get_openapi_schema(
16311631
title=title,
16321632
version=version,
16331633
openapi_version=openapi_version,

aws_lambda_powertools/event_handler/openapi/swagger_ui/html.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
def generate_swagger_html(spec: str, js_url: str, css_url: str) -> str:
1+
from typing import TYPE_CHECKING
2+
3+
if TYPE_CHECKING:
4+
from aws_lambda_powertools.event_handler.openapi.models import OpenAPI
5+
6+
7+
def generate_swagger_html(spec: "OpenAPI", js_url: str, css_url: str) -> str:
28
"""
39
Generate Swagger UI HTML page
410
511
Parameters
612
----------
7-
spec: str
8-
The OpenAPI spec in the JSON format
13+
spec: OpenAPI
14+
The OpenAPI spec
915
js_url: str
1016
The URL to the Swagger UI JavaScript file
1117
css_url: str
1218
The URL to the Swagger UI CSS file
1319
"""
20+
21+
from aws_lambda_powertools.event_handler.openapi.compat import model_json
22+
23+
# The .replace('</', '<\\/') part is necessary to prevent a potential issue where the JSON string contains
24+
# </script> or similar tags. Escaping the forward slash in </ as <\/ ensures that the JSON does not inadvertently
25+
# close the script tag, and the JSON remains a valid string within the JavaScript code.
26+
escaped_spec = model_json(
27+
spec,
28+
by_alias=True,
29+
exclude_none=True,
30+
indent=2,
31+
).replace("</", "<\\/")
32+
1433
return f"""
1534
<!DOCTYPE html>
1635
<html>
@@ -41,9 +60,7 @@ def generate_swagger_html(spec: str, js_url: str, css_url: str) -> str:
4160
layout: "BaseLayout",
4261
showExtensions: true,
4362
showCommonExtensions: true,
44-
spec: JSON.parse(`
45-
{spec}
46-
`.trim()),
63+
spec: {escaped_spec},
4764
presets: [
4865
SwaggerUIBundle.presets.apis,
4966
SwaggerUIBundle.SwaggerUIStandalonePreset
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Exposes version constant to avoid circular dependencies."""
22

3-
VERSION = "2.30.2"
3+
VERSION = "2.31.0"

aws_lambda_powertools/utilities/parser/parser.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,12 @@ def handler(event: Order, context: LambdaContext):
171171
try:
172172
logger.debug(f"Parsing and validating event model with envelope={envelope}")
173173
return envelope().parse(data=event, model=model)
174-
except AttributeError:
175-
raise InvalidEnvelopeError(f"Envelope must implement BaseEnvelope, envelope={envelope}")
174+
except AttributeError as exc:
175+
raise InvalidEnvelopeError(
176+
f"Error: {str(exc)}. Please ensure that both the Input model and the Envelope inherits from BaseModel,\n" # noqa E501
177+
"and your payload adheres to the specified Input model structure.\n"
178+
f"Envelope={envelope}\nModel={model}",
179+
)
176180

177181
try:
178182
disable_pydantic_v2_warning()
@@ -181,5 +185,9 @@ def handler(event: Order, context: LambdaContext):
181185
return model.parse_raw(event)
182186

183187
return model.parse_obj(event)
184-
except AttributeError:
185-
raise InvalidModelTypeError(f"Input model must implement BaseModel, model={model}")
188+
except AttributeError as exc:
189+
raise InvalidModelTypeError(
190+
f"Error: {str(exc)}. Please ensure the Input model inherits from BaseModel,\n"
191+
"and your payload adheres to the specified Input model structure.\n"
192+
f"Model={model}",
193+
)

0 commit comments

Comments
 (0)