dart2-v3template.enum.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connect-openapi-dart Show documentation
Show all versions of connect-openapi-dart Show documentation
dart2 generator from openapi 3.x spec files. Changing to openapitools dependencies.
class {{classname}} {
/// The underlying value of this enum member.
final {{dataType}} value;
const {{classname}}._internal(this.value);
{{#allowableValues}}
{{#enumVars}}
{{#description}}
/// {{description}}
{{/description}}
static const {{classname}} {{{name}}} = const {{classname}}._internal({{{value}}});
{{/enumVars}}
{{/allowableValues}}
static {{classname}} fromJson(dynamic data) {
switch (data) {
{{#allowableValues}}
{{#enumVars}}
case {{{value}}}: return {{classname}}.{{{name}}};
{{/enumVars}}
{{/allowableValues}}
default: throw('Unknown enum value to decode: $data');
}
}
static dynamic toJson({{classname}} data) {
return data.value;
}
}
class {{classname}}TypeTransformer {
dynamic encode({{classname}} data) {
return data.value;
}
{{classname}} decode(dynamic data) {
switch (data) {
{{#allowableValues}}
{{#enumVars}}
case {{{value}}}: return {{classname}}.{{{name}}};
{{/enumVars}}
{{/allowableValues}}
default: throw('Unknown enum value to decode: $data');
}
}
}