-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat: allow x-zod-schema extension property in openapi docs to override generated schema #237
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
hey, adding an escape hatch seems like a good idea, can you add a test and a changeset ? |
definitely. but it'll have to be after today's work day or tomorrow. export const {{@key}}{{#if (lookup ../emittedType @key)}}: z.ZodType<{{@key}}>{{/if}} = {{{this}}}; apparently to aid with circular type dependencies. |
hm I don't think so since you only want to override the zod schemas ? or maybe you'd also like to make a |
I'm not sure, is it ready to be merged ? |
Hi all, are there updates on this PR? I have the same need on some projects I'm working on 😇 |
feel free to take over the PR and update it so it can be merged |
What it does
Allows the user to override the zod schema generated for an openapi schema via an extension property:
This should generate:
Enable It Via
The new CLI option:
--x-zod-schema
.Reasoning
Tweaking the generated client via only handlebars is... quite limiting. In cases where there is a conflict between the spec author/developer and the openapi-zod-client plugin in terms of what should be generated, or when the generator turns out to be inflexible, this extension can provide a much cheaper alternative to forking the project.
Take my example above: I wanted coercion on my date types because js Date class is what I like to use in my form components. That's not possible out of the box with the plugin. In fact, I dropped my attempt at modifying the library to add an option for coercions halfway through and wrote this instead.