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
  • #8980
Closed
Open
Issue created Mar 16, 2021 by Administrator@rootContributor

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

Assignee
Assign to
Time tracking