Skip to content

Commit

Permalink
Improve basic output
Browse files Browse the repository at this point in the history
The goal was the remove failed `if` results from the output. I also
can't find any reason to include the evaluation nodes in the output. I
had a reason for including them at first, but I can't reproduce any
problem now, so there's no reason to keep it anymore.
  • Loading branch information
jdesrosiers committed Jul 23, 2024
1 parent 916366a commit 8a29c88
Show file tree
Hide file tree
Showing 20 changed files with 14 additions and 29 deletions.
12 changes: 10 additions & 2 deletions annotations/annotated-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export const annotation = (node, keyword, dialect = defaultDialectId) => {
const keywordUri = getKeywordId(keyword, dialect);

let currentNode = node.root;
const errors = Object.keys(node.root.errors);
const errors = [...invalidSchemas(currentNode)];
for (let segment of JsonPointer.pointerSegments(node.pointer)) {
segment = segment === "-" && Instance.typeOf(currentNode) === "array" ? Instance.length(currentNode) : segment;
currentNode = Instance.step(segment, currentNode);
errors.push(...Object.keys(currentNode.errors));
errors.push(...invalidSchemas(currentNode));
}

const annotations = [];
Expand All @@ -33,6 +33,14 @@ export const annotation = (node, keyword, dialect = defaultDialectId) => {
return annotations;
};

const invalidSchemas = function* (node) {
for (const error in node.errors) {
if (node.errors[error] === "https://json-schema.org/evaluation/validate") {
yield error;
}
}
};

export const annotatedWith = (instance, keyword, dialectId = defaultDialectId) => {
const nodes = [];

Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/077aa87e28ba586d7bf9bed115391f1c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/0968dc2e0f7f9d0fb95859803d130bcf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
2 changes: 0 additions & 2 deletions bundle/snapshots/1839eb3563f23d86ce8b82968a925bc6
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/string#/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/string#": "https://json-schema.org/evaluation/validate",
"https://bundler.hyperjump.io/main#/if/$ref": "https://json-schema.org/keyword/ref",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/2c8965601028dfe1a687613b46f8ca6f
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/38e3d0fe6da335bf3be09d75dec08db7
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate",
"https://test.json-schema.org/short-string#/maxLength": "https://json-schema.org/keyword/maxLength",
"https://test.json-schema.org/short-string#": "https://json-schema.org/evaluation/validate",
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/4e7597c82e2c012d71fc5af69aae016e
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/54e7e0f163e8df9b57359ebfaa226a94
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/590bff4705440957e5a8b2ca6d90f7c1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/6183fe3ae5936b60f09dda163ec612f0
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/7add5d300125d4643ff534a1883bb27a
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {}
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/8a4bd1aa80fd36bbc9f7625ed7d27c08
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/string#/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/string#": "https://json-schema.org/evaluation/validate"
},
"annotations": {
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/9b8b596cd673f6acb6020628b64323f5
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate",
"https://test.json-schema.org/short-string#/maxLength": "https://json-schema.org/keyword/maxLength",
"https://test.json-schema.org/short-string#": "https://json-schema.org/evaluation/validate",
Expand Down
2 changes: 0 additions & 2 deletions bundle/snapshots/a6a61ea3cecf6acf4c700df42163592e
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/string#/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/string#": "https://json-schema.org/evaluation/validate",
"https://bundler.hyperjump.io/main#/if/$ref": "https://json-schema.org/keyword/ref",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/c0332fa29559fa9f027c2590e4178f98
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate",
"https://test.json-schema.org/short-string#/maxLength": "https://json-schema.org/keyword/maxLength",
"https://test.json-schema.org/short-string#": "https://json-schema.org/evaluation/validate",
Expand Down
2 changes: 0 additions & 2 deletions bundle/snapshots/c26ca442e0696b06b53a6c155ec67eb0
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/string#/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/string#": "https://json-schema.org/evaluation/validate",
"https://bundler.hyperjump.io/main#/if/$ref": "https://json-schema.org/keyword/ref",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate"
},
"annotations": {
Expand Down
1 change: 0 additions & 1 deletion bundle/snapshots/e66fdfb1ce638e361cc818449c04d005
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"#": {
"errors": {
"https://bundler.hyperjump.io/main#/if/type": "https://json-schema.org/keyword/type",
"https://bundler.hyperjump.io/main#/if": "https://json-schema.org/evaluation/validate",
"https://test.json-schema.org/short-string#/maxLength": "https://json-schema.org/keyword/maxLength",
"https://test.json-schema.org/short-string#": "https://json-schema.org/evaluation/validate",
Expand Down
4 changes: 2 additions & 2 deletions lib/keywords/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const id = "https://json-schema.org/keyword/if";

const compile = (schema, ast) => Validation.compile(schema, ast);

const interpret = (ifSchema, instance, ast, dynamicAnchors, quiet) => {
Validation.interpret(ifSchema, instance, ast, dynamicAnchors, quiet);
const interpret = (ifSchema, instance, ast, dynamicAnchors) => {
Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true);
return true;
};

Expand Down
4 changes: 1 addition & 3 deletions lib/keywords/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ const interpret = (url, instance, ast, dynamicAnchors, quiet = false) => {
}

if (!isSchemaValid) {
if (!quiet) {
instance.errors[url] = id;
}
instance.errors[url] = id;
}

instance.valid = isSchemaValid;
Expand Down
4 changes: 1 addition & 3 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ outputFormats.BASIC = (instance) => {

for (const child of Instance.allNodes(instance)) {
for (const [absoluteKeywordLocation, keyword] of Object.entries(child.errors).reverse()) {
if (!child.valid) {
if (keyword !== "https://json-schema.org/evaluation/validate" && !child.valid) {
output.errors.unshift({
keyword,
absoluteKeywordLocation,
Expand All @@ -35,8 +35,6 @@ outputFormats.BASIC = (instance) => {
}
}
}

output.errors.pop();
}

return output;
Expand Down

0 comments on commit 8a29c88

Please sign in to comment.