Skip to content

Commit f5f78f3

Browse files
committed
Correct exporting of enum classes
Fixes #2102.
1 parent 847a8e1 commit f5f78f3

File tree

12 files changed

+136
-162
lines changed

12 files changed

+136
-162
lines changed
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
2-
//export module
3-
if ( typeof define === "function" && define.amd ) {
4-
define('{{datatypeWithEnum}}', [], function() {
5-
return {{datatypeWithEnum}};
6-
});
7-
}
8-
91
var {{datatypeWithEnum}} = function {{datatypeWithEnum}}() {
10-
var self = this;
2+
var self = this;
3+
{{#allowableValues}}{{#enumVars}}
4+
/**
5+
* @const
6+
*/
7+
self.{{name}} = "{{value}}"{{^-last}},
8+
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
119

12-
{{#allowableValues}}{{#enumVars}}
13-
/**
14-
* @const
15-
*/
16-
self.{{name}} = "{{value}}"{{^-last}},
17-
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
10+
};
1811

19-
}
12+
{{classname}}.{{datatypeWithEnum}} = {{datatypeWithEnum}};

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
}
1515
}(this, function(module, ApiClient{{#imports}}, {{import}}{{/imports}}) {
1616
'use strict';
17-
1817
{{#models}}{{#model}}
19-
{{#vars}}{{#isEnum}}{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
20-
{{>enumClass}}{{/items}}*/{{/items.isEnum}}{{/vars}}
21-
2218
{{#description}}/**
2319
* {{description}}
2420
**/{{/description}}
@@ -73,6 +69,9 @@
7369
return JSON.stringify(this);
7470
}
7571

72+
{{#vars}}{{#isEnum}}{{>enumClass}}{{/isEnum}}{{#items.isEnum}}{{#items}}
73+
{{>enumClass}}{{/items}}*/{{/items.isEnum}}{{/vars}}
74+
7675
if (module) {
7776
module.{{classname}} = {{classname}};
7877
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
}
1515
}(this, function(module, ApiClient) {
1616
'use strict';
17-
18-
1917

20-
2118

2219
var Category = function Category() {
2320

@@ -50,6 +47,7 @@
5047
}
5148

5249

50+
5351
/**
5452
* @return {Integer}
5553
**/
@@ -78,11 +76,14 @@
7876
this['name'] = name;
7977
}
8078

79+
8180

8281
Category.prototype.toJson = function() {
8382
return JSON.stringify(this);
8483
}
8584

85+
86+
8687
if (module) {
8788
module.Category = Category;
8889
}

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,8 @@
1414
}
1515
}(this, function(module, ApiClient) {
1616
'use strict';
17-
1817

1918

20-
//export module
21-
if ( typeof define === "function" && define.amd ) {
22-
define('StatusEnum', [], function() {
23-
return StatusEnum;
24-
});
25-
}
26-
27-
var StatusEnum = function StatusEnum() {
28-
var self = this;
29-
30-
31-
/**
32-
* @const
33-
*/
34-
self.PLACED = "placed",
35-
36-
/**
37-
* @const
38-
*/
39-
self.APPROVED = "approved",
40-
41-
/**
42-
* @const
43-
*/
44-
self.DELIVERED = "delivered";
45-
46-
}
47-
48-
49-
5019
var Order = function Order() {
5120

5221
/**
@@ -115,6 +84,7 @@ var StatusEnum = function StatusEnum() {
11584
}
11685

11786

87+
11888
/**
11989
* @return {Integer}
12090
**/
@@ -201,11 +171,35 @@ var StatusEnum = function StatusEnum() {
201171
this['complete'] = complete;
202172
}
203173

174+
204175

205176
Order.prototype.toJson = function() {
206177
return JSON.stringify(this);
207178
}
208179

180+
var StatusEnum = function StatusEnum() {
181+
var self = this;
182+
183+
/**
184+
* @const
185+
*/
186+
self.PLACED = "placed",
187+
188+
/**
189+
* @const
190+
*/
191+
self.APPROVED = "approved",
192+
193+
/**
194+
* @const
195+
*/
196+
self.DELIVERED = "delivered";
197+
198+
};
199+
200+
Order.StatusEnum = StatusEnum;
201+
202+
209203
if (module) {
210204
module.Order = Order;
211205
}

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,8 @@
1414
}
1515
}(this, function(module, ApiClient, Category, Tag) {
1616
'use strict';
17-
1817

1918

20-
//export module
21-
if ( typeof define === "function" && define.amd ) {
22-
define('StatusEnum', [], function() {
23-
return StatusEnum;
24-
});
25-
}
26-
27-
var StatusEnum = function StatusEnum() {
28-
var self = this;
29-
30-
31-
/**
32-
* @const
33-
*/
34-
self.AVAILABLE = "available",
35-
36-
/**
37-
* @const
38-
*/
39-
self.PENDING = "pending",
40-
41-
/**
42-
* @const
43-
*/
44-
self.SOLD = "sold";
45-
46-
}
47-
48-
49-
5019
var Pet = function Pet(photoUrls, name) {
5120

5221
/**
@@ -117,6 +86,7 @@ var StatusEnum = function StatusEnum() {
11786
}
11887

11988

89+
12090
/**
12191
* @return {Integer}
12292
**/
@@ -203,11 +173,35 @@ var StatusEnum = function StatusEnum() {
203173
this['status'] = status;
204174
}
205175

176+
206177

207178
Pet.prototype.toJson = function() {
208179
return JSON.stringify(this);
209180
}
210181

182+
var StatusEnum = function StatusEnum() {
183+
var self = this;
184+
185+
/**
186+
* @const
187+
*/
188+
self.AVAILABLE = "available",
189+
190+
/**
191+
* @const
192+
*/
193+
self.PENDING = "pending",
194+
195+
/**
196+
* @const
197+
*/
198+
self.SOLD = "sold";
199+
200+
};
201+
202+
Pet.StatusEnum = StatusEnum;
203+
204+
211205
if (module) {
212206
module.Pet = Pet;
213207
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
}
1515
}(this, function(module, ApiClient) {
1616
'use strict';
17-
18-
1917

20-
2118

2219
var Tag = function Tag() {
2320

@@ -50,6 +47,7 @@
5047
}
5148

5249

50+
5351
/**
5452
* @return {Integer}
5553
**/
@@ -78,11 +76,14 @@
7876
this['name'] = name;
7977
}
8078

79+
8180

8281
Tag.prototype.toJson = function() {
8382
return JSON.stringify(this);
8483
}
8584

85+
86+
8687
if (module) {
8788
module.Tag = Tag;
8889
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
}
1515
}(this, function(module, ApiClient) {
1616
'use strict';
17-
18-
1917

20-
2118

2219
var User = function User() {
2320

@@ -105,6 +102,7 @@
105102
}
106103

107104

105+
108106
/**
109107
* @return {Integer}
110108
**/
@@ -219,11 +217,14 @@
219217
this['userStatus'] = userStatus;
220218
}
221219

220+
222221

223222
User.prototype.toJson = function() {
224223
return JSON.stringify(this);
225224
}
226225

226+
227+
227228
if (module) {
228229
module.User = User;
229230
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
}
1515
}(this, function(module, ApiClient) {
1616
'use strict';
17-
18-
1917

20-
2118

2219
var Category = function Category() {
2320

@@ -50,6 +47,7 @@
5047
}
5148

5249

50+
5351
/**
5452
* @return {Integer}
5553
**/
@@ -78,11 +76,14 @@
7876
this['name'] = name;
7977
}
8078

79+
8180

8281
Category.prototype.toJson = function() {
8382
return JSON.stringify(this);
8483
}
8584

85+
86+
8687
if (module) {
8788
module.Category = Category;
8889
}

0 commit comments

Comments
 (0)