openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] typescript-fetch code does not compile because of Errors

Open mknj opened this issue 3 years ago • 13 comments

Bug Report Checklist

  • [X] ALL Specs Have you provided a full/minimal spec to reproduce the issue?
  • [X] All Specs Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [X] Have you searched for related issues/PRs?
  • [X] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

typescript-fetch code does not compile because of Errors

openapi-generator version
"@openapitools/openapi-generator-cli": "^1.0.18-4.3.1",

and "@openapitools/openapi-generator-cli": "^1.0.18-5.0.0-beta2",

"typescript": "^4.2.3",
OpenAPI declaration file content or url

any file

Generation Details

There are many bugs like

Error TS6133: 'InlineResponse2003ToJSON' is declared but its value is never read.
Steps to reproduce
openapi-generator generate -i openapi.yaml -g typescript-fetch -o ui/src/generated
tsc ui/src/generated/runtime.ts
Related issues/PRs
Suggest a fix

replace /* tslint:disable */ by // @ts-nocheck or add extra ts-nocheck line

diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache
index 8466deb2853..3781155fd63 100644
--- a/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache
+++ b/modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache
@@ -1,3 +1,4 @@
+// @ts-nocheck
 /* tslint:disable */
 /* eslint-disable */
 {{>licenseInfo}}
diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/models.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/models.mustache
index 20135a84425..e8c7db348c3 100644
--- a/modules/openapi-generator/src/main/resources/typescript-fetch/models.mustache
+++ b/modules/openapi-generator/src/main/resources/typescript-fetch/models.mustache
@@ -1,3 +1,4 @@
+// @ts-nocheck
 /* tslint:disable */
 /* eslint-disable */
 {{>licenseInfo}}
diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache
index d0c29b93a75..ff219a869e5 100644
--- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache
+++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache
@@ -1,3 +1,4 @@
+// @ts-nocheck
 /* tslint:disable */
 /* eslint-disable */
 {{>licenseInfo}}

mknj avatar Mar 12 '21 15:03 mknj

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

auto-labeler[bot] avatar Mar 12 '21 15:03 auto-labeler[bot]

Anyone have a suggested workaround to this?

jmroon avatar Oct 29 '21 15:10 jmroon

add // @ts-nocheck to the generated files

mknj avatar Nov 06 '21 16:11 mknj

add // @ts-nocheck to the generated files

This is what we use atm, e.g.

SED_COMMAND='1s;^;// @ts-nocheck\n;'
if [ "$(uname)" != "Darwin" ]; then
  sed -i "$SED_COMMAND" $TARGET**/*.ts
else
  sed -i '' "$SED_COMMAND" $TARGET**/*.ts
fi

Poitrin avatar Dec 02 '21 15:12 Poitrin

I think adding ts-nocheck is a bit harsh as TypeScript is supposed to add some sort of type safety.

Unfortunately TypeScript does not give us the opportunity to ignore specific errors on class level nor blacklist files during type check.

So I think adding the nocheck option to every generated file should be the solution, too.

sdoeringNew avatar Feb 12 '22 06:02 sdoeringNew

So I think adding the nocheck option to every generated file should be the solution, too.

I stand corrected! If I'm looking at the typescript-axios generator the TypeScript compilation works fine without errors and without // @ts-nocheck. So I added a pull request that is doing the same thing as typescript-axios already does. And this is to add // @ts-ignore before the lines there the current compilation errors appear or might appear.

With this change my projects compiled without errors.

Perhaps you'll have a look for yourself and checkout the latest PR.

sdoeringNew avatar Feb 21 '22 01:02 sdoeringNew

Do you plan to merge this solution soon?

FilipKrawiec avatar Mar 07 '22 09:03 FilipKrawiec

bump

Time to merge? It's the same solution like typescript-axios already has. So it can't be bad for typescript-axios.

sdoeringNew avatar Apr 26 '22 22:04 sdoeringNew

What is taking so long? Merge it already. It's the same solution as done in typescript-axios.

sdoeringNew avatar Sep 02 '22 13:09 sdoeringNew

Currently the generator for typescript-fetch is broken for any spec. Nobody with a standard tsconfig can use it without post applying some work around. A possible solution was provided in the error report.

@sdoeringNew, Thanks for https://github.com/OpenAPITools/openapi-generator/pull/11674. Would it be possible to resolve the merge conflicts and fix the failed "ci/circleci: node2" test?

mknj avatar Sep 05 '22 10:09 mknj

Is there any progress on this? I am waiting for this fix :)

joellp avatar Sep 15 '23 08:09 joellp

Also have run into this issue and curios about status on this

johanbook avatar Oct 12 '23 09:10 johanbook

Is this dead? Hoping it's not.

fidesachates avatar Feb 16 '24 02:02 fidesachates