Skip to content

Commit

Permalink
[Refactor] Update python-based JSON validation (#554)
Browse files Browse the repository at this point in the history
* no need to specify the draft number

* rename exceptions
  • Loading branch information
albertmink authored Sep 12, 2023
1 parent c0a5bf7 commit e154413
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions json-validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import jsonschema
from jsonschema import Draft7Validator
from jsonschema import validate
from jsonschema import exceptions
import os
import glob
Expand All @@ -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))
Expand Down

0 comments on commit e154413

Please sign in to comment.