Skip to content

Commit

Permalink
Merge pull request #619 from swagger-api/swos-188
Browse files Browse the repository at this point in the history
Allow nullable enums
  • Loading branch information
HugoMario authored Mar 4, 2020
2 parents 859b5d8 + ef1b80a commit 81a9246
Show file tree
Hide file tree
Showing 26 changed files with 82 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ public void processModelEnums(Map<String, Object> objs) {
Map<String, String> enumVar = new HashMap<String, String>();
String enumName = findEnumName(truncateIdx, value);
enumVar.put("name", toEnumVarName(enumName, cm.dataType));
enumVar.put("value", toEnumValue(value.toString(), cm.dataType));
if (value == null) {
enumVar.put("value", toEnumValue(null, cm.dataType));
} else {
enumVar.put("value", toEnumValue(value.toString(), cm.dataType));
}
enumVars.add(enumVar);
}
cm.allowableValues.put("enumVars", enumVars);
Expand All @@ -320,6 +324,9 @@ public void processModelEnums(Map<String, Object> objs) {
}

private String findEnumName(int truncateIdx, Object value) {
if (value == null) {
return "null";
}
String enumName;
if (truncateIdx == 0) {
enumName = value.toString();
Expand Down Expand Up @@ -370,6 +377,9 @@ public String toEnumDefaultValue(String value, String datatype) {
* @return the sanitized value for enum
*/
public String toEnumValue(String value, String datatype) {
if (value == null) {
return null;
}
if ("number".equalsIgnoreCase(datatype)) {
return value;
} else {
Expand Down Expand Up @@ -3778,7 +3788,11 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
Map<String, String> enumVar = new HashMap<String, String>();
String enumName = findEnumName(truncateIdx, value);
enumVar.put("name", toEnumVarName(enumName, var.datatype));
enumVar.put("value", toEnumValue(value.toString(), var.datatype));
if (value == null) {
enumVar.put("value", toEnumValue(null, var.datatype));
} else {
enumVar.put("value", toEnumValue(value.toString(), var.datatype));
}
enumVars.add(enumVar);
}
allowableValues.put("enumVars", enumVars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al

@Override
public String toEnumValue(String value, String datatype) {
if (value == null) {
return null;
}
// C# only supports enums as literals for int, int?, long, long?, byte, and byte?. All else must be treated as strings.
// Per: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/enum
// The approved types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,9 @@ public String toEnumVarName(String value, String datatype) {

@Override
public String toEnumValue(String value, String datatype) {
if (value == null) {
return null;
}
if ("Integer".equals(datatype) || "Double".equals(datatype)) {
return value;
} else if ("Long".equals(datatype)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/handlebars/Java/modelEnum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.google.gson.stream.JsonWriter;
public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/handlebars/Java/modelInnerEnum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class {{classname}} {
@ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{^vendorExtensions.x-java-is-response-void}}, content = @Content({{^containerType}}schema = @Schema(implementation = {{{baseType}}}.class)){{/containerType}}{{#containerType}}array = @ArraySchema(schema = @Schema(implementation = {{{baseType}}}.class))){{/containerType}}{{/vendorExtensions.x-java-is-response-void}}){{#hasMore}},{{/hasMore}}{{/responses}} })
{{/useOas2}}
public Response {{nickname}}({{#parameters}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}}, {{/hasMore}}{{/parameters}}) {
return delegate.{{nickname}}({{#parameters}}{{#isBinary}}{{paramName}}InputStream, {{paramName}}Detail{{/isBinary}}{{^isBinary}}{{paramName}}{{/isBinary}}, {{/parameters}}securityContext);
return delegate.{{nickname}}({{#parameters}}{{#isFile}}{{paramName}}InputStream, {{paramName}}Detail{{/isFile}}{{^isFile}}{{paramName}}{{/isFile}}, {{/parameters}}securityContext);
}
{{/contents}}
{{/operation}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum {{datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}@XmlEnumValue({{{value}}}) {{name}}({{datatype}}.valueOf({{{value}}})){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}
{{#enumVars}}{{#value}}@XmlEnumValue({{{value}}}) {{name}}({{datatype}}.valueOf({{{value}}})){{/value}}{{^value}}@XmlEnumValue("") {{name}}(null){{/value}}{{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}
{{/allowableValues}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
public enum {{datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}@XmlEnumValue({{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}{{{value}}}{{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}) {{name}}({{datatype}}.valueOf({{{value}}})){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}
{{#enumVars}}@XmlEnumValue({{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}{{{value}}}{{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}) {{name}}({{#value}}{{datatype}}.valueOf({{{value}}}){{/value}}{{^value}}null{{/value}})){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}
{{/allowableValues}}


Expand Down
28 changes: 17 additions & 11 deletions src/main/resources/handlebars/JavaJaxRS/cxf/enumOuterClass.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,30 @@ import javax.xml.bind.annotation.XmlEnumValue;
{{#if withXml}}
@XmlType(name="{{classname}}")
@XmlEnum({{dataType}}.class)
{{/if~}}
{{/if}}
public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} {
{{#if gson}}
{{#allowableValues}}{{#enumVars}}
{{#allowableValues}}
{{#enumVars}}
@SerializedName({{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}{{{value}}}{{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}})
{{#if withXml}}
@XmlEnumValue({{{value}}})
{{/if~}}
{{{name}}}({{{value}}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
@XmlEnumValue({{#value}}{{{value}}}{{/value}}{{^value}}""{{/value}})
{{/if}}
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}
{{/if}}
{{#unless gson}}
{{#allowableValues}}{{#enumVars}}
{{#allowableValues}}
{{#enumVars}}
{{#if withXml}}
@XmlEnumValue({{{value}}})
{{/if~}}
{{{name}}}({{{value}}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
@XmlEnumValue({{#value}}{{{value}}}{{/value}}{{^value}}""{{/value}})
{{/if}}
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}
{{/unless}}

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

Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/handlebars/JavaJaxRS/cxf/pojo.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ import com.fasterxml.jackson.annotation.JsonCreator;
{{#useOas2}}@ApiModel{{/useOas2}}{{^useOas2}}@Schema{{/useOas2}}(description="{{{description}}}")
{{/description}}
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#interfaceModels}}{{#@first}}implements {{/@first}}{{classname}}{{^@last}}, {{/@last}}{{#@last}} {{/@last}}{{/interfaceModels}} {
{{#vars}}{{#baseItems this}}{{#is this 'enum'}}
{{>modelInnerEnum}}{{/is~}}{{/baseItems}}
{{#vars}}
{{#baseItems this}}
{{#is this 'enum'}}
{{>modelInnerEnum}}
{{/is}}
{{/baseItems}}
{{#withXml}}
@XmlElement(name="{{baseName}}"{{#required}}, required = {{required}}{{/required}})
{{/withXml}}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/handlebars/JavaJaxRS/enumClass.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
{{#allowableValues}}
{{#enumVars}}
@SerializedName({{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}{{{value}}}{{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}})
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}
{{/if}}
{{#unless gson}}
{{#allowableValues}}
{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
{{#if gson}}
{{#allowableValues}}{{#enumVars}}
@SerializedName({{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}{{{value}}}{{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}})
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/if}}
{{#unless gson}}
{{#allowableValues}}{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/unless}}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/handlebars/JavaJaxRS/modelEnum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
{{#if gson}}
{{#allowableValues}}{{#enumVars}}
@SerializedName({{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}{{{value}}}{{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}})
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/if}}
{{#unless gson}}
{{#allowableValues}}{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/unless}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},

{{/@last}}{{#@last}};
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};
{{/@last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
public enum {{#datatypeWithEnum}}{{.}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},

{{/@last}}{{#@last}};
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};
{{/@last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
public enum {{datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}{{name}}({{datatype}}.valueOf({{{value}}})){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}
{{#enumVars}}{{name}}({{#value}}{{datatype}}.valueOf({{{value}}}){{/value}}{{^value}}null{{/value}}){{^@last}}, {{/@last}}{{#@last}};{{/@last}}{{/enumVars}}
{{/allowableValues}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
{{#if gson}}
{{#allowableValues}}{{#enumVars}}
@SerializedName({{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}}{{{value}}}{{#is ../../this 'integer'}}"{{/is}}{{#is ../../this 'double'}}"{{/is}}{{#is ../../this 'long'}}"{{/is}}{{#is ../../this 'float'}}"{{/is}})
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/if}}
{{#unless gson}}
{{#allowableValues}}{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/unless}}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/handlebars/JavaSpring/enumClass.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
{{#allowableValues}}
{{#enumVars}}
@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}
{{/gson}}
{{^gson}}
{{#allowableValues}}
{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
{{#gson}}
{{#allowableValues}}{{#enumVars}}
@SerializedName({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/gson}}
{{^gson}}
{{#allowableValues}}{{#enumVars}}
{{{name}}}({{{value}}}){{^@last}},
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},
{{/@last}}{{#@last}};{{/@last}}{{/enumVars}}{{/allowableValues}}
{{/gson}}

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/handlebars/aspnetcore/enumClass.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
{
{{#allowableValues}}{{#enumVars}}
/// <summary>
/// Enum {{name}} for {{{value}}}
/// Enum {{name}} for {{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}
/// </summary>
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{@index}}{{/isString}}{{^@last}},
{{#isString}}[EnumMember(Value = {{#value}}"{{{value}}}"{{/value}}{{^value}}null{{/value}})]{{/isString}}
{{name}}{{^isString}} = {{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}{{/isString}}{{#isString}} = {{@index}}{{/isString}}{{^@last}},
{{/@last}}{{/enumVars}}{{/allowableValues}}
}
6 changes: 3 additions & 3 deletions src/main/resources/handlebars/csharp/enumClass.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
{
{{#allowableValues}}{{#enumVars}}
/// <summary>
/// Enum {{name}} for {{{value}}}
/// Enum {{name}} for {{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}
/// </summary>
[EnumMember(Value = {{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isFloat}}"{{/isFloat}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isFloat}}"{{/isFloat}})]
{{name}}{{#isLong}} = {{{value}}}{{/isLong}}{{#isInteger}} = {{{value}}}{{/isInteger}}{{^isInteger}} = {{@index}}{{/isInteger}}{{^@last}},
[EnumMember(Value = {{#value}}{{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isFloat}}"{{/isFloat}}{{#isDouble}}"{{/isDouble}}{{{value}}}{{#isLong}}"{{/isLong}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isFloat}}"{{/isFloat}}{{/value}}{{^value}}null{{/value}})]
{{name}} {{#value}}{{#isLong}} = {{{value}}}{{/isLong}}{{#isInteger}} = {{{value}}}{{/isInteger}}{{^isInteger}} = {{@index}}{{/isInteger}}{{/value}}{{^value}}null{{/value}}{{^@last}},
{{/@last}}{{/enumVars}}{{/allowableValues}}
}
6 changes: 3 additions & 3 deletions src/main/resources/handlebars/csharp/modelEnum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
{
{{#allowableValues}}{{#enumVars}}
/// <summary>
/// Enum {{name}} for value: {{{value}}}
/// Enum {{name}} for value: {{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}
/// </summary>
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{@index_1}}{{/isString}}{{^@last}},
{{#isString}}[EnumMember(Value = {{#value}}"{{{value}}}"{{/value}}{{^value}}null{{/value}})]{{/isString}}
{{name}}{{^isString}} = {{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}{{/isString}}{{#isString}} = {{@index_1}}{{/isString}}{{^@last}},
{{/@last}}{{/enumVars}}{{/allowableValues}}
}{{! NOTE: This model's enumVars is modified to look like CodegenProperty}}
6 changes: 3 additions & 3 deletions src/main/resources/handlebars/csharp/modelInnerEnum.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{
{{#allowableValues}}{{#enumVars}}
/// <summary>
/// Enum {{name}} for value: {{{value}}}
/// Enum {{name}} for value: {{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}
/// </summary>
{{#isString}}[EnumMember(Value = "{{{value}}}")]{{/isString}}
{{name}}{{^isString}} = {{{value}}}{{/isString}}{{#isString}} = {{@index_1}}{{/isString}}{{^@last}},
{{#isString}}[EnumMember(Value = {{#value}}"{{{value}}}"{{/value}}{{^value}}null{{/value}})]{{/isString}}
{{name}}{{^isString}} = {{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}{{/isString}}{{#isString}} = {{@index_1}}{{/isString}}{{^@last}},
{{/@last}}{{/enumVars}}{{/allowableValues}}
}
{{/isContainer}}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class {{classname}} (
*/
enum class {{nameInCamelCase}}(val value: {{datatype}}){
{{#allowableValues}}{{#enumVars}}
{{&name}}({{{value}}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{&name}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}{{/allowableValues}}
}
{{/is}}{{/vars}}{{/has}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
*/
enum class {{classname}}(val value: {{dataType}}){
{{#allowableValues}}{{#enumVars}}
{{&name}}({{{value}}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{&name}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}// :/
{{/enumVars}}{{/allowableValues}}
}

0 comments on commit 81a9246

Please sign in to comment.