Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: OpenAPI doesnt support multiValueQueryStringParameters #3622

Closed
leandrodamascena opened this issue Jan 12, 2024 Discussed in #3607 · 2 comments · Fixed by #3667
Closed

Bug: OpenAPI doesnt support multiValueQueryStringParameters #3622

leandrodamascena opened this issue Jan 12, 2024 Discussed in #3607 · 2 comments · Fixed by #3667
Assignees
Labels
bug Something isn't working event_handlers help wanted Could use a second pair of eyes/hands openapi-schema

Comments

@leandrodamascena
Copy link
Contributor

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 :)

Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jan 23, 2024
Copy link
Contributor

github-actions bot commented Feb 2, 2024

This is now released under 2.33.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Feb 2, 2024
@heitorlessa heitorlessa moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers help wanted Could use a second pair of eyes/hands openapi-schema
Projects
Status: Shipped
2 participants