From bf2932d41cd4b8d926e0f656c006d640bb2e573f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Sat, 24 Nov 2018 17:04:59 +0800 Subject: [PATCH] fix array of enum class in JS (#1484) --- .../src/main/resources/Javascript/ApiClient.mustache | 4 ++-- .../src/main/resources/Javascript/es6/ApiClient.mustache | 4 ++-- samples/client/petstore/javascript-es6/src/ApiClient.js | 4 ++-- .../client/petstore/javascript-promise-es6/src/ApiClient.js | 4 ++-- samples/client/petstore/javascript-promise/src/ApiClient.js | 4 ++-- samples/client/petstore/javascript/src/ApiClient.js | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache index b6bbc47374..c0c692fc5b 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Javascript/ApiClient.mustache @@ -546,8 +546,8 @@ if (type === Object) { // generic object, return directly return data; - } else if (typeof type === 'function') { - // for model type like: User + } else if (typeof type.constructFromObject === 'function') { + // for model type like User or enum class return type.constructFromObject(data); } else if (Array.isArray(type)) { // for array type like: ['String'] diff --git a/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache index 49b92e21ca..694013f142 100644 --- a/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Javascript/es6/ApiClient.mustache @@ -502,8 +502,8 @@ class ApiClient { if (type === Object) { // generic object, return directly return data; - } else if (typeof type === 'function') { - // for model type like: User + } else if (typeof type.constructFromObject === 'function') { + // for model type like User and enum class return type.constructFromObject(data); } else if (Array.isArray(type)) { // for array type like: ['String'] diff --git a/samples/client/petstore/javascript-es6/src/ApiClient.js b/samples/client/petstore/javascript-es6/src/ApiClient.js index 369632309d..50bdc61113 100644 --- a/samples/client/petstore/javascript-es6/src/ApiClient.js +++ b/samples/client/petstore/javascript-es6/src/ApiClient.js @@ -486,8 +486,8 @@ class ApiClient { if (type === Object) { // generic object, return directly return data; - } else if (typeof type === 'function') { - // for model type like: User + } else if (typeof type.constructFromObject === 'function') { + // for model type like User and enum class return type.constructFromObject(data); } else if (Array.isArray(type)) { // for array type like: ['String'] diff --git a/samples/client/petstore/javascript-promise-es6/src/ApiClient.js b/samples/client/petstore/javascript-promise-es6/src/ApiClient.js index 2b2d43810c..50ef10e264 100644 --- a/samples/client/petstore/javascript-promise-es6/src/ApiClient.js +++ b/samples/client/petstore/javascript-promise-es6/src/ApiClient.js @@ -478,8 +478,8 @@ class ApiClient { if (type === Object) { // generic object, return directly return data; - } else if (typeof type === 'function') { - // for model type like: User + } else if (typeof type.constructFromObject === 'function') { + // for model type like User and enum class return type.constructFromObject(data); } else if (Array.isArray(type)) { // for array type like: ['String'] diff --git a/samples/client/petstore/javascript-promise/src/ApiClient.js b/samples/client/petstore/javascript-promise/src/ApiClient.js index 0415153dac..883b148d5a 100644 --- a/samples/client/petstore/javascript-promise/src/ApiClient.js +++ b/samples/client/petstore/javascript-promise/src/ApiClient.js @@ -525,8 +525,8 @@ if (type === Object) { // generic object, return directly return data; - } else if (typeof type === 'function') { - // for model type like: User + } else if (typeof type.constructFromObject === 'function') { + // for model type like User or enum class return type.constructFromObject(data); } else if (Array.isArray(type)) { // for array type like: ['String'] diff --git a/samples/client/petstore/javascript/src/ApiClient.js b/samples/client/petstore/javascript/src/ApiClient.js index 07b9ab030e..4e33f192e4 100644 --- a/samples/client/petstore/javascript/src/ApiClient.js +++ b/samples/client/petstore/javascript/src/ApiClient.js @@ -536,8 +536,8 @@ if (type === Object) { // generic object, return directly return data; - } else if (typeof type === 'function') { - // for model type like: User + } else if (typeof type.constructFromObject === 'function') { + // for model type like User or enum class return type.constructFromObject(data); } else if (Array.isArray(type)) { // for array type like: ['String']