[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).