OLD | NEW |
1 {%- macro enum_def(enum_name, enum) -%} | 1 {%- macro enum_def(enum_name, enum) -%} |
2 {{enum_name}} = {}; | 2 {{enum_name}} = {}; |
3 {%- set prev_enum = 0 %} | 3 {%- set prev_enum = 0 %} |
4 {%- for field in enum.fields %} | 4 {%- for field in enum.fields %} |
5 {%- if field.value %} | 5 {%- if field.value %} |
6 {{enum_name}}.{{field.name}} = {{field.value|expression_to_text}}; | 6 {{enum_name}}.{{field.name}} = {{field.value|expression_to_text}}; |
7 {%- elif loop.first %} | 7 {%- elif loop.first %} |
8 {{enum_name}}.{{field.name}} = 0; | 8 {{enum_name}}.{{field.name}} = 0; |
9 {%- else %} | 9 {%- else %} |
10 {{enum_name}}.{{field.name}} = {{enum_name}}.{{enum.fields[loop.index0 - 1].na
me}} + 1; | 10 {{enum_name}}.{{field.name}} = {{enum_name}}.{{enum.fields[loop.index0 - 1].na
me}} + 1; |
| 11 {%- endif %} |
| 12 {%- endfor %} |
| 13 |
| 14 {{enum_name}}.isKnownEnumValue = function(value) { |
| 15 {%- if enum.fields %} |
| 16 switch (value) { |
| 17 {%- for enum_field in enum.fields|groupby('numeric_value') %} |
| 18 case {{enum_field[0]}}: |
| 19 {%- endfor %} |
| 20 return true; |
| 21 } |
11 {%- endif %} | 22 {%- endif %} |
12 {%- endfor %} | 23 return false; |
| 24 }; |
| 25 |
| 26 {{enum_name}}.validate = function(enumValue) { |
| 27 var isExtensible = {% if enum.extensible %}true{% else %}false{% endif %}; |
| 28 if (isExtensible || this.isKnownEnumValue(enumValue)) |
| 29 return validator.validationError.NONE; |
| 30 |
| 31 return validator.validationError.UNKNOWN_ENUM_VALUE; |
| 32 }; |
13 {%- endmacro %} | 33 {%- endmacro %} |
OLD | NEW |