resolveDocument static method

Future<Map<String, Map<String, dynamic>>> resolveDocument(
  1. Map doc, {
  2. required String sourceLabel,
  3. required String testAssetPath,
  4. required Future<String> assetLoader(
    1. String assetPath
    ),
  5. required String resolveAssetPath(
    1. String fromAssetPath,
    2. String relativePath
    ),
  6. Set<String>? resolving,
})

Resolves a mock document map (file root or inline layer) into API maps.

Implementation

static Future<Map<String, Map<String, dynamic>>> resolveDocument(
  Map<dynamic, dynamic> doc, {
  required String sourceLabel,
  required String testAssetPath,
  required Future<String> Function(String assetPath) assetLoader,
  required String Function(String fromAssetPath, String relativePath)
      resolveAssetPath,
  Set<String>? resolving,
}) async {
  final raw = <String, Map<String, dynamic>>{};
  final extendsRaw = doc[extendsKey];
  if (extendsRaw != null) {
    final parents = _extendsList(extendsRaw, sourceLabel);
    for (final parent in parents) {
      final parentApis = await resolveFile(
        testAssetPath: testAssetPath,
        mockFilePath: parent,
        assetLoader: assetLoader,
        resolveAssetPath: resolveAssetPath,
        resolving: resolving,
      );
      mergeApiMaps(
        raw,
        parentApis,
        sourceLabel: sourceLabel,
      );
    }
  }

  for (final entry in doc.entries) {
    final apiName = entry.key.toString();
    if (apiName == extendsKey) continue;
    if (entry.value is! Map) {
      throw EnsembleTestFailure(
        'Mock for API "$apiName" in "$sourceLabel" must be a map',
      );
    }
    mergeApiMaps(
      raw,
      {
        apiName:
            _stringifyKeys(Map<dynamic, dynamic>.from(entry.value as Map)),
      },
      sourceLabel: sourceLabel,
    );
  }
  return raw;
}