Description
Enum types produce invalid JavaScript when dealing with String constants
Swagger-codegen version
Latest (2.2.0)
Swagger declaration file content or url
Given a swagger definition for an Enum type:
"deviceType": {
"enum": [
"ANDROID",
"UNKNOWN",
"IOS"
],
"type": "string"
},
The generated JS client looks like this
exports.DeviceTypeEnum = {
/**
* value: ANDROID
* @const
*/
"ANDROID": ANDROID,
/**
* value: UNKNOWN
* @const
*/
"UNKNOWN": UNKNOWN,
/**
* value: IOS
* @const
*/
"IOS": IOS
};
Which is invalid javascript, since the constants IOS, UNKNOWN, etc. are undefined.
Proposed fix
We've worked around this by adding in double quotes to the templates:
exports.{{datatypeWithEnum}} = {
{{#allowableValues}}
{{#enumVars}}
{{#emitJSDoc}}
/**
* value: {{{value}}}
* @const
*/
{{/emitJSDoc}}
"{{name}}": "{{{value}}}"{{^-last}},
{{/-last}}
{{/enumVars}}
{{/allowableValues}}
};
Command line used for generation
swagger-codegen generate -i $SWAGGER_URL \
-l javascript \
-o clients/javascript/ \
--additional-properties usePromises=true,projectName=test-project
Description
Enum types produce invalid JavaScript when dealing with
StringconstantsSwagger-codegen version
Latest (2.2.0)
Swagger declaration file content or url
Given a swagger definition for an
Enumtype:The generated JS client looks like this
Which is invalid javascript, since the constants
IOS,UNKNOWN, etc. areundefined.Proposed fix
We've worked around this by adding in double quotes to the templates:
Command line used for generation