Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6223
Closed
Open
Issue created May 08, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG][Typescript-Node] Duplicate 'accessToken' setters for oauth2 and bearer

Created by: sinaa

Bug Report Checklist

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

When both Oauth2 and Token are described in the security requirements of an endpoint, the Typescript-Node version generates both as set accessToken() methods that result in duplicate identifier exception from typescript.

openapi-generator version

4.3.1

OpenAPI declaration file content or url

If you have:

/api/endpoint/{id}:
    put:
      tags:
      - Endpoint
      summary: Some description
      operationId: doFoo
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
          format: int32
      responses:
        default:
          description: default response
          content:
            application/json: {}
      security:
      - token: []
      - oauth2:
        - write:foo

Then you get the following in the generated API:

    set accessToken(token: string) {
        this.authentications.oauth2.accessToken = token;
    }

    set accessToken(accessToken: string | (() => string)) {
        this.authentications.token.accessToken = accessToken;
    }

which is not valid.


This is due to

{{#isBasicBearer}}

    set accessToken(accessToken: string | (() => string)) {
        this.authentications.{{name}}.accessToken = accessToken;
    }
{{/isBasicBearer}}
{{#isOAuth}}

    set accessToken(token: string) {
        this.authentications.{{name}}.accessToken = token;
    }
{{/isOAuth}}

In modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache.

Note that this is not possible to have both in the same TS class.

Command line used for generation
openapi-generator generate -i api.yaml -g typescript-node -o src/generated/ --additional-properties=supportsES6=true
Suggest a fix

Set distinct names for oauth and token setters. E.g., accessToken and accessTokenOauth.

An alternative would be to just allow favouring one over the other (e.g., always bearer, or always oauth).

Assignee
Assign to
Time tracking