@origins-digital/zod-openapi-utils 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,10 +11,11 @@ npm install @origins-digital/zod-openapi-utils
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
13
|
- Automatic conversion of Zod schemas to OpenAPI/Swagger schemas
|
|
14
|
-
- Support for all Zod types and validations
|
|
14
|
+
- Support for all Zod types and validations including lazy schemas
|
|
15
15
|
- Type-safe API documentation
|
|
16
16
|
- Seamless integration with NestJS Swagger
|
|
17
17
|
- Custom format support (email, URL, UUID, CUID, etc.)
|
|
18
|
+
- Support for recursive and circular references
|
|
18
19
|
|
|
19
20
|
## Usage
|
|
20
21
|
|
|
@@ -51,7 +52,7 @@ export class AppModule {
|
|
|
51
52
|
import { z } from 'zod';
|
|
52
53
|
import { createZodDto } from '@origins-digital/zod-openapi-utils';
|
|
53
54
|
|
|
54
|
-
// Define your Zod schema
|
|
55
|
+
// Define your Zod schema with .openapi() decorator
|
|
55
56
|
const UserSchema = z
|
|
56
57
|
.object({
|
|
57
58
|
id: z.string().uuid(),
|
|
@@ -61,7 +62,10 @@ const UserSchema = z
|
|
|
61
62
|
createdAt: z.date(),
|
|
62
63
|
password: z.string().min(8).password(),
|
|
63
64
|
})
|
|
64
|
-
.
|
|
65
|
+
.openapi({
|
|
66
|
+
title: 'User',
|
|
67
|
+
description: 'User entity schema',
|
|
68
|
+
});
|
|
65
69
|
|
|
66
70
|
// Create DTO from Zod schema
|
|
67
71
|
export class CreateUserDto extends createZodDto(UserSchema) {}
|
|
@@ -86,8 +90,9 @@ export class UsersController {
|
|
|
86
90
|
- **Objects**: nested schemas
|
|
87
91
|
- **Arrays**: min/max length
|
|
88
92
|
- **Unions and Enums**
|
|
93
|
+
- **Lazy Schemas**: recursive and circular references
|
|
89
94
|
- **Custom Formats**: password, time, etc.
|
|
90
|
-
- **Nested types**: This package is also able to detect nested types when using the .
|
|
95
|
+
- **Nested types**: This package is also able to detect nested types when using the .openapi() method, and create the reference in the openapi spec.
|
|
91
96
|
|
|
92
97
|
## Error Handling
|
|
93
98
|
|