chrishoermann / zod-prisma-types

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

schema.prisma type descriptions? #154

Closed gregg-cbs closed 8 months ago

gregg-cbs commented 1 year ago

Hi Chris,

Sorry to bother you but I have a question I couldnt quite find the answer to.

In my prisma.schema I want to add zod comments to types to add a description to zod.

/// @zod.object({ description: "The dimensions of the product. This is different to the shipping or boxed dimensions and is usually smaller. If you cannot find the product dimensions make this the same as the dimensions_packed." })
type Dimensions {
  width  Float
  depth  Float
  height Float
  unit   String
}

or better yet (this failed because z.object is not equal to Dimensions type)

model Product {
  dimensions        Dimensions? /// @zod.object({ description: "The dimensions of the product. This is different to the shipping or boxed dimensions and is usually smaller. If you cannot find the product dimensions make this the same as the dimensions_packed." })
  dimensions_packed Dimensions? /// @zod.object({ description: "The boxed / shipping / packaged dimensions of the product." })
}

Neither method was successful in adding the descriptions to zod.

chrishoermann commented 8 months ago

@gregg-cbs the first example should work now in the latest version when using

/// @zod.describe("some description")
model MyModel {
...fields
}

for the second one there is no solution implemented yet

gregg-cbs commented 8 months ago

Thanks. I have since moved on from this project using prisma. I appreciate the response. Hopefully this will help others out there.