Swagger CodeGen - Reserved words

506 views
Skip to first unread message

hshorter

unread,
Oct 9, 2014, 10:40:37 AM10/9/14
to swagger-sw...@googlegroups.com
When generating Java code from the JSON I got the following exception:

java.lang.Exception: reserved word "switch" not allowed

at com.wordnik.swagger.codegen.BasicJavaGenerator.escapeReservedWord(BasicJavaGenerator.scala:240)

at com.wordnik.swagger.codegen.language.CodegenConfig.toVarName(CodegenConfig.scala:116)

at com.wordnik.swagger.codegen.BasicJavaGenerator.toVarName(BasicJavaGenerator.scala:112)


Should the code not be replacing the reserved word, in this case 'switch' with something like '_switch'?

Thanks.

 

Ron

unread,
Oct 9, 2014, 10:48:49 AM10/9/14
to swagger-sw...@googlegroups.com
You should probably open a bug on swagger-codegen (it's best if you can provide a sample swagger json to reproduce it).

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hshorter

unread,
Oct 9, 2014, 11:46:38 AM10/9/14
to swagger-sw...@googlegroups.com

Thank you again for replying Ron!

The JSON is pasted below, the switch is a parameter name, I'm not sure if this is invalid as generated by the Restlet implementation or is it is something the codegen should be fixing? Would you still like me to raise the bug?



operations
": [
{
"
consumes": [ ],
"
items": { },
"
method": "GET",
"
nickname": "GET",
"
parameters": [
{
"
allowMultiple": false,
"
description": "",
"
name": "domain",
"
paramType": "path",
"
required": true,
"
type": "string"},
{
"
allowMultiple": false,
"
description": "",
"
name": "svlan",
"
paramType": "path",
"
required": true,
"
type": "string"},
{
"
allowMultiple": false,
"
description": "",
"
name": "address",
"
paramType": "path",
"
required": true,
"
type": "string"},
{
"
allowMultiple": false,
"
description": "",
"
name": "switch",
"
paramType": "path",
"
required": true,
"
type": "string"}],
"
produces": [
"
application/json",
"
application/x-json-smile",
"
application/xml",
"
text/xml",
"
application/x-yaml",
"
text/x-yaml",
"
text/csv",
"
application/*+xml",
"application/xml",
"text/xml"],
"responseMessages": [ ],
"summary": "",
"type": "ErpsRepairVlanList"}

Ron

unread,
Oct 9, 2014, 12:12:09 PM10/9/14
to swagger-sw...@googlegroups.com
There's no problem with having a parameter named "switch", so you should definitely open an issue.

tony tam

unread,
Oct 9, 2014, 7:53:15 PM10/9/14
to swagger-sw...@googlegroups.com
Well, technically swagger-codegen is throwing the error on purpose because escaping reserved words is not supported in the java template.  Regardless I added a comment to the issue in github
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages