From c05ec99182c80993a218a841853ba6412e6a6c16 Mon Sep 17 00:00:00 2001 From: duxiaofeng Date: Fri, 6 Aug 2021 14:59:40 +0800 Subject: [PATCH] make typescript-fetch code compatiable with nodejs environment (#10072) --- .../src/main/resources/typescript-fetch/runtime.mustache | 4 ++-- .../petstore/typescript-fetch/builds/default-v3.0/runtime.ts | 4 ++-- .../petstore/typescript-fetch/builds/default/runtime.ts | 4 ++-- .../client/petstore/typescript-fetch/builds/enum/runtime.ts | 4 ++-- .../typescript-fetch/builds/es6-target/src/runtime.ts | 4 ++-- .../typescript-fetch/builds/multiple-parameters/runtime.ts | 4 ++-- .../builds/prefix-parameter-interfaces/src/runtime.ts | 4 ++-- .../typescript-fetch/builds/sagas-and-records/src/runtime.ts | 4 ++-- .../builds/typescript-three-plus/src/runtime.ts | 4 ++-- .../typescript-fetch/builds/with-interfaces/runtime.ts | 4 ++-- .../typescript-fetch/builds/with-npm-version/src/runtime.ts | 4 ++-- .../builds/without-runtime-checks/src/runtime.ts | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) 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 8df16e9074e..3532836aba0 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -74,7 +74,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -137,7 +137,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts index 6924269e546..4954bd81789 100644 --- a/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default-v3.0/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 8ae5f65348c..164ebaaaea8 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts index c4d82bccb8f..fceb79bf4c4 100644 --- a/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/enum/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts index 8ae5f65348c..164ebaaaea8 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/src/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts index 8ae5f65348c..164ebaaaea8 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts index 8ae5f65348c..164ebaaaea8 100644 --- a/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/prefix-parameter-interfaces/src/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts index 40ac35e9d19..ccfe56260d8 100644 --- a/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/sagas-and-records/src/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts index 40ac35e9d19..ccfe56260d8 100644 --- a/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/typescript-three-plus/src/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index 8ae5f65348c..164ebaaaea8 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts index 8ae5f65348c..164ebaaaea8 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/src/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] { diff --git a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts index 8ae5f65348c..164ebaaaea8 100644 --- a/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/without-runtime-checks/src/runtime.ts @@ -85,7 +85,7 @@ export class BaseAPI { }) || fetchParams; } } - let response = await this.configuration.fetchApi(fetchParams.url, fetchParams.init); + let response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ @@ -148,7 +148,7 @@ export class Configuration { } get fetchApi(): FetchAPI { - return this.configuration.fetchApi || window.fetch.bind(window); + return this.configuration.fetchApi; } get middleware(): Middleware[] {