ModelMapping.fromJson constructor

ModelMapping.fromJson(
  1. Map json
)

Implementation

factory ModelMapping.fromJson(Map json) {
  final entries = ModelAction.values
      .map((e) {
        return switch (json[e.name] ?? json['${e.name}One']) {
          String name => MapEntry<ModelAction, String>(e, name),
          _ => null,
        };
      })
      .where((e) => e != null)
      .whereType<MapEntry<ModelAction, String>>();

  return ModelMapping(
    model: json['model'],
    plural: json['plural'] ?? json['model'],
    actions: Map.fromEntries(entries),
  );
}