From ac93571dbccf1e220c58cddbae3d98d99d1f0517 Mon Sep 17 00:00:00 2001 From: Jakub Onderka Date: Sun, 25 Sep 2022 17:06:00 +0200 Subject: [PATCH] fix: Better validation for taxonomy files --- validate_all.py | 18 ++++++++++++++++++ validate_all.sh | 7 +------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 validate_all.py diff --git a/validate_all.py b/validate_all.py new file mode 100644 index 0000000..8d8359b --- /dev/null +++ b/validate_all.py @@ -0,0 +1,18 @@ +import sys +import glob +import json +from jsonschema import validate + +schema = json.load(open("schema.json", "r")) + +for taxonomy_file in glob.glob('./*/machinetag.json'): + print("Checking {}".format(taxonomy_file)) + taxonomy = json.load(open(taxonomy_file, "r")) + validate(instance=taxonomy, schema=schema) + + if "values" in taxonomy: + predicates = [predicate["value"] for predicate in taxonomy["predicates"]] + for value in taxonomy["values"]: + if value["predicate"] not in predicates: + print("ERROR: Predicate `{}` is missing".format(value["predicate"])) + sys.exit(1) \ No newline at end of file diff --git a/validate_all.sh b/validate_all.sh index 0f4a1f0..025ccdf 100755 --- a/validate_all.sh +++ b/validate_all.sh @@ -20,11 +20,6 @@ if ! [ $((directories-2)) -eq $manifest_entries ]; then exit 1 fi -for dir in */machinetag.json -do - echo -n "${dir}: " - jsonschema -i ${dir} schema.json - echo '' -done +python3 validate_all.py jsonschema -i mapping/mapping.json schema_mapping.json