You can use the lib: https://github.com/colinhacks/zod
And do:
import { createZodDto } from 'nestjs-zod';
import { z } from 'nestjs-zod/z';
// Define Zod schema for CountrySchema
const CountrySchema = z.object({
// ... (your schema definition here)
});
// Create DTO class using createZodDto
export class CountryDTO extends createZodDto(CountrySchema) {}
You need to make some configurations in your main.ts/js
You need to import PatchNestJsSwagger into the main.ts and call it, like this:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { Logger } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { patchNestJsSwagger } from 'nestjs-zod';
import { ConfigService } from '@nestjs/config';
import { Env } from './env';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get<ConfigService<Env, true>>(ConfigService);
patchNestJsSwagger();
app.enableCors();
const config = new DocumentBuilder()
.setTitle('Area API')
.setDescription('Uma api para uma área de membros')
.setVersion('1.0')
.addTag('MEMBROS')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api-docs', app, document);
app.setGlobalPrefix('api');
const port = configService.get('PORT', { infer: true });
await app.listen(port);
Logger.log(`Server running on http://localhost:${port}`, 'Bootstrap');
}
bootstrap();
You can find more informations in the nestjs/zod lib quoted in the start of the response.
Answer from Aleksander Ribeiro Vale on Stack Overflownpm
npmjs.com › package › nestjs-zod
nestjs-zod - npm
May 15, 2026 - Providing a compile-time typescript type from the Zod schema · Providing an OpenAPI schema when using nestjs/swagger
» npm install nestjs-zod
Published Jul 25, 2026
Version 5.5.0
14:56
NestJS Swagger Guide: OpenApi Documentation - YouTube
33:51
NestJs Full Course 2024 -2: Validation In NestJs (ZOD Included) ...
40:12
Validação Com Zod No NestJS | Crie Seu Próprio Decorator! - YouTube
NestJS DTO Schemas, Validation & Pipes Tutorial
Nestjs Configuration (From Basic to Validating with Zod ...
npm
npmjs.com › package › @anatine › zod-nestjs
@anatine/zod-nestjs - npm
Remove dependency on @nestjs/swagger by providing a Swagger UI. Expand to create an express-only wrapper (without NestJS) Auto generate client side libs with Zod validation.
» npm install @anatine/zod-nestjs
Published Apr 05, 2025
Version 2.0.12
GitHub
github.com › wahyubucil › nestjs-zod-openapi
GitHub - wahyubucil/nestjs-zod-openapi: NestJS helper to easily use Zod with OpenAPI · GitHub
This function should run before the `SwaggerModule.createDocument` function. const document = SwaggerModule.createDocument(app, config) SwaggerModule.setup('docs', app, document) await app.listen(3000) } bootstrap() ... localeCompare: using JavaScript localeCompare to sort the order, it will use each locale sorting mechanism. ... // app.module.ts import { APP_PIPE } from '@nestjs/core' import { ZodValidationPipe } from '@wahyubucil/nestjs-zod-openapi' @Module({ providers: [ { provide: APP_PIPE, useClass: ZodValidationPipe, }, ], }) export class AppModule {}
Starred by 22 users
Forked by 2 users
Languages TypeScript 93.6% | JavaScript 6.4%
GitHub
github.com › nestjs › nest › issues › 15837
Swagger with zod schemas · Issue #15837 · nestjs/nest
October 24, 2025 - Many modern TypeScript projects ... in stacks using tRPC, Next.js, or Fastify. In NestJS, however, Swagger only works with class-based DTOs that use decorators....
Author nestjs
GitHub
github.com › risen228 › nestjs-zod
GitHub - BenLorantfy/nestjs-zod: All NestJS + Zod utilities you need · GitHub
May 15, 2022 - This command runs a codemod that adds the validation pipe, serialization interceptor, http exception filter, and swagger cleanup function · Alternatively, you can follow the manual setup steps below ... + import { APP_PIPE } from '@nestjs/core'; + import { ZodValidationPipe } from 'nestjs-zod'; @Module({ imports: [], controllers: [AppController], providers: [ + { + provide: APP_PIPE, + useClass: ZodValidationPipe, + }, ] }) export class AppModule {}
Starred by 1.1K users
Forked by 110 users
Languages TypeScript 87.2% | JavaScript 12.8%
GitHub
github.com › anatine › zod-plugins › blob › main › packages › zod-nestjs › README.md
zod-plugins/packages/zod-nestjs/README.md at main · anatine/zod-plugins
Remove dependency on @nestjs/swagger by providing a Swagger UI. Expand to create an express-only wrapper (without NestJS) Auto generate client side libs with Zod validation.
Author anatine
GitHub
github.com › ThorntonChan › nest-zod-swagger
GitHub - ThorntonChan/nest-zod-swagger: A lightweight library based on [nestjs-zod](https://www.npmjs.com/package/nestjs-zod) for auto openapi registration (and optionally validation) for routes in NestJS.
A lightweight library based on nestjs-zod and nestjs-swagger for auto openapi registration (and optionally validation) for routes in NestJS.
Author ThorntonChan
YouTube
youtube.com › watch
Zod + NestJS | Validation, Types & Swagger - YouTube
Learn how to integrate Zod with NestJS to handle validation, TypeScript types, and Swagger documentation — all from a single schema definition.We build a ful...
Published February 15, 2026
GitHub
github.com › BenLorantfy › nestjs-zod › releases
Releases · BenLorantfy/nestjs-zod
May 15, 2026 - fix: remove optional object properties from required array when using @nestjs/swagger v7 #371 (@55Kamiryo)
Author BenLorantfy
npm
npmjs.com › package › @palmetto › nestjs-zod-dto
@palmetto/nestjs-zod-dto - npm
March 4, 2026 - Improves NestJS DTOs with zod without comprimising on automatic swagger generation.
» npm install @palmetto/nestjs-zod-dto
Published Jun 12, 2026
Version 2.3.0
Stack Overflow
stackoverflow.com › questions › 77287011 › nestjs-swagger-multipart-file-upload-issue-with-zod
typescript - NestJS Swagger Multipart File Upload Issue with Zod - Stack Overflow
The problem is that zod, which I use for validation, doesn't have a specific File type, and Swagger doesn't recognize it as a file input because it lacks the @ApiProperty({ format: 'binary' }) decoration. I'm looking for a solution to properly document and validate multipart file uploads using zod And in the same time I want to keep up using my Dtos that i am doing ... Copyimport { createZodDto } from 'nestjs-zod/dto'; import * as z from 'nestjs-zod/z'; export const schema = z.object({ field: z.string().optional(), requiredFile: z .string() .refine((str: any): str is Buffer => Buffer.isBuffer(Buffer.from(str))), optionalFile: z .string() .refine((str: any): str is Buffer => Buffer.isBuffer(Buffer.from(str))) .optional(), }); export class Dto extends createZodDto(schema) {}
Nestzod
nestzod.dev
nest-zod
Zod-powered request parsing, response ... and encode outgoing responses. ... Use `nest-zod/swagger` to automatically generate OpenAPI metadata from the same schemas....