Fix error with array of enum in Java client

ref: https://github.com/swagger-api/swagger-codegen/pull/1457#issuecomment-155185530
This commit is contained in:
xhh 2015-11-10 12:04:29 +08:00
parent 8408b97771
commit aaafd0632c

View File

@ -496,7 +496,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
}
allowableValues.put("enumVars", enumVars);
// handle default value for enum, e.g. available => StatusEnum.AVAILABLE
if (var.defaultValue != null && !"null".equals(var.defaultValue)) {
if (var.defaultValue != null) {
String enumName = null;
for (Map<String, String> enumVar : enumVars) {
if (var.defaultValue.equals(enumVar.get("value"))) {
@ -504,10 +504,9 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
break;
}
}
if (enumName == null) {
throw new RuntimeException("default value of property \"" + var.baseName + "\" is not in allowed values: " + var.defaultValue);
if (enumName != null) {
var.defaultValue = var.datatypeWithEnum + "." + enumName;
}
var.defaultValue = var.datatypeWithEnum + "." + enumName;
}
}
}