readSchemaSync method
Synchronously reads and parses a JSON Schema file from the given filePath.
Returns a JsonSchema object representing the parsed schema.
Throws FileSystemException if the file doesn't exist or can't be read.
Throws ArgumentError if filePath is null or empty.
Throws FormatException if the file contains invalid JSON.
Implementation
JsonSchema readSchemaSync(String filePath) {
if (filePath.isEmpty) {
throw ArgumentError('File path cannot be empty');
}
final file = File(filePath);
if (!file.existsSync()) {
throw FileSystemException('Schema file does not exist', filePath);
}
try {
final content = file.readAsStringSync();
final jsonData = json.decode(content) as Map<String, dynamic>;
return JsonSchema.fromJson(jsonData);
} on FormatException catch (e) {
throw FormatException('Invalid JSON in schema file: ${e.message}', filePath);
} catch (e) {
throw FileSystemException('Failed to read schema file: $e', filePath);
}
}