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 - 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 ...
» npm install nestjs-zod
Published Jul 25, 2026
Version 5.5.0
Swagger with zod schemas
Is there an existing issue that is already proposing this? I have searched the existing issues Is your feature request related to a problem? Please describe it At the moment, when using Zod schemas for DTOs in NestJS, the built-in Swagge... More on github.com
Is there an easy way to create api documentation using Drizzle/Prisma ?
That’s not the only purpose of a DTO class. DTOs are there to validate and also to allow you to control which fields are returned by an API. If you return the full entity you could expose data to clients that should not be returned to them. Retuning model instances straight from the database is generally bad practice. Your services should deal with model instances but your http layer (controllers in NestJS) should make use of DTOs to control data access. More on reddit.com
Anyone using decorators, or some other form of inline documentation, to generate an openapi spec file based on a typescript library?
Im using tsoa for describing controllers There is a lot of things supported: Jsdoc (each endpoint could be described using markdown) Request\response definitions also exported to result swagger.json file Built-in validators More on reddit.com
Generate Postman documentation from zod DTO nest js
Hey I currently use nestjs and postman to develop API’s. but for the postman part i have to manually create requests and add it to the collection its… More on reddit.com
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 ...
Author BenLorantfy
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
npm install openapi3-ts zod @anatine/zod-openapi @anatine/zod-nestjs · Use Zod to generate a schema. Additionally, use @anatidae/zod-openapi to extend a schema for OpenAPI and Swagger UI.
Author anatine
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 › 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](https://www.npmjs.com/package/nestjs-zod) for auto openapi registration (and optionally validation) for routes in NestJS. - ThorntonChan/nest-zod-swagger
Author ThorntonChan
Reddit
reddit.com › r/nestjs › is there an easy way to create api documentation using drizzle/prisma ?
r/nestjs on Reddit: Is there an easy way to create api documentation using Drizzle/Prisma ?
March 27, 2025 -
Hi, how is it going?
I'm trying to use Drizzle, but i don't get how should I make the documentation using @nestjs/swagger. Because the first approach is to define dto clases that only has the purpose of beign the type in @ApiResponse and that sound like overcomplicated. Is there another way or this problem is inherent to the Workflow using these techs?
Top answer 1 of 4
5
That’s not the only purpose of a DTO class. DTOs are there to validate and also to allow you to control which fields are returned by an API. If you return the full entity you could expose data to clients that should not be returned to them. Retuning model instances straight from the database is generally bad practice. Your services should deal with model instances but your http layer (controllers in NestJS) should make use of DTOs to control data access.
2 of 4
3
I went this path very recently looking for a good way to generate documentation for a Nest API. (Also I use prisma but imo this doesn't matter very much). The first issue that you (almost) can't avoid is that your typesafe schema (prisma, drizzle or kysely doesn't matter) or your TypeDtos does not exists at runtime (because it's just Typescript types) so it's very hard to generate openapi schemas from this. One path I tried is Typia / Nestia. That is a wrapper over all the main NestJS decorators. Typia adds code (patches) to the TS codebase to enable some very interesting capabilities. It can generate a whole openapi documentation inferred from the Typescript types from your decorated endpoints inputs or outputs + automatic runtime validation of those types. WOW best thing ever I thought ! But there is a catch. Patching the TS codebase is not something easy and that made the setup with something like Prisma impossible for me... And now that TS is moving to GO I think this approach won't be available very soon. So for me it's too fragile. So I guess I have to write something that will be held at runtime in order to generate the documentation of my api... I don't like the DTO approach from @nestjs/swagger because I find it very very verbose with all the decorators and having to duplicate some information like the type of each property, the Nullability etc... Also I'm not a very big fan of classes but if it's to model my data why not... But this API is just way too verbose. To end my journey I landed on TS-REST, a framework heavily inspired by TRPC but for REST APIs and it has support for NestJs. You define a contract where you can specify the endpoints, theirs inputs and outputs. And then you use the custom decorator in your Nest Api to implement your backend and it's fully typed. For good documentation and validation you should use Zod schemas in your contract. You can also use your contract to generate a typesafe client and you can use your Zod schema to coerces values etc... I understand that's not ideal because you still have to re-define your DTOs as Zod schemas but in my project and in my opinion this is a very good way to build your typesafe api with good automatic documentation. Edited: typos
HackMD
hackmd.io › UVRGb-LoQPK7a2Obls_iAw
Deep Dive: NestJS + Zod Integration Architecture - HackMD
# Deep Dive: NestJS + Zod Integration Architecture ## Table of Contents 1. [Project Overview](#project-overview) 2. [TypeScript Decorators](#typescript-decorators) 3. [Metadata Reflection System](#metadata-reflection-system) 4. [Auto-Validation Mechanism](#auto-validation-mechanism) 5. [createZodDto Deep Analysis](#createzoddto-deep-analysis) 6. [Complete Integration Flow](#complete-integration-flow) ## Project Overview ### Repository Structure This is a monorepo containing NestJS + Zod validation utilities: ``` packages/ ├── nestjs-zod/src/ # Core NestJS + Zod integration library │ ├
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
Nestzod
nestzod.dev
nest-zod
Zod-powered request parsing, response ... requests and encode outgoing responses. ... Use `nest-zod/swagger` to automatically generate OpenAPI metadata from the same schemas....