Openapi-generator: Generate typescript-fetch code without portable-fetch

Created on 4 Nov 2018  路  6Comments  路  Source: OpenAPITools/openapi-generator

Description

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.

Suggest a fix/enhancement

I think it's better to use native fetch as deafult, and if developer wants using polyfill, inject it via APIFactory at runtime.

Most helpful comment

OK, I'll send PR in a few days!

All 6 comments

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?

Was this page helpful?
0 / 5 - 0 ratings