-
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
Getting types for parameters #256
Comments
Yes I've tried this but types are not generated for parameters and anyway types are not manipulable as schemas are. |
I've had some success, enhancing the {{#if @root.options.withAlias}}
{{#each endpoints}}
export const {{alias}}Endpoint = {
method: "{{method}}" as const,
path: "{{path}}" as const,
{{#if @root.options.withAlias}}
{{#if alias}}
alias: "{{alias}}" as const,
{{/if}}
{{/if}}
{{#if description}}
description: `{{description}}`,
{{/if}}
{{#if requestFormat}}
requestFormat: "{{requestFormat}}" as const,
{{/if}}
{{#if parameters}}
parameters: makeParameters([
{{#each parameters}}
{
name: "{{name}}" as const,
{{#if description}}
description: `{{description}}`,
{{/if}}
{{#if type}}
type: "{{type}}" as const,
{{/if}}
// @ts-ignore
schema: {{{schema}}}
},
{{/each}}
]),
{{/if}}
response: {{{response}}},
{{#if errors.length}}
errors: makeErrors([
{{#each errors}}
{
{{#ifeq status "default" }}
status: "default" as const,
{{else}}
status: {{status}} as const,
{{/ifeq}}
{{#if description}}
description: `{{description}}` as const,
{{/if}}
// @ts-ignore
schema: {{{schema}}}
},
{{/each}}
])
{{/if}}
};
type T{{alias}}Endpoint = typeof {{alias}}Endpoint;
{{/each}}
{{/if}}
{{#if @root.options.withAlias}}
export type TEndpoints = [
{{#each endpoints}}
{{#if @root.options.withAlias}}
T{{alias}}Endpoint,
{{else}}
{{/if}}
{{/each}}
];
export namespace types {
{{#each schemas}}
export type {{@key}} = z.infer<typeof schemas.{{@key}}>;
{{/each}}
}
export type TNarrowEndpoints = Narrow<TEndpoints>;
{{/if}} which exports every Endpoint config, a |
Hello @astahmer !
I'm using the lib along with
openapi-generator
to get:For now, I'm using the template to get well formed objects for each spec like this
I would like to have associated types for these.
I tried an implementation with
z.infer
but it's only working with strict TS and we're not here yet.I've seen in
typed-openapi
that you can get types for a path like this:Is there a way to do the same with
openapi-zod-client
template?FI, I can't use
typed-openapi
directly as I need both schemas and ts types withoutz.infer
, and I need a template to get clean files.Thanks a lot!
The text was updated successfully, but these errors were encountered: