OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
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.
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:
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
npm i
andnpm run openapi:generate
npm run build
to start a Angular build that errorsRelated 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.