OpenAPITools / OpenAPITools/openapi-generator
[BUG] typescript-fetch openapi generator fails out-of-the-box
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
I added this to my package.json:
"@openapitools/openapi-generator-cli": "^2.3.10",
and when I run this command:
"generate:api": "(rm -rf src/api/gen || rmdir src/api/gen /s /q) && openapi-generator-cli generate -g typescript-fetch --additional-properties=supportsES6=true,typescriptThreePlus=true -i ../openapi/schema.yaml -o ./src/api/gen"
I get the following error:
Failed to compile.
/##/runtime.ts
TypeScript error in /###/runtime.ts(152,3):
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>'. TS2322
150 |
151 | get fetchApi(): FetchAPI {
> 152 | return this.configuration.fetchApi;
| ^
153 | }
154 |
155 | get middleware(): Middleware[] {
When I add "as FetchAPI" to line 152, everything works correctly. I have no idea where the problem is. Why does it generate code with this error?
openapi-generator version
2.3.10
OpenAPI declaration file content or url
N/A
Generation Details
N/A
Steps to reproduce
N/A
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/10164
https://github.com/OpenAPITools/openapi-generator/pull/10216 - supposedly it was fixed but it's still an issue when using version 2.3.10
Suggest a fix
Not sure about the fix. I quickly worked around it by casting it "as FetchAPI" which is not a good solution:
150 |
151 | get fetchApi(): FetchAPI {
152 | return this.configuration.fetchApi as FetchAPI;
|
153 | }
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 by reproducing the package.json command with @openapitools/openapi-generator-cli 2.3.10 and inspect the generated runtime.ts at line 152. Compare the failure with related issue 10164 and PR 10216; done means typescript-fetch output compiles without a manual FetchAPI cast.
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
- 35/100