Skip to content

feat(event_handler): add support for multiValueQueryStringParameters in OpenAPI schema#3667

Merged
leandrodamascena merged 10 commits intoaws-powertools:developfrom
leandrodamascena:query-headers-params
Jan 23, 2024
Merged

feat(event_handler): add support for multiValueQueryStringParameters in OpenAPI schema#3667
leandrodamascena merged 10 commits intoaws-powertools:developfrom
leandrodamascena:query-headers-params

Conversation

@leandrodamascena
Copy link
Copy Markdown
Contributor

Issue number: #3622

Summary

Changes

This pull request enhances the OpenAPI utility by introducing support for multiValueQueryStringParameters in the OpenAPI schema. Previously, our utility encountered issues parsing multi-value query fields, leading to errors for customers attempting to utilize such fields. Work did:

  • Added support for multiValueQueryStringParameters in the OpenAPI schema.
  • Resolved parsing issues previously encountered when dealing with multi-value fields in different Resolvers.
  • Added new tests

User experience

Using the code below now we can validate multi value param.

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)

image

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jan 23, 2024
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 23, 2024

Codecov Report

❌ Patch coverage is 97.43590% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.65%. Comparing base (517acd6) to head (ee83b1b).
⚠️ Report is 2583 commits behind head on develop.

Files with missing lines Patch % Lines
...lambda_powertools/utilities/data_classes/common.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3667      +/-   ##
===========================================
+ Coverage    95.57%   95.65%   +0.07%     
===========================================
  Files          214      214              
  Lines         9993    10031      +38     
  Branches      1827     1840      +13     
===========================================
+ Hits          9551     9595      +44     
+ Misses         329      326       -3     
+ Partials       113      110       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@boring-cyborg boring-cyborg Bot added the documentation Improvements or additions to documentation label Jan 23, 2024
@leandrodamascena leandrodamascena linked an issue Jan 23, 2024 that may be closed by this pull request
@leandrodamascena leandrodamascena marked this pull request as ready for review January 23, 2024 13:35
@leandrodamascena leandrodamascena requested review from a team and rubenfonseca January 23, 2024 13:35
Copy link
Copy Markdown
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job diving deep into OpenAPI :D Just left some small things

Comment thread aws_lambda_powertools/event_handler/middlewares/openapi_validation.py Outdated
Comment thread aws_lambda_powertools/event_handler/middlewares/openapi_validation.py Outdated
Comment thread aws_lambda_powertools/event_handler/middlewares/openapi_validation.py Outdated
Comment thread aws_lambda_powertools/utilities/data_classes/alb_event.py Outdated
Comment thread aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py Outdated
Comment thread aws_lambda_powertools/utilities/data_classes/bedrock_agent_event.py Outdated
Comment thread aws_lambda_powertools/utilities/data_classes/common.py
Comment thread aws_lambda_powertools/utilities/data_classes/vpc_lattice.py Outdated
Comment thread aws_lambda_powertools/utilities/data_classes/vpc_lattice.py Outdated
Comment thread examples/event_handler_rest/src/working_with_multi_query_values.py Outdated
@leandrodamascena
Copy link
Copy Markdown
Contributor Author

Great job diving deep into OpenAPI :D Just left some small things

Thanks @rubenfonseca! Can you review it again pls?

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Copy Markdown
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, I've also checked the highlights in the documentation and it looks good!

@leandrodamascena leandrodamascena merged commit 0519fa3 into aws-powertools:develop Jan 23, 2024
@leandrodamascena leandrodamascena deleted the query-headers-params branch January 23, 2024 15:09
@leandrodamascena leandrodamascena restored the query-headers-params branch January 30, 2024 23:17
@leandrodamascena leandrodamascena deleted the query-headers-params branch January 30, 2024 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation event_handlers size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: OpenAPI doesnt support multiValueQueryStringParameters

3 participants