IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit 2cf30200 authored by Joshua Gay's avatar Joshua Gay 💾
Browse files

Merge branch 'main' into 'main'

Update to validator to fix the bug after the schemas were updated to have the id element

See merge request omh/1752!3
parents 01648fe8 20fdf22c
Pipeline #154 passed with stage
in 17 seconds
......@@ -24,6 +24,7 @@ import os
import json
from jsonschema import validate, RefResolver
import jsonschema
import traceback
schema_dir = 'sc/'
samples_dir = 'sd/'
......@@ -32,6 +33,21 @@ schema_files = [f for f in os.listdir(schema_dir) if f.endswith('.json') and '
sample_files = [f for f in os.listdir(samples_dir) if f.endswith('.json') and 'survey' not in f]
isError = False
store = {}
for f in schema_files:
key = 'https://w3id.org/ieee/ieee-1752-schema/' + f
fp = open('sc/'+f, 'r')
json_schema = json.load(fp)
fp.close()
fn = f
splits = fn.split('-')
index = fn.find(splits[-1])
name_without_version = fn[:index-1]
key1 = 'https://w3id.org/ieee/ieee-1752-schema/' + name_without_version + '.json'
store[key] = json_schema
store[key1] = json_schema
for sample in sample_files:
index = sample.find('sample-data')
......@@ -42,23 +58,27 @@ for sample in sample_files:
index = schema.find(splits[-1])
if schema_start == schema[:index]:
schema_fp = open(schema_dir+schema, 'r')
schema_fp.seek(0)
instance_fp = open(samples_dir+sample, 'r')
instance_fp.seek(0)
instance = json.load(instance_fp)
schema_json = json.load(schema_fp)
schema_path = 'file://{0}/'.format(os.path.dirname(os.path.realpath(schema_fp.name)))
resolver = RefResolver(schema_path, schema_json)
resolver = RefResolver(schema_path, schema_json, store)
try:
validate(instance, schema_json, resolver=resolver)
except Exception as e:
msg = 'Validation failed on instance {0} for schema {1}'.format(sample, schema)
print(msg)
print(e)
traceback.print_exc()
isError = True
schema_fp.close()
instance_fp.close()
if isError: exit(1)
print('Done!')
exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment