Skip to content

Commit 86154f8

Browse files
committed
Use objects for enums, not constructor functions
Fixes #2101.
1 parent 847a8e1 commit 86154f8

File tree

11 files changed

+39
-29
lines changed

11 files changed

+39
-29
lines changed

modules/swagger-codegen/src/main/resources/Javascript/enumClass.mustache

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ if ( typeof define === "function" && define.amd ) {
66
});
77
}
88

9-
var {{datatypeWithEnum}} = function {{datatypeWithEnum}}() {
10-
var self = this;
11-
9+
var {{datatypeWithEnum}} = {
1210
{{#allowableValues}}{{#enumVars}}
1311
/**
1412
* @const
1513
*/
16-
self.{{name}} = "{{value}}"{{^-last}},
17-
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
14+
{{name}}: "{{value}}"{{^-last}},
15+
{{/-last}}{{/enumVars}}{{/allowableValues}}
1816

1917
}

samples/client/petstore/javascript-promise/src/model/Category.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151

5252

53+
5354
/**
5455
* @return {Integer}
5556
**/
@@ -78,6 +79,7 @@
7879
this['name'] = name;
7980
}
8081

82+
8183

8284
Category.prototype.toJson = function() {
8385
return JSON.stringify(this);

samples/client/petstore/javascript-promise/src/model/Order.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) {
2424
});
2525
}
2626

27-
var StatusEnum = function StatusEnum() {
28-
var self = this;
29-
27+
var StatusEnum = {
3028

3129
/**
3230
* @const
3331
*/
34-
self.PLACED = "placed",
32+
PLACED: "placed",
3533

3634
/**
3735
* @const
3836
*/
39-
self.APPROVED = "approved",
37+
APPROVED: "approved",
4038

4139
/**
4240
* @const
4341
*/
44-
self.DELIVERED = "delivered";
42+
DELIVERED: "delivered"
4543

4644
}
4745

@@ -115,6 +113,7 @@ var StatusEnum = function StatusEnum() {
115113
}
116114

117115

116+
118117
/**
119118
* @return {Integer}
120119
**/
@@ -201,6 +200,7 @@ var StatusEnum = function StatusEnum() {
201200
this['complete'] = complete;
202201
}
203202

203+
204204

205205
Order.prototype.toJson = function() {
206206
return JSON.stringify(this);

samples/client/petstore/javascript-promise/src/model/Pet.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) {
2424
});
2525
}
2626

27-
var StatusEnum = function StatusEnum() {
28-
var self = this;
29-
27+
var StatusEnum = {
3028

3129
/**
3230
* @const
3331
*/
34-
self.AVAILABLE = "available",
32+
AVAILABLE: "available",
3533

3634
/**
3735
* @const
3836
*/
39-
self.PENDING = "pending",
37+
PENDING: "pending",
4038

4139
/**
4240
* @const
4341
*/
44-
self.SOLD = "sold";
42+
SOLD: "sold"
4543

4644
}
4745

@@ -117,6 +115,7 @@ var StatusEnum = function StatusEnum() {
117115
}
118116

119117

118+
120119
/**
121120
* @return {Integer}
122121
**/
@@ -203,6 +202,7 @@ var StatusEnum = function StatusEnum() {
203202
this['status'] = status;
204203
}
205204

205+
206206

207207
Pet.prototype.toJson = function() {
208208
return JSON.stringify(this);

samples/client/petstore/javascript-promise/src/model/Tag.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151

5252

53+
5354
/**
5455
* @return {Integer}
5556
**/
@@ -78,6 +79,7 @@
7879
this['name'] = name;
7980
}
8081

82+
8183

8284
Tag.prototype.toJson = function() {
8385
return JSON.stringify(this);

samples/client/petstore/javascript-promise/src/model/User.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
}
106106

107107

108+
108109
/**
109110
* @return {Integer}
110111
**/
@@ -219,6 +220,7 @@
219220
this['userStatus'] = userStatus;
220221
}
221222

223+
222224

223225
User.prototype.toJson = function() {
224226
return JSON.stringify(this);

samples/client/petstore/javascript/src/model/Category.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151

5252

53+
5354
/**
5455
* @return {Integer}
5556
**/
@@ -78,6 +79,7 @@
7879
this['name'] = name;
7980
}
8081

82+
8183

8284
Category.prototype.toJson = function() {
8385
return JSON.stringify(this);

samples/client/petstore/javascript/src/model/Order.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) {
2424
});
2525
}
2626

27-
var StatusEnum = function StatusEnum() {
28-
var self = this;
29-
27+
var StatusEnum = {
3028

3129
/**
3230
* @const
3331
*/
34-
self.PLACED = "placed",
32+
PLACED: "placed",
3533

3634
/**
3735
* @const
3836
*/
39-
self.APPROVED = "approved",
37+
APPROVED: "approved",
4038

4139
/**
4240
* @const
4341
*/
44-
self.DELIVERED = "delivered";
42+
DELIVERED: "delivered"
4543

4644
}
4745

@@ -115,6 +113,7 @@ var StatusEnum = function StatusEnum() {
115113
}
116114

117115

116+
118117
/**
119118
* @return {Integer}
120119
**/
@@ -201,6 +200,7 @@ var StatusEnum = function StatusEnum() {
201200
this['complete'] = complete;
202201
}
203202

203+
204204

205205
Order.prototype.toJson = function() {
206206
return JSON.stringify(this);

samples/client/petstore/javascript/src/model/Pet.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ if ( typeof define === "function" && define.amd ) {
2424
});
2525
}
2626

27-
var StatusEnum = function StatusEnum() {
28-
var self = this;
29-
27+
var StatusEnum = {
3028

3129
/**
3230
* @const
3331
*/
34-
self.AVAILABLE = "available",
32+
AVAILABLE: "available",
3533

3634
/**
3735
* @const
3836
*/
39-
self.PENDING = "pending",
37+
PENDING: "pending",
4038

4139
/**
4240
* @const
4341
*/
44-
self.SOLD = "sold";
42+
SOLD: "sold"
4543

4644
}
4745

@@ -117,6 +115,7 @@ var StatusEnum = function StatusEnum() {
117115
}
118116

119117

118+
120119
/**
121120
* @return {Integer}
122121
**/
@@ -203,6 +202,7 @@ var StatusEnum = function StatusEnum() {
203202
this['status'] = status;
204203
}
205204

205+
206206

207207
Pet.prototype.toJson = function() {
208208
return JSON.stringify(this);

samples/client/petstore/javascript/src/model/Tag.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151

5252

53+
5354
/**
5455
* @return {Integer}
5556
**/
@@ -78,6 +79,7 @@
7879
this['name'] = name;
7980
}
8081

82+
8183

8284
Tag.prototype.toJson = function() {
8385
return JSON.stringify(this);

samples/client/petstore/javascript/src/model/User.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
}
106106

107107

108+
108109
/**
109110
* @return {Integer}
110111
**/
@@ -219,6 +220,7 @@
219220
this['userStatus'] = userStatus;
220221
}
221222

223+
222224

223225
User.prototype.toJson = function() {
224226
return JSON.stringify(this);

0 commit comments

Comments
 (0)