You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
aspect 'software.amazon.lambda:powertools-validation:{{ powertools.version }}' // Not needed when using the functional approach with ValidationUtils.validate()
83
+
implementation 'software.amazon.lambda:powertools-validation:{{ powertools.version }}' // Use this instead of 'aspect' when using the functional approach
82
84
}
83
85
84
86
sourceCompatibility = 11 // or higher
@@ -87,17 +89,18 @@ This utility provides JSON Schema validation for payloads held within events and
87
89
88
90
## Validating events
89
91
90
-
You can validate inbound and outbound events using `@Validation` annotation.
92
+
You can validate inbound and outbound events using either the `@Validation` annotation or the functional approach with `ValidationUtils.validate()` methods:
91
93
92
-
You can also use the `Validator#validate()` methods, if you want more control over the validation process such as handling a validation error.
94
+
-**@Validation annotation** - Simpler syntax with automatic validation, but requires AspectJ configuration
95
+
-**ValidationUtils.validate()** - No AspectJ required, provides more control over the validation process such as handling validation errors
93
96
94
-
We support JSON schema version 4, 6, 7, 2019-09 and 2020-12 using the [NetworkNT JSON Schema Validator](https://github.com/networknt/json-schema-validator). ([Compatibility with JSON Schema versions](https://github.com/networknt/json-schema-validator/blob/master/doc/compatibility.md)).
97
+
We support JSON schema version 4, 6, 7, 2019-09 and 2020-12 using the [NetworkNT JSON Schema Validator](https://github.com/networknt/json-schema-validator) ([Compatibility with JSON Schema versions](https://github.com/networknt/json-schema-validator/blob/master/doc/compatibility.md)).
95
98
96
99
The validator is configured to enable format assertions by default even for 2019-09 and 2020-12.
97
100
98
101
### Validation annotation
99
102
100
-
`@Validation` annotation is used to validate either inbound events or functions' response.
103
+
The `@Validation` annotation is used to validate either inbound events or functions' response.
101
104
102
105
It will fail fast if an event or response doesn't conform with given JSON Schema. For most type of events a `ValidationException` will be thrown.
103
106
@@ -129,11 +132,11 @@ While it is easier to specify a json schema file in the classpath (using the not
129
132
130
133
**NOTE**: It's not a requirement to validate both inbound and outbound schemas - You can either use one, or both.
131
134
132
-
### Validate function
135
+
### Functional approach with ValidationUtils
133
136
134
-
Validate standalone function is used within the Lambda handler, or any other methods that perform data validation.
137
+
The `ValidationUtils.validate()` method provides a functional approach that can be used within the Lambda handler or any other methods that perform data validation. This approach does not require AspectJ configuration.
135
138
136
-
You can also gracefully handle schema validation errors by catching `ValidationException`.
139
+
With this approach, you can gracefully handle schema validation errors by catching `ValidationException`.
0 commit comments