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
@@ -28,6 +28,7 @@ Find the complete project's [documentation here](https://docs.powertools.aws.dev
28
28
-**[Batch Processing](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/batch/)** - Utility to handle partial failures when processing batches from Amazon SQS, Amazon Kinesis Data Streams, and Amazon DynamoDB Streams.
29
29
-**[JMESPath Functions](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/jmespath/)** - Built-in JMESPath functions to easily deserialize common encoded JSON payloads in Lambda functions.
30
30
-**[Parser (Zod)](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/parser/)** - Utility that provides data validation and parsing using Zod, a TypeScript-first schema declaration and validation library.
31
+
-**[Validation](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/validation/)** - JSON Schema validation for events and responses, including JMESPath support to unwrap events before validation.
31
32
32
33
## Install
33
34
@@ -41,6 +42,7 @@ You can use Powertools for AWS Lambda (TypeScript) by installing it with your fa
Copy file name to clipboardExpand all lines: packages/validation/README.md
+216-5
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,6 @@
2
2
3
3
This utility provides JSON Schema validation for events and responses, including JMESPath support to unwrap events before validation.
4
4
5
-
> [!Warning]
6
-
> This feature is currently under development. As such it's considered not stable and we might make significant breaking changes before going before its release. You are welcome to [provide feedback](https://github.com/aws-powertools/powertools-lambda-typescript/discussions/3519) and [contribute to its implementation](https://github.com/aws-powertools/powertools-lambda-typescript/milestone/18).
7
-
8
5
Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda/typescript/latest/#features). You can use the library in both TypeScript and JavaScript code bases.
9
6
10
7
To get started, install the package by running:
@@ -13,8 +10,222 @@ To get started, install the package by running:
13
10
npm i @aws-lambda-powertools/validation
14
11
```
15
12
16
-
> [!Note]
17
-
> This readme is a work in progress.
13
+
## Features
14
+
15
+
You can validate inbound and outbound payloads using the `@validator` class method decorator or `validator` Middy.js middleware.
16
+
17
+
You can also use the standalone `validate` function, if you want more control over the validation process such as handling a validation error.
18
+
19
+
### Validator decorator
20
+
21
+
The `@validator` decorator is a TypeScript class method decorator that you can use to validate both the incoming event and the response payload.
22
+
23
+
If the validation fails, we will throw a `SchemaValidationError`.
Like the `@validator` decorator, you can choose to validate only the inbound or outbound payload.
99
+
100
+
### Standalone validate function
101
+
102
+
The `validate` function gives you more control over the validation process, and is typically used within the Lambda handler, or any other function that needs to validate data.
103
+
104
+
When using the standalone function, you can gracefully handle schema validation errors by catching `SchemaValidationError` errors.
Since the validator is built on top of [Ajv](https://ajv.js.org/), you can extend it with custom formats and external schemas, as well as bringing your own `ajv` instance.
178
+
179
+
The example below shows how to pass additional options to the `validate` function, but you can also pass them to the `@validator` decorator and `validator` middleware.
For more information on how to use the `validate` function, please refer to the [documentation](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/validation).
0 commit comments