swagger-api / swagger-api/swagger-codegen
Typescript-fetch: Invalid import of isomorphic-fetch causing TypeError
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Hello, I've encountered an issue with generated code for typescript-fetch. The generated api.ts file contains import of portable-fetch which isn't correct:
import * as portableFetch from "portable-fetch";
When fixed to
import portableFetch from "portable-fetch";
the code works as expected.
Swagger-codegen version
2.4.12
Command line used for generation
swagger-codegen generate -i swagger.yaml -l typescript-fetch -o src/shared/apiClient/
Steps to reproduce
- Generate code with codegen for typescript-fetch.
- Try to use API using the generated code.
You'll always get:
TypeError: fetch is not a function
Suggest a fix/enhancement
I've found this code is generated from moustache template here. I can create pull request and fix it, however, I'm not sure if I'm missing something and the code should work under other circumstances as it's there for very long time without a fix. Please advise, thanks!
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/swagger-codegen/src/main/resources/typescript-fetch/api.mustache and inspect the generated api.ts import. Reproduce the issue with the provided swagger-codegen command, then verify that generated typescript-fetch code can call the API without the reported “fetch is not a function” TypeError.
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
- 38/100