2016-12-29 23:27:33 +01:00
|
|
|
#!/usr/bin/env python
|
2020-11-14 17:58:56 +01:00
|
|
|
import json, sys
|
2016-12-29 23:27:33 +01:00
|
|
|
from os import path
|
2017-07-30 13:32:10 +02:00
|
|
|
from jsonschema import Draft3Validator, RefResolver
|
2016-12-29 23:27:33 +01:00
|
|
|
|
2022-02-11 20:36:15 +01:00
|
|
|
from urllib.parse import urljoin
|
|
|
|
from urllib.request import pathname2url
|
|
|
|
|
|
|
|
def path2url(path):
|
|
|
|
return urljoin('file:', pathname2url(path))
|
|
|
|
|
2016-12-29 23:27:33 +01:00
|
|
|
print('-- validate json file')
|
|
|
|
|
|
|
|
jsonFileName = sys.argv[1]
|
|
|
|
schemaFileName = sys.argv[2]
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open(schemaFileName) as schemaFile:
|
|
|
|
with open(jsonFileName) as jsonFile:
|
2022-02-11 20:36:15 +01:00
|
|
|
schema = json.load(schemaFile)
|
|
|
|
uri = path2url('%s/schema/' % path.abspath(path.dirname(schemaFileName)))
|
|
|
|
resolver = RefResolver(uri, referrer = schema)
|
|
|
|
instance = json.load(jsonFile)
|
|
|
|
Draft3Validator(schema, resolver=resolver).validate(instance)
|
2017-02-09 20:10:57 +01:00
|
|
|
except Exception as e:
|
2016-12-29 23:27:33 +01:00
|
|
|
print('validation error: '+jsonFileName + ' '+schemaFileName+' ('+str(e)+')')
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
sys.exit(0)
|