Closed
Description
Discussed in #3607
Originally posted by MCR2019 January 9, 2024
When an event from APIGatway contains a path parameter or query parameter these can be specified and validated using aws_lambda_powertools.event_handler.openapi.params
Path
and Query
(and the openAPI spec generated).
If an event contains multiValueQueryStringParameters
then I cannot see any way to specify, validate and access these? (and have them generated for the openAPI spec).
I've been unable to find anything in the documentation or code or get anything to work.
The following code is a starting point to demonstrate what I'm looking for (it doesn't work as I have used Query
rather than something to specify multi value query parameters).
from enum import Enum
from http import HTTPStatus
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.event_handler.openapi.params import Query
from aws_lambda_powertools.shared.types import Annotated
from aws_lambda_powertools.utilities.typing import LambdaContext
app = APIGatewayRestResolver(enable_validation=True)
class ExampleEnum(Enum):
"""Example of an Enum class."""
ONE = "value_one"
TWO = "value_two"
THREE = "value_three"
@app.get("/example-resource")
def get(
example_multi_value_param: Annotated[
ExampleEnum,
Query(
description="This should be a multi value query parameter."
), # TODO: How should this represent multi-value query string parameters?
]
):
"""Return validated multi-value param values."""
return example_multi_value_param
def lambda_handler(event: dict, context: LambdaContext):
"""Handler to route API Gateway events."""
return app.resolve(event, context)
class TestGetExample:
def test_multi_param_call(self):
"""Get call with multi value param."""
get_event = {
"path": "/example-resource",
"httpMethod": "GET",
"queryStringParameters": {"example_multi_value_param": "value_three"},
"multiValueQueryStringParameters": {"example_multi_value_param": ["value_one", "value_two", "value_three"]},
}
example_response = lambda_handler(event=get_event, context=LambdaContext)
assert example_response["statusCode"] == HTTPStatus.OK
assert example_response["body"] == ["value_one", "value_two", "value_three"]
I'd be interested in any thoughts on this :)
Metadata
Metadata
Assignees
Type
Projects
Status
Shipped