chrishoermann / zod-prisma-types

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

Field validators not working for negative numbers #192

Closed kevin-dp closed 8 months ago

kevin-dp commented 8 months ago

zod-prisma-types fails on the following model:

model User {
  id   Int @id
  foo  Int /// @zod.number.gt(-5)
}

The reason it fails is because the NUMBER_VALIDATOR_NUMBER_AND_MESSAGE_REGEX regex does not match the minus sign: https://github.com/chrishoermann/zod-prisma-types/blob/96c7dcb5c217baec88204922207f4e8899892f79/packages/generator/src/constants/regex.ts#L76

The regex can be modified to match an optional minus sign:

/.(?<validator>gt|gte|lt|lte|multipleOf)(?<number>\(-?[\d]+([,][ ]?)?(?<message>[{][ ]?message:[ ]?['"][\w\W]+['"][ ]?[}])?\))/
chrishoermann commented 8 months ago

@kevin-dp thanks for the hint. Should be working in 2.7.10 now