From 86154f87c34b761d88c63cd71346a1e382bfd1f5 Mon Sep 17 00:00:00 2001 From: delenius Date: Thu, 11 Feb 2016 09:02:45 -0800 Subject: [PATCH] Use objects for enums, not constructor functions Fixes #2101. --- .../src/main/resources/Javascript/enumClass.mustache | 8 +++----- .../javascript-promise/src/model/Category.js | 2 ++ .../petstore/javascript-promise/src/model/Order.js | 12 ++++++------ .../petstore/javascript-promise/src/model/Pet.js | 12 ++++++------ .../petstore/javascript-promise/src/model/Tag.js | 2 ++ .../petstore/javascript-promise/src/model/User.js | 2 ++ .../client/petstore/javascript/src/model/Category.js | 2 ++ .../client/petstore/javascript/src/model/Order.js | 12 ++++++------ samples/client/petstore/javascript/src/model/Pet.js | 12 ++++++------ samples/client/petstore/javascript/src/model/Tag.js | 2 ++ samples/client/petstore/javascript/src/model/User.js | 2 ++ 11 files changed, 39 insertions(+), 29 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Javascript/enumClass.mustache b/modules/swagger-codegen/src/main/resources/Javascript/enumClass.mustache index aa7d8bf50fd..341c55ca977 100644 --- a/modules/swagger-codegen/src/main/resources/Javascript/enumClass.mustache +++ b/modules/swagger-codegen/src/main/resources/Javascript/enumClass.mustache @@ -6,14 +6,12 @@ if ( typeof define === "function" && define.amd ) { }); } -var {{datatypeWithEnum}} = function {{datatypeWithEnum}}() { - var self = this; - +var {{datatypeWithEnum}} = { {{#allowableValues}}{{#enumVars}} /** * @const */ - self.{{name}} = "{{value}}"{{^-last}}, - {{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} + {{name}}: "{{value}}"{{^-last}}, + {{/-last}}{{/enumVars}}{{/allowableValues}} } diff --git a/samples/client/petstore/javascript-promise/src/model/Category.js b/samples/client/petstore/javascript-promise/src/model/Category.js index 26742d7036b..61d1b9b8f61 100644 --- a/samples/client/petstore/javascript-promise/src/model/Category.js +++ b/samples/client/petstore/javascript-promise/src/model/Category.js @@ -50,6 +50,7 @@ } + /** * @return {Integer} **/ @@ -78,6 +79,7 @@ this['name'] = name; } + Category.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript-promise/src/model/Order.js b/samples/client/petstore/javascript-promise/src/model/Order.js index 0d5b90d319a..ef318c61b8a 100644 --- a/samples/client/petstore/javascript-promise/src/model/Order.js +++ b/samples/client/petstore/javascript-promise/src/model/Order.js @@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) { }); } -var StatusEnum = function StatusEnum() { - var self = this; - +var StatusEnum = { /** * @const */ - self.PLACED = "placed", + PLACED: "placed", /** * @const */ - self.APPROVED = "approved", + APPROVED: "approved", /** * @const */ - self.DELIVERED = "delivered"; + DELIVERED: "delivered" } @@ -115,6 +113,7 @@ var StatusEnum = function StatusEnum() { } + /** * @return {Integer} **/ @@ -201,6 +200,7 @@ var StatusEnum = function StatusEnum() { this['complete'] = complete; } + Order.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript-promise/src/model/Pet.js b/samples/client/petstore/javascript-promise/src/model/Pet.js index 67bacb19390..78484070859 100644 --- a/samples/client/petstore/javascript-promise/src/model/Pet.js +++ b/samples/client/petstore/javascript-promise/src/model/Pet.js @@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) { }); } -var StatusEnum = function StatusEnum() { - var self = this; - +var StatusEnum = { /** * @const */ - self.AVAILABLE = "available", + AVAILABLE: "available", /** * @const */ - self.PENDING = "pending", + PENDING: "pending", /** * @const */ - self.SOLD = "sold"; + SOLD: "sold" } @@ -117,6 +115,7 @@ var StatusEnum = function StatusEnum() { } + /** * @return {Integer} **/ @@ -203,6 +202,7 @@ var StatusEnum = function StatusEnum() { this['status'] = status; } + Pet.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript-promise/src/model/Tag.js b/samples/client/petstore/javascript-promise/src/model/Tag.js index 563c1ee9df8..ab1497a0796 100644 --- a/samples/client/petstore/javascript-promise/src/model/Tag.js +++ b/samples/client/petstore/javascript-promise/src/model/Tag.js @@ -50,6 +50,7 @@ } + /** * @return {Integer} **/ @@ -78,6 +79,7 @@ this['name'] = name; } + Tag.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript-promise/src/model/User.js b/samples/client/petstore/javascript-promise/src/model/User.js index 67c45561d3c..bb8a8f99008 100644 --- a/samples/client/petstore/javascript-promise/src/model/User.js +++ b/samples/client/petstore/javascript-promise/src/model/User.js @@ -105,6 +105,7 @@ } + /** * @return {Integer} **/ @@ -219,6 +220,7 @@ this['userStatus'] = userStatus; } + User.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript/src/model/Category.js b/samples/client/petstore/javascript/src/model/Category.js index 26742d7036b..61d1b9b8f61 100644 --- a/samples/client/petstore/javascript/src/model/Category.js +++ b/samples/client/petstore/javascript/src/model/Category.js @@ -50,6 +50,7 @@ } + /** * @return {Integer} **/ @@ -78,6 +79,7 @@ this['name'] = name; } + Category.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript/src/model/Order.js b/samples/client/petstore/javascript/src/model/Order.js index 0d5b90d319a..ef318c61b8a 100644 --- a/samples/client/petstore/javascript/src/model/Order.js +++ b/samples/client/petstore/javascript/src/model/Order.js @@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) { }); } -var StatusEnum = function StatusEnum() { - var self = this; - +var StatusEnum = { /** * @const */ - self.PLACED = "placed", + PLACED: "placed", /** * @const */ - self.APPROVED = "approved", + APPROVED: "approved", /** * @const */ - self.DELIVERED = "delivered"; + DELIVERED: "delivered" } @@ -115,6 +113,7 @@ var StatusEnum = function StatusEnum() { } + /** * @return {Integer} **/ @@ -201,6 +200,7 @@ var StatusEnum = function StatusEnum() { this['complete'] = complete; } + Order.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript/src/model/Pet.js b/samples/client/petstore/javascript/src/model/Pet.js index 67bacb19390..78484070859 100644 --- a/samples/client/petstore/javascript/src/model/Pet.js +++ b/samples/client/petstore/javascript/src/model/Pet.js @@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) { }); } -var StatusEnum = function StatusEnum() { - var self = this; - +var StatusEnum = { /** * @const */ - self.AVAILABLE = "available", + AVAILABLE: "available", /** * @const */ - self.PENDING = "pending", + PENDING: "pending", /** * @const */ - self.SOLD = "sold"; + SOLD: "sold" } @@ -117,6 +115,7 @@ var StatusEnum = function StatusEnum() { } + /** * @return {Integer} **/ @@ -203,6 +202,7 @@ var StatusEnum = function StatusEnum() { this['status'] = status; } + Pet.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript/src/model/Tag.js b/samples/client/petstore/javascript/src/model/Tag.js index 563c1ee9df8..ab1497a0796 100644 --- a/samples/client/petstore/javascript/src/model/Tag.js +++ b/samples/client/petstore/javascript/src/model/Tag.js @@ -50,6 +50,7 @@ } + /** * @return {Integer} **/ @@ -78,6 +79,7 @@ this['name'] = name; } + Tag.prototype.toJson = function() { return JSON.stringify(this); diff --git a/samples/client/petstore/javascript/src/model/User.js b/samples/client/petstore/javascript/src/model/User.js index 67c45561d3c..bb8a8f99008 100644 --- a/samples/client/petstore/javascript/src/model/User.js +++ b/samples/client/petstore/javascript/src/model/User.js @@ -105,6 +105,7 @@ } + /** * @return {Integer} **/ @@ -219,6 +220,7 @@ this['userStatus'] = userStatus; } + User.prototype.toJson = function() { return JSON.stringify(this);