[BUG][typescript-angular] Configuration template generates code that fails strict type checking
Created by: Toeler
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.