Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions bowtie_jschon.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def cmd_dialect(self, dialect):
self._metaschema_uri = jschon.URI(dialect)
return dict(ok=self._metaschema_uri in VOCABULARIES)

def cmd_run(self, case, seq):
def cmd_run(self, case, seq, output):
assert self._started, "Not started!"
try:
catalog = jschon.create_catalog(
Expand All @@ -104,7 +104,25 @@ def cmd_run(self, case, seq):

for test in case["tests"]:
result = schema.evaluate(jschon.JSON(test["instance"]))
results.append({"valid": result.valid})

if output == "annotations":
basic_output = result.output("basic")
annotations = []
for entry in basic_output.get("annotations", []):
keyword_location = entry["keywordLocation"]
keyword = keyword_location.rsplit("/", 1)[-1]
annotations.append({
"keyword": keyword,
"instanceLocation": entry["instanceLocation"],
"keywordLocation": "#" + keyword_location,
"annotation": entry["annotation"],
})
results.append({
"valid": result.valid,
"annotations": annotations,
})
else:
results.append({"valid": result.valid})

return dict(seq=seq, results=results)
except Exception:
Expand Down
Loading