All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dart2-v3template.enum.mustache Maven / Gradle / Ivy

Go to download

dart2 generator from openapi 3.x spec files. Changing to openapitools dependencies.

The newest version!

enum {{classname}} {
  {{#allowableValues}}
    {{#enumVars}}{{{name}}}{{^-last}}, {{/-last}}{{/enumVars}}
  {{/allowableValues}}
}

class {{classname}}TypeTransformer {
  static Map fromJsonMap = {  {{#allowableValues}}
  {{#enumVars}}"{{{name}}}":{{classname}}.{{{name}}}{{^-last}}, {{/-last}}{{/enumVars}}
{{/allowableValues}} };
  static Map<{{classname}}, String> toJsonMap = {  {{#allowableValues}}
  {{#enumVars}}{{classname}}.{{{name}}}:"{{{name}}}"{{^-last}}, {{/-last}}{{/enumVars}}
{{/allowableValues}} };

  static {{classname}} fromJson(dynamic data) {
    var found = fromJsonMap[data];
    if (found == null) {
      throw('Unknown enum value to decode: $data');
    }
    return found;
  }

  static dynamic toJson({{classname}} data) {
    return toJsonMap[data];
  }

  static List<{{classname}}> listFromJson(List json) {
    return json == null ? List<{{classname}}>() : json.map((value) => fromJson(value)).toList();
  }

  static Map mapFromJson(Map json) {
    var map = Map();
    if (json != null && json.isNotEmpty) {
      json.forEach((String key, dynamic value) => map[key] = fromJson(value));
    }
    return map;
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy