» npm install nestjs-zod
typescript - How to create custom validation pipe for NestJs that will use Zod as validator - Stack Overflow
Using global ZodValidationPipe (nestjs-zod) to validate body that is an array of objects? - Stack Overflow
OpenAPI validation for NestJS with Zod
OpenAPI validation for NestJS with Zod
hey guys, I'm new at nestjs framework and better to know that I'm a front-end developer! would you please let me know how may I use zod schemas as validator in nestjs as well? I have added nestjs-zod's validator as app module provider and converted the schema to dto using createZodDto method of the package although I get any type when I import the exported class that is extended the createZodDto(MY_ZOD_SCHEMA)!
tl;dr it basically uses typescript inference to automatically generate your class validation (no extra decorators)
If you use OpenAPI automatic generation in NestJS, for a standard project, you'd often have to define a property three times:
-
TypeScript: id: number;
-
Validation:
IsInt() -
Documentation:
ApiProperty()
And for class-validator and swagger, you often need more than 1 decorator each.
With this lib, for most properties, just the TypeScript definition is enough. You don't need any decorator, it's completely automatic.