-
Notifications
You must be signed in to change notification settings - Fork 434
feat(event_handler): add support for multiValueQueryStringParameters in OpenAPI schema #3667
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
Merged
leandrodamascena
merged 10 commits into
aws-powertools:develop
from
leandrodamascena:query-headers-params
Jan 23, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b1acfb2
Initial code for multivalue querystring
leandrodamascena 38da25d
Adding tests and improving code
leandrodamascena ad44f5f
Adding tests and improving code
leandrodamascena 522ea9a
Refactoging to avoid abstraction leaky
leandrodamascena c092c7a
Merge branch 'develop' into query-headers-params
leandrodamascena 40d80ae
Making Pydanticv2 happy
leandrodamascena 1124293
Adding documentation
leandrodamascena 673b7e1
Addressing Ruben's feedback
leandrodamascena ef8f4ba
Addressing Ruben's feedback
leandrodamascena ee83b1b
Mypy....
leandrodamascena File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
examples/event_handler_rest/src/working_with_multi_query_values.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from enum import Enum | ||
from typing import List | ||
|
||
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("/todos") | ||
def get( | ||
example_multi_value_param: Annotated[ | ||
List[ExampleEnum], # (1)! | ||
Query( | ||
description="This is multi value query parameter.", | ||
), | ||
], | ||
): | ||
"""Return validated multi-value param values.""" | ||
return example_multi_value_param | ||
|
||
|
||
def lambda_handler(event: dict, context: LambdaContext) -> dict: | ||
return app.resolve(event, context) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"requestContext": { | ||
"elb": { | ||
"targetGroupArn": "arn:aws:elasticloadbalancing:eu-central-1:1234567890:targetgroup/alb-c-Targe-11GDXTPQ7663S/804a67588bfdc10f" | ||
} | ||
}, | ||
"httpMethod": "GET", | ||
"path": "/todos", | ||
"multiValueQueryStringParameters": { | ||
"parameter1": ["value1","value2"], | ||
"parameter2": ["value"] | ||
}, | ||
"multiValueHeaders": { | ||
"accept": [ | ||
"*/*" | ||
], | ||
"host": [ | ||
"alb-c-LoadB-14POFKYCLBNSF-1815800096.eu-central-1.elb.amazonaws.com" | ||
], | ||
"user-agent": [ | ||
"curl/7.79.1" | ||
], | ||
"x-amzn-trace-id": [ | ||
"Root=1-62fa9327-21cdd4da4c6db451490a5fb7" | ||
], | ||
"x-forwarded-for": [ | ||
"123.123.123.123" | ||
], | ||
"x-forwarded-port": [ | ||
"80" | ||
], | ||
"x-forwarded-proto": [ | ||
"http" | ||
] | ||
}, | ||
"body": "", | ||
"isBase64Encoded": false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"version":"2.0", | ||
"routeKey":"$default", | ||
"rawPath":"/", | ||
"rawQueryString":"", | ||
"headers":{ | ||
"sec-fetch-mode":"navigate", | ||
"x-amzn-tls-version":"TLSv1.2", | ||
"sec-fetch-site":"cross-site", | ||
"accept-language":"pt-BR,pt;q=0.9", | ||
"x-forwarded-proto":"https", | ||
"x-forwarded-port":"443", | ||
"x-forwarded-for":"123.123.123.123", | ||
"sec-fetch-user":"?1", | ||
"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", | ||
"x-amzn-tls-cipher-suite":"ECDHE-RSA-AES128-GCM-SHA256", | ||
"sec-ch-ua":"\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"102\", \"Google Chrome\";v=\"102\"", | ||
"sec-ch-ua-mobile":"?0", | ||
"x-amzn-trace-id":"Root=1-62ecd163-5f302e550dcde3b12402207d", | ||
"sec-ch-ua-platform":"\"Linux\"", | ||
"host":"<url-id>.lambda-url.us-east-1.on.aws", | ||
"upgrade-insecure-requests":"1", | ||
"cache-control":"max-age=0", | ||
"accept-encoding":"gzip, deflate, br", | ||
"sec-fetch-dest":"document", | ||
"user-agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36" | ||
}, | ||
"queryStringParameters": { | ||
"parameter1": "value1,value2", | ||
"parameter2": "value" | ||
}, | ||
"requestContext":{ | ||
"accountId":"anonymous", | ||
"apiId":"<url-id>", | ||
"domainName":"<url-id>.lambda-url.us-east-1.on.aws", | ||
"domainPrefix":"<url-id>", | ||
"http":{ | ||
"method":"GET", | ||
"path":"/", | ||
"protocol":"HTTP/1.1", | ||
"sourceIp":"123.123.123.123", | ||
"userAgent":"agent" | ||
}, | ||
"requestId":"id", | ||
"routeKey":"$default", | ||
"stage":"$default", | ||
"time":"05/Aug/2022:08:14:39 +0000", | ||
"timeEpoch":1659687279885 | ||
}, | ||
"isBase64Encoded":false | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"version": "2.0", | ||
"path": "/newpath", | ||
"method": "GET", | ||
"headers": { | ||
"user_agent": "curl/7.64.1", | ||
"x-forwarded-for": "10.213.229.10", | ||
"host": "test-lambda-service-3908sdf9u3u.dkfjd93.vpc-lattice-svcs.us-east-2.on.aws", | ||
"accept": "*/*" | ||
}, | ||
"queryStringParameters": { | ||
"parameter1": [ | ||
"value1", | ||
"value2" | ||
], | ||
"parameter2": [ | ||
"value" | ||
] | ||
}, | ||
"body": "{\"message\": \"Hello from Lambda!\"}", | ||
"isBase64Encoded": false, | ||
"requestContext": { | ||
"serviceNetworkArn": "arn:aws:vpc-lattice:us-east-2:123456789012:servicenetwork/sn-0bf3f2882e9cc805a", | ||
"serviceArn": "arn:aws:vpc-lattice:us-east-2:123456789012:service/svc-0a40eebed65f8d69c", | ||
"targetGroupArn": "arn:aws:vpc-lattice:us-east-2:123456789012:targetgroup/tg-6d0ecf831eec9f09", | ||
"identity": { | ||
"sourceVpcArn": "arn:aws:ec2:region:123456789012:vpc/vpc-0b8276c84697e7339", | ||
"type" : "AWS_IAM", | ||
"principal": "arn:aws:sts::123456789012:assumed-role/example-role/057d00f8b51257ba3c853a0f248943cf", | ||
"sessionName": "057d00f8b51257ba3c853a0f248943cf", | ||
"x509SanDns": "example.com" | ||
}, | ||
"region": "us-east-2", | ||
"timeEpoch": "1696331543569073" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.