Skip to content

Commit

Permalink
support x-enumNames vendor extension and make it available to Java te…
Browse files Browse the repository at this point in the history
…mplate
  • Loading branch information
craffael committed Aug 31, 2017
1 parent 049b1b2 commit 2b7851a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3554,6 +3554,7 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
List<Map<String, String>> enumVars = new ArrayList<Map<String, String>>();
String commonPrefix = findCommonPrefixOfVars(values);
int truncateIdx = commonPrefix.length();
int idx = 0;
for (Object value : values) {
Map<String, String> enumVar = new HashMap<String, String>();
String enumName;
Expand All @@ -3567,7 +3568,11 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
}
enumVar.put("name", toEnumVarName(enumName, var.datatype));
enumVar.put("value", toEnumValue(value.toString(), var.datatype));
if(var.vendorExtensions.containsKey("x-enumNames")) {
enumVar.put("x-enumName", (String)((List)var.vendorExtensions.get("x-enumNames")).get(idx));
}
enumVars.add(enumVar);
idx++;
}
allowableValues.put("enumVars", enumVars);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import com.google.gson.stream.JsonWriter;
{{/gson}}
public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
{{#allowableValues}}{{#enumVars}}
{{{name}}}({{{value}}}){{^-last}},
{{#x-enumName}}{{{x-enumName}}}{{/x-enumName}}{{^x-enumName}}{{{name}}}{{/x-enumName}}({{{value}}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}

private {{{dataType}}} value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}}({{{value}}}){{^-last}},
{{#x-enumName}}{{{x-enumName}}}{{/x-enumName}}{{^x-enumName}}{{{name}}}{{/x-enumName}}({{{value}}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down

0 comments on commit 2b7851a

Please sign in to comment.