chrishoermann / zod-prisma-types

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

Custom validations aren't propagated to all generated schemas #137

Closed ghoshnirmalya closed 1 year ago

ghoshnirmalya commented 1 year ago

Description

For the following model:

model Project {
  id          Int      @id @default(autoincrement())
  title       String /// @zod.string.min(4).max(10)
  creatorId   String

  author User @relation(fields: [creatorId], references: [id])

  @@index([creatorId])
}

ProjectCreateInputSchema show the correct validations:

export const ProjectCreateInputSchema: z.ZodType<Prisma.ProjectCreateInput> = z.object({
  title: z.string().min(4).max(10),
  author: z.lazy(() => UserCreateNestedOneWithoutProjectsInputSchema)
}).strict();

However, ProjectCreateWithoutAuthorInputSchema doesn't show the correct validations:

export const ProjectCreateWithoutAuthorInputSchema: z.ZodType<Prisma.ProjectCreateWithoutAuthorInput> = z.object({
  title: z.string(),
}).strict();

Expected behaviour

The title attribute should be the following:

- title: z.string(),
+ title: z.string().min(4).max(10)
chrishoermann commented 1 year ago

@ghoshnirmalya thanks for the report. This is currently not implemented. I need to refine the logic that determines if the inputSchema should be validated.

chrishoermann commented 1 year ago

@ghoshnirmalya should work now in the latest version