listFromJson static method

List<RelationDescriptor> listFromJson(
  1. Map<String, dynamic> json,
  2. String path, {
  3. PanelDirection direction = PanelDirection.ltr,
})

Parses relations one entry at a time, matching RepeaterComponent._templateFrom: a single malformed relation — missing key/label, a card that is bad or fills no slot, or not even an object — is dropped rather than failing the whole resource. relations itself absent reads as no relations (an older server predating P6d); present but not a list is a genuine contract violation and throws.

Implementation

static List<RelationDescriptor> listFromJson(
  Map<String, dynamic> json,
  String path, {
  PanelDirection direction = PanelDirection.ltr,
}) {
  final raw = json['relations'];
  if (raw == null) return const [];
  if (raw is! List) {
    throw SchemaFormatException(
      '$path.relations',
      'expected List, got ${raw.runtimeType}',
    );
  }

  final relations = <RelationDescriptor>[];
  for (var index = 0; index < raw.length; index++) {
    final node = raw[index];
    if (node is! Map<String, dynamic>) continue;
    try {
      relations.add(
        RelationDescriptor.fromJson(
          node,
          '$path.relations[$index]',
          direction: direction,
        ),
      );
    } on SchemaFormatException {
      continue;
    }
  }
  return relations;
}