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

`withAlias` is applied regardless of option

scarf005 opened this issue · comments

commented

/**
* When true, will either use the `operationId` as `alias`, or auto-generate it from the method and path.
*
* You can alternatively provide a custom function to generate the alias with the following signature:
* `(path: string, method: string, operation: OperationObject) => string`
* `OperationObject` is the OpenAPI operation object as defined in `openapi3-ts` npm package.
* @see https://github.com/metadevpro/openapi3-ts/blob/master/src/model/OpenApi.ts#L110
*
* @see https://www.zodios.org/docs/client#zodiosalias
* @default false
*/
withAlias?: boolean | ((path: string, method: string, operation: OperationObject) => string);
/**
* when using the default `template.hbs`, allow customizing the `export const {apiClientName}`

let getOperationAlias = (path: string, method: string, operation: OperationObject) =>
operation.operationId ?? method + pathToVariableName(path);
if (options?.withAlias && typeof options.withAlias === "function") {
getOperationAlias = options.withAlias;
}

const operationName = getOperationAlias(path, method, operation);
const endpointDefinition: EndpointDefinitionWithRefs = {
method: method as EndpointDefinitionWithRefs["method"],
path: replaceHyphenatedPath(path),
alias: operationName,
description: operation.description,
requestFormat: "json",
parameters: [],
errors: [],
response: "",
};

despite the docs, an alias will be generated even if withAlias is set to false. is this intended behavior?

weird but no it's not, feel free to make a PR for that ! 🙏

commented

alright, but i think it'll be a good idea to set withAlias default to true to not introduce a breaking change both to users and tests.