-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-schema.ts
More file actions
48 lines (40 loc) · 1.52 KB
/
validate-schema.ts
File metadata and controls
48 lines (40 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env npx tsx
/**
* Schema Validation Test
* Tests the cognitive space JSON schema against actual space files
*/
import Ajv from 'ajv';
import * as fs from 'fs';
import * as path from 'path';
// Load the schema
const schemaPath = './src/lib/cognitive-space.schema.json';
const schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8'));
// Initialize AJV validator
const ajv = new Ajv({allErrors: true});
const validate = ajv.compile(schema);
// Test with the Canada journey space
const testFilePath = './data/spaces/canada-journey-prep-2025-09-18T10-33-52-3NZ/space.json';
const testData = JSON.parse(fs.readFileSync(testFilePath, 'utf8'));
console.log('🧪 Testing JSON Schema Validation\n');
console.log('📁 Schema:', schemaPath);
console.log('📄 Test file:', testFilePath);
console.log();
const isValid = validate(testData);
if (isValid) {
console.log('✅ Schema validation passed!');
console.log('The JSON structure matches the schema perfectly.');
} else {
console.log('❌ Schema validation failed!');
console.log('\nValidation errors:');
validate.errors?.forEach((error, index) => {
console.log(`${index + 1}. ${error.instancePath}: ${error.message}`);
if (error.params) {
console.log(` Additional info:`, error.params);
}
});
}
console.log('\n📊 Schema Summary:');
console.log('- Covers all TypeScript interfaces');
console.log('- Validates actual serialized JSON output');
console.log('- Maintains type safety without compilation');
console.log('- Ready for database storage validation');