chrishoermann / zod-prisma-types

Generator creates zod types for your prisma models with advanced validation
Other
579 stars 43 forks source link

`custom.omit` and Comments Together Result in Incorrect Generated Schema #185

Closed carlosyan1807 closed 8 months ago

carlosyan1807 commented 10 months ago

First of all, thanks for your awesome work. I had a bit of a problem using custom.omit and comments in schema.prisma.

model User {
  /// ID
  id Int @id @default(autoincrement())
  /// Nickname
  nickname String
  /// Avatar
  avatar String?
  /// Private Salt
  privateSalt String? /// @zod.custom.omit(["model", "input"])
}

The generated UserSchema is:

export const UserSchema = z.object({
  /**
   * ID
   */
  id: z.number().int(),
  /**
   * Nickname
   */
  nickname: z.string(),
  /**
   * Avatar
   */
  avatar: z.string().nullable(),
  // omitted: 
  /**
   * Private Salt
   */
  privateSalt: z.string().nullable(),
}

Omitting works correctly when no comments are used. I've tried multiple variations, but none produce the expected result.

  /// Private Salt
  /// @zod.custom.omit(["model", "input"])
  privateSalt String? 

  /// @zod.custom.omit(["model", "input"])
  /// Private Salt
  privateSalt String? 

  /// Private Salt
  privateSalt String?   /// @zod.custom.omit(["model", "input"])

 /// @zod.custom.omit(["model", "input"])
  privateSalt String?    /// Private Salt

Any help or insights on how to resolve this problem would be greatly appreciated!

chrishoermann commented 8 months ago

@carlosyan1807 this shold work - Definitly a bug

chrishoermann commented 8 months ago

@carlosyan1807 should be fixed now in the latest version

carlosyan1807 commented 8 months ago

Hey, that's great. I've tried, its worked.

Thank you!