Create DTO classes out of Zod's schema definitions

Usage no npm install needed!

<script type="module">
  import abitiaZodDto from 'https://cdn.skypack.dev/@abitia/zod-dto';



Use zod v3 schemas to validate requests in Nest.js. Supports generating OpenApi too!

Getting Started

rush add -p @abitia/zod-dto

Setup a validation pipe (ZodValidationPipe)

In order to validate incoming requests, the ZodValidationPipe needs to be registered.

import { ZodValidationPipe } from '@abitia/zod-dto';

export class TestController {
    // ... your methods here

Create a DTO

const createAuctionDtoSchema = z.object({
    item: z.string(),
    price: z.number(),
    type: z.enum(['buy-it-now', 'auction'])

export class CreateAuctionDto extends createZodDto(createAuctionDtoSchema) {}

Use the DTO

export class TestController {
    public createAuction(
        @Body() dto: CreateAuctionDto,
    ) {
        // dto is of type { item: string, price: number, type: 'buy-it-now' | 'auction' }

Setup OpenAPI (Swagger) support

Add the following snippet to your application's bootstrap function:

import { patchNestjsSwagger } from '@abitia/zod-dto';


Then follow the Nest.js' Swagger Module Guide.

Local Development

Please add tests for every new feature.

  • npm run build - build the package
  • npm run lint - run linter
  • npm run test - run tests


Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.


We use SemVer for versioning.


  • Jakub Kisielewski - Initial work - kbkk

See also the list of contributors who participated in this project.


This project is licensed under the MIT License.