Skip to content

Commit 903bdbb

Browse files
refactor(parser): Improve ALB models with examples and descriptions (#7100)
Improve ALB models with examples and descriptions
1 parent d594783 commit 903bdbb

File tree

1 file changed

+37
-10
lines changed
  • aws_lambda_powertools/utilities/parser/models

1 file changed

+37
-10
lines changed
Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
from typing import Dict, Type, Union
22

3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, Field
44

55

66
class AlbRequestContextData(BaseModel):
7-
targetGroupArn: str
7+
targetGroupArn: str = Field(
8+
description="The ARN of the target group that the request was routed to.",
9+
examples=[
10+
"arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/my-targets/73e2d6bc24d8a067",
11+
"arn:aws:elasticloadbalancing:eu-west-1:123456789012:targetgroup/api-targets/1234567890123456",
12+
],
13+
)
814

915

1016
class AlbRequestContext(BaseModel):
11-
elb: AlbRequestContextData
17+
elb: AlbRequestContextData = Field(
18+
description="Information about the Elastic Load Balancer that processed the request.",
19+
)
1220

1321

1422
class AlbModel(BaseModel):
15-
httpMethod: str
16-
path: str
17-
body: Union[str, Type[BaseModel]]
18-
isBase64Encoded: bool
19-
headers: Dict[str, str]
20-
queryStringParameters: Dict[str, str]
21-
requestContext: AlbRequestContext
23+
httpMethod: str = Field(
24+
description="The HTTP method used for the request.",
25+
examples=["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "CONNECT"],
26+
)
27+
path: str = Field(
28+
description="The path portion of the request URL.",
29+
examples=["/", "/api/users", "/health", "/api/v1/products/123"],
30+
)
31+
body: Union[str, Type[BaseModel]] = Field(
32+
description="The request body. Can be a string or a parsed model if content-type allows parsing.",
33+
)
34+
isBase64Encoded: bool = Field(description="Indicates whether the body is base64-encoded.", examples=[False, True])
35+
headers: Dict[str, str] = Field(
36+
description="The request headers as key-value pairs.",
37+
examples=[
38+
{"host": "example.com", "user-agent": "Mozilla/5.0"},
39+
{"content-type": "application/json", "authorization": "Bearer token123"},
40+
],
41+
)
42+
queryStringParameters: Dict[str, str] = Field(
43+
description="The query string parameters as key-value pairs.",
44+
examples=[{"page": "1", "limit": "10"}, {"filter": "active", "sort": "name"}],
45+
)
46+
requestContext: AlbRequestContext = Field(
47+
description="Contains information about the request context, including the load balancer details.",
48+
)

0 commit comments

Comments
 (0)