risen228 / nestjs-zod-prisma

Zod Prisma fork for nestjs-zod
MIT License
62 stars 11 forks source link

DTO support for ApiProperty #11

Open LeulAria opened 1 year ago

LeulAria commented 1 year ago

can we add a confg like generateDTO for swagger to add api property

generator zod {
  provider                 = "nestjs-zod-prisma"
  output                   = "./src/zod" // (default) the directory where generated zod schemas will be saved

  relationModel            = true // (default) Create and export both plain and related models.
  // relationModel         = "default" // Do not export model without relations.
  // relationModel         = false // Do not generate related model

  generateDto              = true // (default) Generate DTOs for NestJS
  generateSwaggerApiProperty = true // (default) Genrate ApiPrpoertyDecorator on DTO's
  ...

From schema.prisma

model User {
  id                String   @id /// @z.string()
  email             String   @unique /// @z.string().email() @ApiProperty({ example: 'test@email.com', description: 'User email' })
  full_name         String   @unique /// @z.string().max(50, { message: "Fullname should be less than 50 characters " }) @ApiProperty({ example: 'Jean Doe', description: 'Users full name' })
  password          String   @unique /// @z.password().atLeastOne('digit').atLeastOne('lowercase').atLeastOne('uppercase').min(8).max(100) @ApiProperty({ description: 'User password' })
}

To Generate example

export class UserDto {
  @ApiProperty({ example: 'test@email.com', description: 'User email' })
  email: string;
  @ApiProperty({ example: 'Jean Doe', description: 'Users full name' })
  full_name: string;
  @ApiProperty({ description: 'User password' })
  password: string;
}
yangricardo commented 1 year ago

Also desire this =D There are some interesting behaviors from this other generator that could be included, like @DtoReadOnly and creations of Create / Update dtos

https://www.npmjs.com/package/prisma-types-generator