OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.94k stars 6.59k forks source link

[BUG][typescript-angular] Unused imports are generated that cause TS errors with "noUnusedLocals" enabled #20134

Open jase88 opened 3 days ago

jase88 commented 3 days ago

Bug Report Checklist

Description

If you use typescript-angular the generated code might contain imports that are unused.

If the tsconfig configuration noUnusedLocals is enabled and you directly consume generated OpenAPI code within an Angular application, the TypeScript compiler errors:

✘ [ERROR] TS6133: 'FooDto' is declared but its value is never read. [plugin angular-compiler]

In my repo this occurs on model files with discriminators.

openapi-generator version

7.10.0

OpenAPI declaration file content or url

see https://github.com/jase88/openapi-ts-ng-unused-locals/blob/main/api-definition.openapi.yaml

Generation Details

MacOS 15.1 openjdk 23.0.1 2024-10-15 Node v22.8.0

Steps to reproduce
Related issues/PRs
Suggest a fix

Ideally, it can be determined during generation that the import is not required in the file and can be discarded.

Alternatively, you could add @ts-check to every import, but in my opinion this should be a last resort.