OpenAPITools / OpenAPITools/openapi-generator
[BUG] typescript-fetch produces types with unused imports and arguments
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When we create types through the openapi-generator-cli, the generated TypeScript files contains some unused imports and arguments. Among these are import { mapValues } from '../runtime'; at the top of each file, and ignoreDiscriminator as an unused argument to each ...FromJSONTyped function.
These unused imports and arguments become an issue when we try to build our app and do type checking through tsc. Since these files are imported throughout our app to use the types, there is no way to exclude them from type checking externally.
Is there any way to prevent the type generator to generate files with unused imports and arguments, or could the generated files perhaps be annotated with // @ts-nocheck at the top of the file to exclude them from the tsc type checker?
openapi-generator version
2.17.0
Suggest a fix
The issue can be fixed if the generated output-files could be annotated with // @ts-nocheck at the top of each file.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript-fetch generator and inspect its generated TypeScript files, especially the ../runtime mapValues import and ...FromJSONTyped functions. Reproduce generation with openapi-generator-cli version 2.17.0, then run tsc against the generated output. Done means the generated files no longer trigger unused-import or unused-argument errors, or are consistently excluded as specified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100