Skip to content

[typescript-angular] Bug - Parameters named "responseType" cause conflict. #5853

@SandroBuerki

Description

@SandroBuerki
Description

If you name a parameter responseType (or response_type etc.) the generated client method signature expects a parameter called responseType. However, the generated code of such method declares a variable responseType, which causes the compiler to throw the error message Duplicate identifier 'responseType'.

Method signature:
public authorize(responseType?: 'code', state?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined}): Observable<any> {

Variable declaration:
let responseType: 'text' | 'json' = 'json';

openapi-generator version

v4.3.0 - It jused to work with v4.2.3

OpenAPI declaration file content or url

###swagger.json

{
  "swagger": "2.0",
  "info": {
    "title": "Example swagger",
    "description": "Example description",
    "version": "1.0.0"
  },
  "paths": {
    "\/oauth\/auth": {
      "get": {
        "operationId": "authorize",
        "parameters": [
          {
            "name": "response_type",
            "in": "query",
            "type": "string",
            "enum": [
              "code"
            ]
          }
        ],
        "responses": {
          "302": {
            "description": "Redirection to Authentication flow or straight to the redirect_uri if the authentication has been completed before"
          }
        }
      }
    }
  }
}
Command line used for generation

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate
-i /local/swagger.json
-g typescript-angular
-o /local/out
--additional-properties modelPropertyNaming=original,ngVersion=9.0.0,npmVersion=1.0.0,npmName=@package/scope,npmRepository=https://gitlab.com/api/v4/projects/123/packages/npm/

Steps to reproduce
  • Create a swagger.json with the content as shown above
  • Execute the command as shown above
  • See the method signature of authenticate() generated in out/api/oAuth.service.ts
Related issues/PRs

No similar issues, but the PR which changed the behavior. It swapped the logic of toVarName() and toParamName(): #5427

Suggest a fix/enhancement

With 4.2.3, the method parameter kept its case. Due to a change in 4.3.0, all parameters are now camelized. I could probably fix the code myself, and I'm willing to open a PR. I'm just not sure what you guys think the best way would be:

  • Should modelPropertyNaming affect the parameter name?
  • Should I add responseType as a reserved word?
  • Should I just rename the responseType variable inside the generated function?
  • Or am I completely wrong and something else is needed?

Best regards, and thanks a lot in advance.

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