V5 beta (including zod/v4 support) #148
Replies: 14 comments 13 replies
-
|
Working on a project that would benefit from upgrading to Zod v4, we use nestjs-zod pretty heavily, so definitely keeping an eye on this getting merged to main! 🥳 |
Beta Was this translation helpful? Give feedback.
-
|
@BenLorantfy Thanks for your work with this project. I'm trialing the beta today alongside zod Thanks! |
Beta Was this translation helpful? Give feedback.
-
|
I tried to use the beta version but got this error: I assumed it was due to being on nest 10, but upgrading to nest 11 didn't help. const options = new DocumentBuilder().build()
const document = SwaggerModule.createDocument(app, options); // this is the line that throws an errorrelated packages in my project: |
Beta Was this translation helpful? Give feedback.
-
|
Is it hard to backport the zod4 migration? As for the openapi specification generation, the "example" values are really missing, and with zod4 we can have this with ease. I really love the package but i have to admit, i have really considered stop using it right now, as the openapi generation is a bit limited (which all will be fixed with zod4). I have some time where i can wait for the zod4 version with e.g. example fields in the openapi spec. Also happy to help by the way, if you tell me what i can do from my end to have it |
Beta Was this translation helpful? Give feedback.
-
|
Another beta version of nestjs-zod has been published that includes support for external / reusable schemas: Please feel free to try it out and let me know if you have any problems / feedback 🙏 |
Beta Was this translation helpful? Give feedback.
-
|
I just tested and it's working fine for me! |
Beta Was this translation helpful? Give feedback.
-
|
Just bumped to 5.0.0-beta.20250719T005107. |
Beta Was this translation helpful? Give feedback.
-
|
Just updated to 5.0.0-beta.20250719T005107 and it works 👍 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Hey folks, the last-ish beta version I plan to release is If you'd like to try it out, please feel free to lmk if you have any feedback (including on the README.md and MIGRATION.md pages) If all goes well I plan to release v5 this |
Beta Was this translation helpful? Give feedback.
-
|
There were still refs to export const variablesSchemaSchema = z.object({
properties: z.record(z.string(), z.any()).optional(),
required: z.array(z.string()).optional(),
});this works, but: export const variablesSchemaSchema = z.object({
properties: z.record(z.string(), jsonSchema4Schema).optional(),
required: z.array(z.string()).optional(),
});this doesn't. jsonSchema4Schema here: export const jsonSchema4Schema: z.ZodType<JSONSchema4> = z.lazy(
() =>
z
.object({
id: z.string().optional(),
$schema: z.string().optional(),
title: z.string().optional(),
description: z.string().optional(),
default: z.any().optional(),
// Numeric validators
multipleOf: z.number().positive().optional(),
maximum: z.number().optional(),
exclusiveMaximum: z.boolean().optional(),
minimum: z.number().optional(),
exclusiveMinimum: z.boolean().optional(),
// String validators
maxLength: z.number().int().nonnegative().optional(),
minLength: z.number().int().nonnegative().optional(),
pattern: z.string().optional(),
format: z.string().optional(),
// Array validators
additionalItems: z.union([z.boolean(), jsonSchema4Schema]).optional(),
items: z
.union([jsonSchema4Schema, z.array(jsonSchema4Schema)])
.optional(),
maxItems: z.number().int().nonnegative().optional(),
minItems: z.number().int().nonnegative().optional(),
uniqueItems: z.boolean().optional(),
// Object validators
maxProperties: z.number().int().nonnegative().optional(),
minProperties: z.number().int().nonnegative().optional(),
required: z.array(z.string()).optional(),
additionalProperties: z
.union([z.boolean(), jsonSchema4Schema])
.optional(),
definitions: z.record(z.string(), jsonSchema4Schema).optional(),
properties: z.record(z.string(), jsonSchema4Schema).optional(),
patternProperties: z.record(z.string(), jsonSchema4Schema).optional(),
dependencies: z
.record(z.string(), z.union([jsonSchema4Schema, z.array(z.string())]))
.optional(),
// Generic validators
enum: z.array(z.any()).optional(),
type: z
.union([
z.enum([
'string',
'number',
'integer',
'object',
'array',
'boolean',
'null',
]),
z.array(
z.enum([
'string',
'number',
'integer',
'object',
'array',
'boolean',
'null',
]),
),
])
.optional(),
// Applicators
allOf: z.array(jsonSchema4Schema).optional(),
anyOf: z.array(jsonSchema4Schema).optional(),
oneOf: z.array(jsonSchema4Schema).optional(),
not: jsonSchema4Schema.optional(),
})
.and(z.record(z.string(), z.any())), // Allows for custom/non-standard keywords
);``` |
Beta Was this translation helpful? Give feedback.
-
Now that I am migrating already, I found that these error messages are quite confusing, as I have over > 100 zod DTOs and I don't know which of them causes issues; I figured that this was caused by an Additionally, ( I don't want to open a new comment ) I learned that: "name": {
"type": "string",
"nullable": true
}becomes "name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
} |
Beta Was this translation helpful? Give feedback.
-
|
Re @BenLorantfy I still have an issue with the migration. In the md file you said that
But when I ran the program, I get the following stacktrace: This is from a controller annotated as follows: |
Beta Was this translation helpful? Give feedback.
-
|
Release notes: https://github.com/BenLorantfy/nestjs-zod/releases/tag/v5.0.0 |
Beta Was this translation helpful? Give feedback.





Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I wanted to announce that I've published the v5 beta. You can install it using the
nexttag:v5 is planning on including several updates, including:
zod/v4, which was released stable today (May 19th, 2025)i. Removing
patchNestJsSwaggerii. Deprecating
validate(redundant withparse),UseZodGuard / ZodGuard(not recommended for validation by nestjs),zodToOpenAPI(redundant withz.toJsonSchema), etc.Please feel free to try it out today and let me know in the comments if you run into any issues (especially if you try it out with
zod/v4on a medium / large codebase). But please note that some changes are likely in the coming days so it's not recommended for production use.You can also follow me on twitter if you want more updates: https://x.com/benlorantfy
Cheers,
Ben
Beta Was this translation helpful? Give feedback.
All reactions