astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)
openapi-zod-client.vercel.app
717 stars 80 forks source link

[Feature request] lower case schema names? #266

Open kornysietsma opened 6 months ago

kornysietsma commented 6 months ago

Hi - we have a preferred convention of using lower case first letters for Zod schema, and keeping upper case for types:

export const fooBar = z.object(...);
export type FooBar = z.infer<typeof fooBar>;

Is there a way to generate code with these kinds of names?

astahmer commented 6 months ago

you can use a custom template for that https://github.com/astahmer/openapi-zod-client?tab=readme-ov-file#customization

kornysietsma commented 6 months ago

Hmm - I'm not sure I can see how to do that. I could change the schema names in handlebars, by registering a helper function to rename the keys, something like

{{#each schemas}}
const {{#lowerCamel}}{{@key}}{{/lowerCamel}} = {{{this}}};
{{/each}}

but that wouldn't help where the {{{this}}} part of the schema referes to other schemas.

Anyway from looking through the openapi-zod-client it looks like it'd be fiddly; we can probably get by with a bit of post-generation conversion.