Skip to content

Commit

Permalink
Add enum validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jwen-adobe committed Aug 16, 2022
1 parent 3e7fc41 commit 7bc3c7d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bin/incompatibility-check.js
Expand Up @@ -311,6 +311,29 @@ function validate(o, file) {
}
}

if (file.indexOf("../schemas/descriptors/") == -1) {//enum validation
if (o[i] && o[i].hasOwnProperty('enum') && o[i].hasOwnProperty('meta:enum')) {
var enumSet = new Set();
var metaEnumSet = new Set();

for (let j in o[i]["enum"]) {
enumSet.add(o[i]["enum"][j])
}

for (let k in o[i]["meta:enum"]) {
metaEnumSet.add(k)
}

const eqSet = (xs, ys) =>
xs.size === ys.size && [...xs].every((x) => ys.has(x));

if (!eqSet(enumSet, metaEnumSet)) {
errLogs.push(file + " validation error!!! Mismatch between enum and meta:enum for property " + i + "\n");
}
} else if (o[i] && o[i].hasOwnProperty('enum') && !o[i].hasOwnProperty('meta:enum')) {
errLogs.push(file + " validation error!!! Missing meta:enum for property " + i + "\n");
}
}

if (o[i] !== null && typeof(o[i]) == "object") {
//going one step down in the object tree!!
Expand Down

0 comments on commit 7bc3c7d

Please sign in to comment.