[BUG] typescript-fetch openapi generator fails out-of-the-box
See original GitHub issueBug 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 | }
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:7
Top GitHub Comments
I am seeing the same issue with generator-cli v5.2.1
On v5.1.1 the generated code is (runtime.ts):
On v5.2.1 the generated code is (runtime.ts):
Possibly related to changes from #10050?
We have been using generated api for a few months and now are trying to move to TS strict mode. But it seems that the generated
runtime.ts
files have inherent strict-failing lines; for instance:There are a total of 12 errors in each
runtime.ts
file failing thestrictNullChecks
strict clause. Run with version 6.2.0 andtypescript-fetch
.I hope this thread is still being looked at.