decodeComponentSchemas function

List<ComponentSchema> decodeComponentSchemas(
  1. Object? json
)

Decodes a schema list, skipping malformed entries.

Implementation

List<ComponentSchema> decodeComponentSchemas(Object? json) {
  final schemas = <ComponentSchema>[];
  if (json is! List) return schemas;
  for (final entry in json) {
    if (entry is! Map) continue;
    try {
      schemas.add(ComponentSchema.fromJson(entry.cast<String, Object?>()));
    } on FormatException {
      // A malformed entry (or a future format) never breaks the readable
      // ones; schema lists come from caches and manifests of varying age.
    } on TypeError {
      // Same skip for shape mismatches fromJson's casts surface (a string
      // where a map was expected, a non-string list element).
    }
  }
  return schemas;
}