OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-fetch] Compilation failure in typescript build
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
The typescript-fetch client fails to compile.
Compilation failure:
src/ext/runtime.ts:152:9 - error TS2322: Type '((input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>) | undefined' is not assignable to type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.
Type 'undefined' is not assignable to type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.
152 return this.configuration.fetchApi;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
openapi-generator version
Version: v5.2.1
Regression: Yes
Generation Details
CLI used:
docker run -v "${PWD}:/local" openapitools/openapi-generator-cli:v5.2.1 generate -i /local/<specfile> -g typescript-fetch
Steps to reproduce
See above
Related issues/PRs
This was introduced in: https://github.com/OpenAPITools/openapi-generator/commit/c05ec99182c80993a218a841853ba6412e6a6c16
This causes an error because this config value may be undefined:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache#L122
Suggest a fix
The fallback as seen here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache#L122
Could be added to the getter.
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 modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache at the referenced getter and compare it with the fallback already used at line 122. Generate a typescript-fetch client with the v5.2.1 Docker command, run its TypeScript build, and confirm compilation succeeds without the TS2322 error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100