RemoteModelsCatalog.fromJson constructor

RemoteModelsCatalog.fromJson(
  1. Object? json
)

Decodes a catalog body, returning a successful empty catalog on any shape error (the host keeps working with whatever the endpoint reported).

Implementation

factory RemoteModelsCatalog.fromJson(Object? json) {
  if (json is! Map) return const RemoteModelsCatalog();
  final rawProviders = json['providers'];
  if (rawProviders is! Map) return const RemoteModelsCatalog();
  final providers = <String, RemoteProviderEntry>{};
  for (final entry in rawProviders.entries) {
    final key = entry.key;
    if (key is! String) continue;
    final value = entry.value;
    if (value is! Map) continue;
    final parsed = RemoteProviderEntry.fromJson(
      Map<String, Object?>.from(value),
    );
    providers[key] = parsed;
  }
  return RemoteModelsCatalog(providers: providers);
}