From 6f9d8259b03eb8cead511c5d75af2144a58446f8 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Tue, 28 Apr 2020 15:21:53 +0200 Subject: [PATCH] [typescript-fetch] Make FormData optional (#6077) Check "typeof FormData" first. This allows the code to also work in nodejs with isomorphic-fetch. --- .../src/main/resources/typescript-fetch/runtime.mustache | 2 +- .../client/petstore/typescript-fetch/builds/default/runtime.ts | 2 +- .../petstore/typescript-fetch/builds/es6-target/src/runtime.ts | 2 +- .../typescript-fetch/builds/multiple-parameters/runtime.ts | 2 +- .../builds/prefix-parameter-interfaces/src/runtime.ts | 2 +- .../builds/typescript-three-plus/src/runtime.ts | 2 +- .../petstore/typescript-fetch/builds/with-interfaces/runtime.ts | 2 +- .../typescript-fetch/builds/with-npm-version/src/runtime.ts | 2 +- 8 files changed, 8 insertions(+), 8 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 ee1ee65cc39..767a3488080 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -50,7 +50,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body); diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 649e1750424..747ca17e206 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -61,7 +61,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body); 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 649e1750424..747ca17e206 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 @@ -61,7 +61,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body); 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 649e1750424..747ca17e206 100644 --- a/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/multiple-parameters/runtime.ts @@ -61,7 +61,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body); 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 649e1750424..747ca17e206 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 @@ -61,7 +61,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body); 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 b6e6a7744d7..8fae3715d1b 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 @@ -61,7 +61,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body); 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 649e1750424..747ca17e206 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -61,7 +61,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body); 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 649e1750424..747ca17e206 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 @@ -61,7 +61,7 @@ export class BaseAPI { // do not handle correctly sometimes. url += '?' + this.configuration.queryParamsStringify(context.query); } - const body = (context.body instanceof FormData || context.body instanceof URLSearchParams || isBlob(context.body)) + const body = ((typeof FormData !== "undefined" && context.body instanceof FormData) || context.body instanceof URLSearchParams || isBlob(context.body)) ? context.body : JSON.stringify(context.body);