-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.js
More file actions
29 lines (24 loc) · 738 Bytes
/
Copy pathvalidate.js
File metadata and controls
29 lines (24 loc) · 738 Bytes
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
import Ajv from "ajv";
import fs from "fs";
// Read command line arguments
const schemaPath = process.argv[2];
const dataPath = process.argv[3];
if (!schemaPath || !dataPath) {
console.error("Usage: node validate.js <schema.json> <data.json>");
process.exit(1);
}
// Read files
const schema = JSON.parse(fs.readFileSync(schemaPath, "utf8"));
const data = JSON.parse(fs.readFileSync(dataPath, "utf8"));
// Validate
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(schema);
const valid = validate(data);
if (valid) {
console.log("✅ Validation successful!");
process.exit(0);
} else {
console.log("❌ Validation failed!");
console.log(JSON.stringify(validate.errors, null, 2));
process.exit(1);
}