From 7bc3c7d97e4cacf69c69072d882320a7c20ff8d9 Mon Sep 17 00:00:00 2001 From: jwen-adobe Date: Tue, 16 Aug 2022 11:22:34 -0700 Subject: [PATCH] Add enum validation --- bin/incompatibility-check.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bin/incompatibility-check.js b/bin/incompatibility-check.js index 1c971a50e8..6067b381ee 100644 --- a/bin/incompatibility-check.js +++ b/bin/incompatibility-check.js @@ -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!!