forked from adobe/xdm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidate.js
66 lines (57 loc) · 2.51 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const $ = require("shelljs");
const schemas = $.find("schemas").filter(name => { return name.match(/.*\.schema\.json$/)});
const extensions = $.find("extensions").filter(name => { return name.match(/.*\.schema\.json$/)});
const examples = $.find("schemas").filter(name => { return name.match(/.*\.example\.[0-9]+\.json$/)});
const invalids = $.find("schemas").filter(name => { return name.match(/.*\.invalid\.[0-9]+\.json$/)});
const invalid = [];
let missing = 0;
schemas.forEach(schema => {
const directory = schema.replace(/\.schema\.json$/,"");
const myExamples = examples.filter(example => {
return example.indexOf(directory + ".example.") >= 0;
});
const myInvalids = invalids.filter(example => {
return example.indexOf(directory + ".invalid.") >= 0;
});
if (myExamples.length==0) {
console.error(schema + " has no examples");
missing++;
} else {
myExamples.forEach(example => {
//console.log("Validating " + example + " against " + schema + " and " + (schemas.length - 1) + " other schemas");
const result = $.exec("ajv validate --errors=text --all-errors -s " + schema + " -d " + example + " -r " + schemas.join(" -r "), {silent: true} );
if (result.code!=0) {
invalid.push({
schema: schema,
example: example,
result: result
});
console.error("Example " + example + " does not validate against " + schema + " and " + (schemas.length - 1) + " other schemas");
console.error(result.stderr);
console.error(result.stdout);
}
});
}
myInvalids.forEach(example => {
//console.log("Validating " + example + " against " + schema + " and " + (schemas.length - 1) + " other schemas");
const result = $.exec("ajv validate --errors=text --all-errors -s " + schema + " -d " + example + " -r " + schemas.join(" -r "), {silent: true} );
if (result.code==0) {
invalid.push({
schema: schema,
example: example,
result: result
});
console.error("Invalid example " + example + " validates against " + schema + " and " + (schemas.length - 1) + " other schemas");
console.error(result.stderr);
console.error(result.stdout);
}
});
});
if (invalid.length==0&&missing==0) {
console.log("All examples validated.");
} else if (missing==0) {
console.error("There have been " + invalid.length + " validation errors");
} else {
console.error("There have been " + invalid.length + " validation errors and " + missing + " missing examples.");
}
$.exit(invalid.length);