resolveFileList function

Future<List<TFileInfo>> resolveFileList(
  1. String rootPath
)

Resolves and processes a list of .swagger.json files in the specified directory.

Parameters:

  • rootPath: The String root directory path to search for .swagger.json files.

Returns:

Implementation

Future<List<TFileInfo>> resolveFileList(String rootPath) async {
  // Define the glob pattern for finding .swagger.json files
  final glob = Glob('*.swagger.json');
  final absolutePathList = glob.listSync(root: rootPath, followLinks: false);

  final fileList = <TFileInfo>[];

  for (final entity in absolutePathList) {
    if (entity is File) {
      try {
        final file = File(entity.path);
        final content = await file.readAsString();
        final parsedData =
            jsonDecode(content) as Map<String, dynamic>;

        fileList.add(TFileInfo(
          absolutePath: file.absolute.path,
          parsedData: parsedData,
        ));
      } catch (e) {
        print(
            'Error reading or parsing file: ${entity.absolute.path}. Error: $e');
      }
    }
  }

  return fileList;
}