Openapi-generator: Query String parameter named 'configuration' conflicts with the api configuration in the generated typescript-fetch client.

Created on 1 Apr 2019  路  6Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [ ] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description

Query String parameter named 'configuration' conflicts with the api configuration in the generated typescript-fetch client. Here is a sample of the problem:

/**
 *  - fetch parameter creator
 * @export
 */
export const ControllerApiFetchParamCreator = function (configuration?: Configuration) {
    return {
        /**
         */
        getControllers(skip?: number, take?: number, controllerId?: string, configuration?: string, options: any = {}): FetchArgs {
            const localVarPath = `/api/Controller`;
            const localVarUrlObj = url.parse(localVarPath, true);
            let baseOptions;
            if (configuration) {
                baseOptions = configuration.baseOptions; // note this conflicts with line 5 parameter
            }
            const localVarRequestOptions = Object.assign({ method: 'GET' }, baseOptions, options);
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication oauth2-clientCred required
            // oauth required
            if (configuration && configuration.accessToken) { // note this conflicts with line 5 parameter
                const localVarAccessTokenValue = typeof configuration.accessToken === 'function' 
                    ? configuration.accessToken("oauth2-clientCred", ["scope1", "scope2", "scope3"])
                    : configuration.accessToken; // note this conflicts with line 5 parameter
                localVarHeaderParameter["Authorization"] = "Bearer " + localVarAccessTokenValue;
            }

openapi-generator version

v3.3.4

OpenAPI declaration file content or url

I don't have one available that I can share; however, it occurs anytime a any parameter is named 'configuration' since that conflicts with the internal client configuration object.

Command line used for generation

java -jar openapi-generator-cli.jar generate -i "https://example.com/swagger/v1/swagger.json" -o "C:\Source\Project\src\api" -g typescript-fetch -D withInterfaces=true

Steps to reproduce

Linting/Transpile error when trying to build generated api.ts file (even with //tslint:disable)

Related issues/PRs
Suggest a fix

Rename internal 'configuration' parameter to something a bit more specific and less likely to conflict with other api parameter names. Ex: tsFetchClientConfiguration or similar.

TypeScript Bug

All 6 comments

馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@macjohnny I don't know if thats the problem, I think the issue is that the variable defined in the BaseAPI conflicts with the parameter of the action.

https://github.com/OpenAPITools/openapi-generator/blob/2353d71d4b02be6dbabe25aac1a9e56eb3b812a2/modules/openapi-generator/src/main/resources/typescript-fetch/api.mustache#L47

I think its an issue in the template?

the issue in the template arises due to local variables with the same name. this can be prevented by adding configuration to the reserved words, leading to an automatic rewrite of the parameter variable name.

Would you like me to open a pull request with that add? What branch should I start with?

You can open a branch from master, make the changes, compile and check this actually resolves the issue.

Was this page helpful?
0 / 5 - 0 ratings