chrishoermann / zod-prisma-types

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

[Feature Request] appending custom string to generated type #276

Open valerii15298 opened 2 months ago

valerii15298 commented 2 months ago

Is your feature request related to a problem? Please describe. I wanna use prisma with Hono zod-opeapi

Basically like this:

model Post {
   // ...
   title  String /// @zod.string.openapi({example: 'John Doe'})
 }

Describe the solution you'd like The best solution would be just to append any string to generated schema type like this

model Post {
   // ...
   title  String /// @append: .openapi({example: 'John Doe'})
 }

So that after @append there could be any string. And it will generate:

export const PostSchema = z.object({
  id: z.string(),
  title: z.string().openapi({example: 'John Doe'})
  userId: z.string(),
})

Basically .openapi({example: 'John Doe'}) is appended as a string to already default generated type z.string()

Describe alternatives you've considered Using /// @zod.custom.use(z.string().openapi({example: 'John Doe'})) but it will overwrite whole type, while I just want extend it append to default generated type Put a comment and then use bash script to format correct schema

therebelrobot commented 5 days ago

Just chiming in here that this would also open up support for zod-to-openapi (looks like a similar independent library). I've tried other methods and it's seeming just not able to be done yet.

Additionally, other supported methods like .describe() aren't available without overriding the original type as well (that errors with 'describe' is not a valid validator type.)