Fix Java Generator to always generate valid Java variable names

This commit is contained in:
Mark Crowther 2013-10-03 15:59:40 +01:00
parent f17654cd96
commit 7bde2ffd6e
2 changed files with 9 additions and 4 deletions

View File

@ -41,10 +41,10 @@ public class {{classname}} {
{{/requiredParamCount}}
{{#queryParams}}if(!"null".equals(String.valueOf({{paramName}})))
queryParams.put("{{paramName}}", String.valueOf({{paramName}}));
queryParams.put("{{baseName}}", String.valueOf({{paramName}}));
{{/queryParams}}
{{#headerParams}}headerParams.put("{{paramName}}", {{paramName}});
{{#headerParams}}headerParams.put("{{baseName}}", {{paramName}});
{{/headerParams}}
String contentType = "application/json";
@ -68,4 +68,4 @@ public class {{classname}} {
}
{{/operation}}
}
{{/operations}}
{{/operations}}

View File

@ -93,6 +93,11 @@ class BasicJavaGenerator extends BasicGenerator {
// file suffix
override def fileSuffix = ".java"
override def toVarName(name: String): String = {
val paramName = name.replaceAll("[^a-zA-Z0-9_]","")
super.toVarName(paramName)
}
// response classes
override def processResponseClass(responseClass: String): Option[String] = {
responseClass match {
@ -209,4 +214,4 @@ class BasicJavaGenerator extends BasicGenerator {
("JsonUtil.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "JsonUtil.java"),
("apiException.mustache", destinationDir + java.io.File.separator + invokerPackage.get.replace(".", java.io.File.separator) + java.io.File.separator, "ApiException.java"),
("pom.mustache", "generated-code/java", "pom.xml"))
}
}