Merge pull request #256 from JakubOnderka/fix-invalid-taxonomy

fix: Better validation for taxonomy files
pull/257/head v2.4.163
Alexandre Dulaunoy 2022-09-25 17:25:17 +02:00 committed by GitHub
commit b44753d57a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

18
validate_all.py Normal file
View File

@ -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)

View File

@ -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