Does typescript-fetch support generating code without dependent libraries such as portable-fetch?
BaseAPI supports injecting fetch at runtime.
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-fetch/api.mustache#L49
However, as default, portable-fetch is used and import statement is exist. Therefore, regardless of whether portable-fetch is actually used or not at runtime, we have to install and load it.
I think it's better to use native fetch as deafult, and if developer wants using polyfill, inject it via APIFactory at runtime.
For people who want same feature, currently I'm bundling all TS files with webpack, so I can avoid installing portable-fetch by aliasing with dummy file.
// webpack.config.js
module.exports.resolve.alias['portable-fetch'] = path.resolve(__dirname, 'src/portable-fetch-dummy.ts');
portable-fetch-dummy.ts is empty file, and inject native fetch at runtime as follows:
const API = DefaultApiFactory(undefined, fetch);
@macjohnny Sorry, but your answer looks how to configure fetch API implementation at runtime. Even if it's configurable, as long as portable-fetch is used as default, we have to install and bundle it. Otherwise, error is occurred when it's loaded.
@Kiikurage would you like to implement a fix?
OK, I'll send PR in a few days!
Any updates on this?
Most helpful comment
OK, I'll send PR in a few days!