astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)

Home Page:openapi-zod-client.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Move endpointRefiner function call location to just before the endpoint information being pushed to endpoints array

imballinst opened this issue · comments

Hello! I submitted this issue before #173 and the PR for adding that feature before.

However, I think I made a mistake. Instead of placing it here, where it's still "fresh":

let endpointDefinition: EndpointDefinitionWithRefs = {
method: method as EndpointDefinitionWithRefs["method"],
path: replaceHyphenatedPath(path),
...(options?.withAlias && { alias: operationName }),
description: operation.description,
requestFormat: "json",
parameters: [],
errors: [],
response: "",
};
if (options?.endpointDefinitionRefiner) {
// Refine the endpoint definition, in case consumer wants to add some specific fields
// to be rendered in the Handlebars template.
endpointDefinition = options.endpointDefinitionRefiner(endpointDefinition, operation);
}

Perhaps it would be better to place it here, just before it's being pushed so that endpointRefiner can "inspect" all fields that are going to be used in the Handlebars template.

if (!endpointDefinition.response) {
endpointDefinition.response = voidSchema;
}
endpoints.push(endpointDefinition);

What do you think? Aalso I'm unsure if it counts as a minor change or patch change, let me know. Thanks!

yeah that makes sense, a patch is fine since it shouldnt break any current behaviour

Alrighty! I'm going to submit a PR in a bit. Thanks for the confirmation!