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][typescript-angular] Configuration template generates code that fails strict type checking #8980

Closed
Toeler opened this issue Mar 16, 2021 · 1 comment · Fixed by #9260

Comments

@Toeler
Copy link

Toeler commented Mar 16, 2021

Description

The code generated by the typescript-angular template results in code that fails the strictNullChecks compiler option for Typescript

openapi-generator version

5.0.1 - issue added in 5.0.0 via #6953

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: '1.0'
  title: Example API
paths:
  /securitySchemeA:
    get:
      responses:
        default:
          description: successful operation
components:
  securitySchemes:
    ExampleA:
      type: apiKey
      name: Authorization
      in: header
Command line used for generation

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

Steps to reproduce

Use the spec file and command provided above to generate a client.
Then run the command npx tsc configuration.ts --lib esnext --strictNullChecks.
Ignore the error Cannot find module '@angular/common/http'.
Observe two errors stating Object is possibly 'undefined'

Related issues/PRs

Not that I can see

Suggest a fix/enhancement

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-angular/configuration.mustache#L67
The code could be changed to use Optional Chaining (?.) to access the keys on this.apiKeys, since apiKeys is nullable. e.g. this.apiKeys?.['{{name}}']
Alternatively, it could simply check for the truthiness of apiKeys before accessing it.

@auto-labeler
Copy link

auto-labeler bot commented Mar 16, 2021

👍 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.

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