Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Angular-typescript generator generates invalid code #9259

Closed
EmmanuelRoux opened this issue Apr 14, 2021 · 0 comments · Fixed by #9260
Closed

[BUG] Angular-typescript generator generates invalid code #9259

EmmanuelRoux opened this issue Apr 14, 2021 · 0 comments · Fixed by #9260

Comments

@EmmanuelRoux
Copy link
Contributor

Description

Using angular-typescript generator leads to invalid code throwing following error at runtime :
ERROR TypeError: Cannot read property 'apiKey' of undefined

Looking at generated source code, see Configuration class in configuration.ts does not correctly handle undefined config parameters :

    constructor(configurationParameters: ConfigurationParameters = {}) {
        this.apiKeys = configurationParameters.apiKeys; // <-- THIS MAY BE UNDEFINED
        // [...] 
        if (configurationParameters.credentials) {
            this.credentials = configurationParameters.credentials;
        }
        else {
            this.credentials = {};
        }

        // init default apiKey credential
        if (!this.credentials['apiKey']) {
            this.credentials['apiKey'] = () => {
                return this.apiKeys['apiKey'] || this.apiKeys['apiKey']; // <-- THIS IS THROWING THE ERROR
            };
        }
    }
openapi-generator version

Version 5.1.0

(npm package @openapitools/openapi-generator-cli version 2.2.5)

OpenAPI declaration file content or url
# api.yml
openapi: 3.0.0
info:
  version: '1.0'
  title: Example API
security:
  - oauthSecurity: []
  - apiKey: []
paths:
  /endpointX:
    get:
      responses:
        default:
          description: successful operation
components:
  securitySchemes:
    apiKey:
      type: apiKey
      description: API Key
      name: apiKey
      in: header
Generation Details

openapi-generator-cli generate -g typescript-angular -i api.yml

Related issues/PRs

This problem also lead to compilation errors when using strict type checking, as described in #8980 and #8983.

Suggest a fix

The fix suggested in #8980 may work

EmmanuelRoux added a commit to EmmanuelRoux/openapi-generator that referenced this issue Apr 15, 2021
macjohnny pushed a commit that referenced this issue Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant