From e1544136da1357d11a4b6b160251bb6731350884 Mon Sep 17 00:00:00 2001 From: Albert Mink Date: Tue, 12 Sep 2023 09:18:15 +0200 Subject: [PATCH] [Refactor] Update python-based JSON validation (#554) * no need to specify the draft number * rename exceptions --- json-validator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/json-validator.py b/json-validator.py index 9740d4195..bb2c04a11 100644 --- a/json-validator.py +++ b/json-validator.py @@ -1,6 +1,6 @@ import json import jsonschema -from jsonschema import Draft7Validator +from jsonschema import validate from jsonschema import exceptions import os import glob @@ -25,11 +25,11 @@ def validate_json( schema, instance ): json_schema = decode_json( schema ) json_instance = decode_json( instance ) try: - Draft7Validator(json_schema).validate(json_instance) - except jsonschema.exceptions.ValidationError as exVal: - msg_errors.append(f"::error file={instance},line=1,col=1::{exVal.message} in {instance}") - except jsonschema.exceptions.SchemaError as error_ex: - msg_errors.print(f"::error file={instance},line=1,col=1::{error_ex.message} in {instance}") + validate( instance=json_instance, schema=json_schema) + except jsonschema.exceptions.ValidationError as ex_validation: + msg_errors.append(f"::error file={instance},line=1,col=1::{ex_validation.message} in {instance}") + except jsonschema.exceptions.SchemaError as ex_schema: + msg_errors.print(f"::error file={instance},line=1,col=1::{ex_schema.message} in {instance}") else: #print(f"::set-output name={os.path.basename(instance).ljust(31)} valid instance of schema {os.path.basename(schema)}" ) print( "valid: " + os.path.basename(schema) + "; " + os.path.basename(instance))