Skip to content

[BUG] typescript-axios generation produces duplicate identifiers when a path parameter called "index" is used #17068

@rmisiakexscientia

Description

@rmisiakexscientia

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

In 7.1.0 when a request uses a path parameter called index the typescript generated with the typescript-axios generator does not compile because it contains duplicate identifiers.

7.0.0 works correctly.

openapi-generator version
"@openapitools/openapi-generator-cli": "^2.7.0",
{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.1.0"
  }
}
OpenAPI declaration file content or url

https://gist.github.com/rmisiakexscientia/074283d6ef3e975dbd6250ef550b64c7

Generation Details
Steps to reproduce
npx openapi-generator-cli generate -g typescript-axios -i "./src/openapi.json" -o "./src/client" --additional-properties="apiPackage=clients,modelPackage=models,withoutPrefixEnums=false,withSeparateModelsAndApi=true"

Then in count-api.ts you get this

/**
 * CountApi - functional programming interface
 * @export
 */
export const CountApiFp = function(configuration?: Configuration) {
    const localVarAxiosParamCreator = CountApiAxiosParamCreator(configuration)
    return {
        /**
         * 
         * @param {CountControllerTotalIndexEnum} index 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async countControllerTotal(index: CountControllerTotalIndexEnum, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.countControllerTotal(index, options);
            const index = configuration?.serverIndex ?? 0;
            const operationBasePath = operationServerMap['CountApi.countControllerTotal']?.[index]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, operationBasePath || basePath);
        },
    }
};

which is invalid because index is both a parameter and declared inside the body

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions