Skip to content

Commit cfede64

Browse files
committed
fix: handle single object in fixture files
- Support single object fixture - Improve JSON type handling - Added error message on bad type
1 parent 096e4da commit cfede64

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

routes/_middleware.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,18 @@ List<Map<String, dynamic>> _loadFixtureSync(String fileName) {
9898
return [];
9999
}
100100
final content = file.readAsStringSync();
101-
final decoded = jsonDecode(content) as List<dynamic>?;
102-
return decoded?.whereType<Map<String, dynamic>>().toList() ?? [];
101+
final decoded = jsonDecode(content);
102+
103+
if (decoded is Map<String, dynamic>) {
104+
// If it's a single object, wrap it in a list
105+
return [decoded];
106+
} else if (decoded is List<dynamic>) {
107+
// If it's a list, filter for maps and return
108+
return decoded.whereType<Map<String, dynamic>>().toList();
109+
} else {
110+
print('Error: Fixture file $path contains unexpected JSON type.');
111+
return [];
112+
}
103113
} catch (e) {
104114
print('Error loading or parsing fixture file $path: $e');
105115
return [];

0 commit comments

Comments
 (0)