SourceSpecification.fromJson constructor

SourceSpecification.fromJson(
  1. Map<String, dynamic> json
)

Deserializes a source specification from JSON.

Implementation

factory SourceSpecification.fromJson(Map<String, dynamic> json) {
  return switch (json['type'] as String?) {
    'local' => LocalSource(
      paths: (json['paths'] as List? ?? const [])
          .map((e) => e as String)
          .toList(),
    ),
    'git' => GitSource(
      repository: Uri.parse(json['repository'] as String),
      revision: json['revision'] as String,
      subdirectory: json['subdirectory'] as String?,
      submodules: json['submodules'] as bool? ?? false,
    ),
    'archive' => ArchiveSource(
      uri: Uri.parse(json['uri'] as String),
      sha256: json['sha256'] as String,
      subdirectory: json['subdirectory'] as String?,
    ),
    final type => throw FormatException('Unknown source type: $type'),
  };
}