From d524e20754ef18ebcb5aba6bdd7549c6076b1db8 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Fri, 27 Jan 2017 16:49:50 +0200 Subject: [PATCH] [JavaScript] Fixed handling of empty arrays/empty strings/booleans/single numbers as valid API responses (#4653) --- .../src/main/resources/Javascript/ApiClient.mustache | 2 +- samples/client/petstore/javascript-promise/src/ApiClient.js | 2 +- samples/client/petstore/javascript/src/ApiClient.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache index 934201a0404..d85705f5127 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/ApiClient.mustache @@ -317,7 +317,7 @@ // Rely on SuperAgent for parsing response body. // See http://visionmedia.github.io/superagent/#parsing-response-bodies var data = response.body; - if (data == null || !Object.keys(data).length) { + if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) { // SuperAgent does not always produce a body; use the unparsed response as a fallback data = response.text; } diff --git a/samples/client/petstore/javascript-promise/src/ApiClient.js b/samples/client/petstore/javascript-promise/src/ApiClient.js index 433f6b1a445..3f735978306 100644 --- a/samples/client/petstore/javascript-promise/src/ApiClient.js +++ b/samples/client/petstore/javascript-promise/src/ApiClient.js @@ -320,7 +320,7 @@ // Rely on SuperAgent for parsing response body. // See http://visionmedia.github.io/superagent/#parsing-response-bodies var data = response.body; - if (data == null || !Object.keys(data).length) { + if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) { // SuperAgent does not always produce a body; use the unparsed response as a fallback data = response.text; } diff --git a/samples/client/petstore/javascript/src/ApiClient.js b/samples/client/petstore/javascript/src/ApiClient.js index 96fccb169e1..6d150160192 100644 --- a/samples/client/petstore/javascript/src/ApiClient.js +++ b/samples/client/petstore/javascript/src/ApiClient.js @@ -320,7 +320,7 @@ // Rely on SuperAgent for parsing response body. // See http://visionmedia.github.io/superagent/#parsing-response-bodies var data = response.body; - if (data == null || !Object.keys(data).length) { + if (data == null || (typeof data === 'object' && typeof data.length === 'undefined' && !Object.keys(data).length)) { // SuperAgent does not always produce a body; use the unparsed response as a fallback data = response.text; }