-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate.js
30 lines (22 loc) · 832 Bytes
/
validate.js
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
import Ajv from "ajv";
import fs from "fs";
const ajv = new Ajv({ strict: false });
// schemas
const collectionSchema = JSON.parse(fs.readFileSync("schema/collection.schema.json", "utf8"));
const traitsSchemaFilePath = process.argv[3];
collectionSchema.properties.items.items.properties.meta.properties.traits.$ref =
"traits.schema.json";
// traitsSchemaFilePath;
const traitsSchema = JSON.parse(fs.readFileSync(traitsSchemaFilePath, "utf8"));
// Add referenced schemas
ajv.addSchema(traitsSchema);
// Compile envelope schema
const validate = ajv.compile(collectionSchema);
const dataFilePath = process.argv[2];
const data = JSON.parse(fs.readFileSync(dataFilePath, "utf8"));
// Validate
if (validate(data)) {
console.log("Collection JSON is valid!");
} else {
console.error("Validation errors:", validate.errors);
}