From 5d05cc0e66a6420cca145475b385e1a00fb029bb Mon Sep 17 00:00:00 2001 From: Andy Bao Date: Tue, 26 Mar 2019 06:23:23 -0400 Subject: [PATCH] Fix body serialization in javascript-flowtyped generator when body is falsy (#2499) --- .../resources/Javascript-Flowtyped/api.mustache | 2 +- .../petstore/javascript-flowtyped/src/api.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache b/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache index 0d5bfc94e42..989b8b40d63 100644 --- a/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache +++ b/modules/openapi-generator/src/main/resources/Javascript-Flowtyped/api.mustache @@ -214,7 +214,7 @@ export const {{classname}}FetchParamCreator = function (configuration?: Configur {{/hasFormParams}} {{#bodyParam}} const needsSerialization = (typeof {{paramName}} !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify({{paramName}} || {}) : ((({{paramName}}:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify({{paramName}} != null ? {{paramName}} : {}) : ((({{paramName}}:any):string) || ""); {{/bodyParam}} return { diff --git a/samples/client/petstore/javascript-flowtyped/src/api.js b/samples/client/petstore/javascript-flowtyped/src/api.js index cd921bbc237..a651816178b 100644 --- a/samples/client/petstore/javascript-flowtyped/src/api.js +++ b/samples/client/petstore/javascript-flowtyped/src/api.js @@ -323,7 +323,7 @@ export const PetApiFetchParamCreator = function (configuration?: Configuration) delete localVarUrlObj.search; localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}) : (((body:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify(body != null ? body : {}) : (((body:any):string) || ""); return { url: url.format(localVarUrlObj), @@ -515,7 +515,7 @@ export const PetApiFetchParamCreator = function (configuration?: Configuration) delete localVarUrlObj.search; localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}) : (((body:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify(body != null ? body : {}) : (((body:any):string) || ""); return { url: url.format(localVarUrlObj), @@ -878,7 +878,7 @@ export const StoreApiFetchParamCreator = function (configuration?: Configuration delete localVarUrlObj.search; localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}) : (((body:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify(body != null ? body : {}) : (((body:any):string) || ""); return { url: url.format(localVarUrlObj), @@ -997,7 +997,7 @@ export const UserApiFetchParamCreator = function (configuration?: Configuration) delete localVarUrlObj.search; localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}) : (((body:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify(body != null ? body : {}) : (((body:any):string) || ""); return { url: url.format(localVarUrlObj), @@ -1027,7 +1027,7 @@ export const UserApiFetchParamCreator = function (configuration?: Configuration) delete localVarUrlObj.search; localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}) : (((body:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify(body != null ? body : {}) : (((body:any):string) || ""); return { url: url.format(localVarUrlObj), @@ -1057,7 +1057,7 @@ export const UserApiFetchParamCreator = function (configuration?: Configuration) delete localVarUrlObj.search; localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}) : (((body:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify(body != null ? body : {}) : (((body:any):string) || ""); return { url: url.format(localVarUrlObj), @@ -1206,7 +1206,7 @@ export const UserApiFetchParamCreator = function (configuration?: Configuration) delete localVarUrlObj.search; localVarRequestOptions.headers = Object.assign({}, localVarHeaderParameter, options.headers); const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json'; - localVarRequestOptions.body = needsSerialization ? JSON.stringify(body || {}) : (((body:any):string) || ""); + localVarRequestOptions.body = needsSerialization ? JSON.stringify(body != null ? body : {}) : (((body:any):string) || ""); return { url: url.format(localVarUrlObj),