resolveSource method
Implementation
FutureOr<Map<String, dynamic>> resolveSource(Object? source,
{String? workingPath}) {
if (source == null) {
return <String, dynamic>{};
} else if (source is Map<String, dynamic>) {
return source;
} else if (source is String) {
if (RegExp(r'^\S+\.json$').hasMatch(source)) {
var apiPlatform = APIPlatform.get();
var filePath =
apiPlatform.resolveFilePath(source, parentPath: workingPath);
if (filePath == null) {
throw StateError("Can't resolve source file path: $source");
}
_log.info('Reading $this source file: $filePath');
var fileData = apiPlatform.readFileAsString(filePath);
if (fileData != null) {
return fileData.resolveMapped((data) {
if (data != null) {
return Json.decode<dynamic>(data);
} else {
return <String, dynamic>{};
}
});
}
} else {
return Json.decode<dynamic>(source);
}
}
return <String, List<Object>>{};
}