Skip to content

Commit f1f0b5c

Browse files
committed
Update validation docs highlithing functional API.
1 parent 95f05d7 commit f1f0b5c

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

docs/utilities/validation.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This utility provides JSON Schema validation for payloads held within events and
2626
</dependencies>
2727
...
2828
<!-- configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lambda-powertools-java aspects into your project -->
29+
<!-- Note: This AspectJ configuration is not needed when using the functional approach with ValidationUtils.validate() -->
2930
<build>
3031
<plugins>
3132
...
@@ -67,18 +68,19 @@ This utility provides JSON Schema validation for payloads held within events and
6768

6869
=== "Gradle"
6970

70-
```groovy hl_lines="3 11"
71+
```groovy hl_lines="3 11 12"
7172
plugins {
7273
id 'java'
73-
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0'
74+
id 'io.freefair.aspectj.post-compile-weaving' version '8.1.0' // Not needed when using the functional approach with ValidationUtils.validate()
7475
}
7576
7677
repositories {
7778
mavenCentral()
7879
}
7980
8081
dependencies {
81-
aspect 'software.amazon.lambda:powertools-validation:{{ powertools.version }}'
82+
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
8284
}
8385
8486
sourceCompatibility = 11 // or higher
@@ -87,17 +89,18 @@ This utility provides JSON Schema validation for payloads held within events and
8789

8890
## Validating events
8991

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

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
9396

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)).
9598

9699
The validator is configured to enable format assertions by default even for 2019-09 and 2020-12.
97100

98101
### Validation annotation
99102

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.
101104

102105
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.
103106

@@ -129,11 +132,11 @@ While it is easier to specify a json schema file in the classpath (using the not
129132

130133
**NOTE**: It's not a requirement to validate both inbound and outbound schemas - You can either use one, or both.
131134

132-
### Validate function
135+
### Functional approach with ValidationUtils
133136

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.
135138

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`.
137140

138141
=== "MyFunctionHandler.java"
139142

0 commit comments

Comments
 (0)