Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure applications to generate NestJS DTOs from Zod schemas #194

Merged
merged 5 commits into from
Mar 27, 2024

Conversation

wcalderipe
Copy link
Collaborator

@wcalderipe wcalderipe commented Mar 27, 2024

This PR configures NestJS servers to enable the generation of DTOs from Zod schemas.

  • It provides a unified validation experience from the front-end to the back-end, with Zod schemas as the primary library.
  • It enhances DevEx with Zod, according to the team's preference.

Here's an example on how to convert a schema to a DTO:

import { createZodDto } from 'nestjs-zod'
import { z } from 'zod'

const CredentialsSchema = z.object({
  username: z.string(),
  password: z.string(),
})

class CredentialsDto extends createZodDto(CredentialsSchema) {}

If you would like to know more about Zod validations in NestJS, head over to https://github.com/risen228/nestjs-zod

Configure Swagger on all applications to understand Zod DTOs.
@wcalderipe wcalderipe self-assigned this Mar 27, 2024
@wcalderipe wcalderipe marked this pull request as ready for review March 27, 2024 12:55
@wcalderipe wcalderipe merged commit af6bc5c into main Mar 27, 2024
5 checks passed
@wcalderipe wcalderipe deleted the chore/generate-dtos-from-zod-schemas branch May 27, 2024 09:17
mattschoch pushed a commit that referenced this pull request Jun 19, 2024
* Install nestjs-zod

* Configure Swagger on all applications to understand Zod DTOs

* Rename nestjs-shared decorators directory

* Fix DTO unit test

* Add utility to set up Swagger

* Refactor NestJS application bootstrap to use shared withSwagger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant