Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
valerii15298 opened this issue Sep 22, 2024 · 1 comment
Open

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

valerii15298 opened this issue Sep 22, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@valerii15298
Copy link

valerii15298 commented Sep 22, 2024

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

@valerii15298 valerii15298 changed the title [Feature Request] support for custom string appending for generated type [Feature Request] appending custom string to generated type Sep 22, 2024
@therebelrobot
Copy link

therebelrobot commented Nov 20, 2024

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.)

@chrishoermann chrishoermann self-assigned this Dec 4, 2024
@chrishoermann chrishoermann added the enhancement New feature or request label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants