Skip to content

Commit

Permalink
Add validator script
Browse files Browse the repository at this point in the history
  • Loading branch information
blokhin committed Jan 13, 2025
1 parent 45e34b2 commit 744c1d6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions scripts/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python

import sys
import json
import httplib2
from jsonschema import validate, Draft4Validator
from jsonschema.exceptions import ValidationError

try: input_json = sys.argv[1]
except IndexError: sys.exit("Usage: %s input_json" % sys.argv[0])

network = httplib2.Http()
response, content = network.request("http://developer.mpds.io/mpds.schema.json")
assert response.status == 200

schema = json.loads(content)
Draft4Validator.check_schema(schema)

target = json.loads(open(input_json).read())

if not target.get("npages") or not target.get("out") or target.get("error"):
sys.exit("Unexpected API response")

try:
validate(target["out"], schema)
except ValidationError, e:
raise RuntimeError(
"The item: \r\n\r\n %s \r\n\r\n has an issue: \r\n\r\n %s" % (
e.instance, e.context
)
)

0 comments on commit 744c1d6

Please sign in to comment.