|
2 | 2 | from dataclasses import dataclass
|
3 | 3 | from enum import Enum
|
4 | 4 | from pathlib import PurePath
|
5 |
| -from typing import List, Tuple |
| 5 | +from typing import List, Optional, Tuple |
6 | 6 |
|
7 | 7 | import pytest
|
8 | 8 | from pydantic import BaseModel
|
|
15 | 15 | Response,
|
16 | 16 | VPCLatticeResolver,
|
17 | 17 | VPCLatticeV2Resolver,
|
| 18 | + content_types, |
18 | 19 | )
|
19 | 20 | from aws_lambda_powertools.event_handler.openapi.params import Body, Header, Query
|
20 | 21 | from aws_lambda_powertools.shared.types import Annotated
|
| 22 | +from aws_lambda_powertools.utilities.data_classes import APIGatewayProxyEvent |
21 | 23 | from tests.functional.utils import load_event
|
22 | 24 |
|
23 | 25 | LOAD_GW_EVENT = load_event("apiGatewayProxyEvent.json")
|
@@ -1018,3 +1020,23 @@ def handler3():
|
1018 | 1020 | # IF expected_error_text is provided, THEN check for its presence in the response body
|
1019 | 1021 | if expected_error_text:
|
1020 | 1022 | assert any(text in result["body"] for text in expected_error_text)
|
| 1023 | + |
| 1024 | + |
| 1025 | +def test_validation_with_alias(): |
| 1026 | + # GIVEN a Http API V2 proxy type event |
| 1027 | + app = APIGatewayRestResolver(enable_validation=True) |
| 1028 | + event = load_event("apiGatewayProxyEvent.json") |
| 1029 | + |
| 1030 | + class FunkyTown(BaseModel): |
| 1031 | + parameter: str |
| 1032 | + |
| 1033 | + @app.get("/my/path") |
| 1034 | + def my_path( |
| 1035 | + parameter: Annotated[Optional[str], Query(alias="parameter1")] = None, |
| 1036 | + ) -> Response[FunkyTown]: |
| 1037 | + assert isinstance(app.current_event, APIGatewayProxyEvent) |
| 1038 | + assert parameter == "value1" |
| 1039 | + return Response(200, content_types.APPLICATION_JSON, FunkyTown(parameter=parameter)) |
| 1040 | + |
| 1041 | + result = app(event, {}) |
| 1042 | + assert result["statusCode"] == 200 |
0 commit comments