-
Notifications
You must be signed in to change notification settings - Fork 90
feat(v2): Validation failures return 400s #1489
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
jeromevdl
merged 21 commits into
aws-powertools:v2
from
skal111:feat/1298-validation-400
Dec 1, 2023
Merged
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f311722
#1298 first implem - api gateway events validation will be catched an…
ddbb2a1
#1298 updated tests in pt-examples-validation + sonar qaulity fixes
eda478d
#1298 code smell
4808b8f
1298 introduced E2E tests for validation
ecf056e
#1298 updated documentation to match new behavior of @Validation
3f64d55
#1298 implemented suggested changes
46f7f4c
#1298 added new E2E tests for ALB event, which should trigger a valid…
3a48656
#1298 original headers are returned as part of a 400 validation faile…
80ceb05
#1298 javadoc
5387e49
#1298 first implem - api gateway events validation will be catched an…
d72ee64
Rebased upstream
4ef6abf
1298 introduced E2E tests for validation
200cbd1
#1298 updated documentation to match new behavior of @Validation
22e069a
#1298 implemented suggested changes
a7d02c4
#1298 added new E2E tests for ALB event, which should trigger a valid…
dd13481
#1298 original headers are returned as part of a 400 validation faile…
a414353
#1298 javadoc
3e336c4
tests are compatible with java8
36318b2
fixed java8 compatibility
111d79a
indentation
jeromevdl c9ca742
Merge branch 'v2' into feat/1298-validation-400
jeromevdl 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
60 changes: 60 additions & 0 deletions
60
powertools-e2e-tests/handlers/validation-alb-event/pom.xml
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,60 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>e2e-test-handlers-parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>e2e-test-handler-validation-alb-event</artifactId> | ||
<packaging>jar</packaging> | ||
<name>A Lambda function using Powertools for AWS Lambda (Java) validation</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-validation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-lambda-java-events</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjrt</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>dev.aspectj</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-validation</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
...rs/validation-alb-event/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
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,40 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import com.amazonaws.services.lambda.runtime.events.ApplicationLoadBalancerRequestEvent; | ||
import com.amazonaws.services.lambda.runtime.events.ApplicationLoadBalancerResponseEvent; | ||
import com.amazonaws.services.lambda.runtime.events.SQSBatchResponse; | ||
|
||
import software.amazon.lambda.powertools.validation.Validation; | ||
public class Function implements RequestHandler<ApplicationLoadBalancerRequestEvent, ApplicationLoadBalancerResponseEvent> { | ||
// @Validation(inboundSchema = "classpath:/validation/inbound_schema.json", outboundSchema = "classpath:/validation/outbound_schema.json") | ||
// public String handleRequest(SQSEvent input, Context context) { | ||
// return "OK"; | ||
// } | ||
|
||
|
||
@Validation(inboundSchema = "classpath:/validation/inbound_schema.json", outboundSchema = "classpath:/validation/outbound_schema.json") | ||
// @Validation(inboundSchema = "classpath:/validation/inbound_schema.json") | ||
skal111 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public ApplicationLoadBalancerResponseEvent handleRequest(ApplicationLoadBalancerRequestEvent input, Context context) { | ||
ApplicationLoadBalancerResponseEvent response = new ApplicationLoadBalancerResponseEvent(); | ||
response.setBody(input.getBody()); | ||
response.setStatusCode(200); | ||
response.setIsBase64Encoded(false); | ||
return response; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
powertools-e2e-tests/handlers/validation-alb-event/src/main/resources/log4j2.xml
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration> | ||
<Appenders> | ||
<Console name="JsonAppender" target="SYSTEM_OUT"> | ||
<JsonTemplateLayout eventTemplateUri="classpath:LambdaJsonLayout.json" /> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="INFO"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Root> | ||
<Logger name="JsonLogger" level="INFO" additivity="false"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Logger> | ||
</Loggers> | ||
</Configuration> |
32 changes: 32 additions & 0 deletions
32
...e2e-tests/handlers/validation-alb-event/src/main/resources/validation/inbound_schema.json
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,32 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "http://example.com/product.json", | ||
"type": "object", | ||
"title": "Product schema", | ||
"description": "JSON schema to validate Products", | ||
"default": {}, | ||
"examples": [ | ||
{ | ||
"id": 43242, | ||
"name": "FooBar XY", | ||
"price": 258 | ||
} | ||
], | ||
"required": [ | ||
"price" | ||
], | ||
"properties": { | ||
"price": { | ||
"$id": "#/properties/price", | ||
"type": "number", | ||
"title": "Price of the product", | ||
"description": "Positive price of the product", | ||
"default": 0, | ||
"exclusiveMinimum": 0, | ||
"examples": [ | ||
258.99 | ||
] | ||
} | ||
}, | ||
"additionalProperties": true | ||
} |
32 changes: 32 additions & 0 deletions
32
...2e-tests/handlers/validation-alb-event/src/main/resources/validation/outbound_schema.json
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,32 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "http://example.com/product.json", | ||
"type": "object", | ||
"title": "Product schema", | ||
"description": "JSON schema to validate Products", | ||
"default": {}, | ||
"examples": [ | ||
{ | ||
"id": 43242, | ||
"name": "FooBar XY", | ||
"price": 258 | ||
} | ||
], | ||
"required": [ | ||
"price" | ||
], | ||
"properties": { | ||
"price": { | ||
"$id": "#/properties/price", | ||
"type": "number", | ||
"title": "Price of the product", | ||
"description": "Positive price of the product", | ||
"default": 0, | ||
"exclusiveMaximum": 1000, | ||
"examples": [ | ||
258.99 | ||
] | ||
} | ||
}, | ||
"additionalProperties": true | ||
} |
60 changes: 60 additions & 0 deletions
60
powertools-e2e-tests/handlers/validation-apigw-event/pom.xml
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,60 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>e2e-test-handlers-parent</artifactId> | ||
<version>1.0.0</version> | ||
</parent> | ||
|
||
<artifactId>e2e-test-handler-validation-apigw-event</artifactId> | ||
<packaging>jar</packaging> | ||
<name>A Lambda function using Powertools for AWS Lambda (Java) validation</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-validation</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.amazonaws</groupId> | ||
<artifactId>aws-lambda-java-events</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.aspectj</groupId> | ||
<artifactId>aspectjrt</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>dev.aspectj</groupId> | ||
<artifactId>aspectj-maven-plugin</artifactId> | ||
<configuration> | ||
<source>${maven.compiler.source}</source> | ||
<target>${maven.compiler.target}</target> | ||
<complianceLevel>${maven.compiler.target}</complianceLevel> | ||
<aspectLibraries> | ||
<aspectLibrary> | ||
<groupId>software.amazon.lambda</groupId> | ||
<artifactId>powertools-validation</artifactId> | ||
</aspectLibrary> | ||
</aspectLibraries> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
33 changes: 33 additions & 0 deletions
33
.../validation-apigw-event/src/main/java/software/amazon/lambda/powertools/e2e/Function.java
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,33 @@ | ||
/* | ||
* Copyright 2023 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package software.amazon.lambda.powertools.e2e; | ||
|
||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; | ||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; | ||
|
||
import software.amazon.lambda.powertools.validation.Validation; | ||
|
||
public class Function implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { | ||
@Validation(inboundSchema = "classpath:/validation/inbound_schema.json", outboundSchema = "classpath:/validation/outbound_schema.json") | ||
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) { | ||
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent(); | ||
response.setBody(input.getBody()); | ||
response.setStatusCode(200); | ||
response.setIsBase64Encoded(false); | ||
return response; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
powertools-e2e-tests/handlers/validation-apigw-event/src/main/resources/log4j2.xml
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,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration> | ||
<Appenders> | ||
<Console name="JsonAppender" target="SYSTEM_OUT"> | ||
<JsonTemplateLayout eventTemplateUri="classpath:LambdaJsonLayout.json" /> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Root level="INFO"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Root> | ||
<Logger name="JsonLogger" level="INFO" additivity="false"> | ||
<AppenderRef ref="JsonAppender"/> | ||
</Logger> | ||
</Loggers> | ||
</Configuration> |
32 changes: 32 additions & 0 deletions
32
...e-tests/handlers/validation-apigw-event/src/main/resources/validation/inbound_schema.json
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,32 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"$id": "http://example.com/product.json", | ||
"type": "object", | ||
"title": "Product schema", | ||
"description": "JSON schema to validate Products", | ||
"default": {}, | ||
"examples": [ | ||
{ | ||
"id": 43242, | ||
"name": "FooBar XY", | ||
"price": 258 | ||
} | ||
], | ||
"required": [ | ||
"price" | ||
], | ||
"properties": { | ||
"price": { | ||
"$id": "#/properties/price", | ||
"type": "number", | ||
"title": "Price of the product", | ||
"description": "Positive price of the product", | ||
"default": 0, | ||
"exclusiveMinimum": 0, | ||
"examples": [ | ||
258.99 | ||
] | ||
} | ||
}, | ||
"additionalProperties": true | ||
} |
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.