Skip to content

Commit 977fccf

Browse files
committed
Suppress excessive unevaluated errors
1 parent f836214 commit 977fccf

File tree

4 files changed

+104
-4
lines changed

4 files changed

+104
-4
lines changed

lib/keywords/unevaluatedItems.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ const interpret = ([schemaUrl, unevaluatedItems], instance, context) => {
1919
return true;
2020
}
2121
const evaluatedItemsPlugin = new EvaluatedItemsPlugin(schemaUrl);
22-
Validation.interpret(schemaUrl, instance, {
22+
if (!Validation.interpret(schemaUrl, instance, {
2323
...context,
2424
plugins: [...context.ast.plugins, evaluatedItemsPlugin]
25-
});
25+
})) {
26+
return true;
27+
}
2628
const evaluatedItems = evaluatedItemsPlugin.evaluatedItems;
2729

2830
let isValid = true;

lib/keywords/unevaluatedProperties.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ const interpret = ([schemaUrl, unevaluatedProperties], instance, context) => {
1919
return true;
2020
}
2121
const evaluatedPropertiesPlugin = new EvaluatedPropertiesPlugin(schemaUrl);
22-
Validation.interpret(schemaUrl, instance, {
22+
if (!Validation.interpret(schemaUrl, instance, {
2323
...context,
2424
plugins: [...context.ast.plugins, evaluatedPropertiesPlugin]
25-
});
25+
})) {
26+
return true;
27+
}
2628
const evaluatedProperties = evaluatedPropertiesPlugin.evaluatedProperties;
2729

2830
let isValid = true;

lib/output-basic.spec.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,28 @@ describe("Basic Output Format", () => {
645645
});
646646
});
647647

648+
test("invalid - doesn't apply if the schema fails", async () => {
649+
registerSchema({
650+
properties: {
651+
foo: true,
652+
bar: false
653+
},
654+
unevaluatedProperties: false
655+
}, schemaUri, dialectUri);
656+
const output = await validate(schemaUri, { foo: 42, bar: true, baz: null }, BASIC);
657+
658+
expect(output).to.eql({
659+
valid: false,
660+
errors: [
661+
{
662+
keyword: "https://json-schema.org/evaluation/validate",
663+
absoluteKeywordLocation: `${schemaUri}#/properties/bar`,
664+
instanceLocation: "#/bar"
665+
}
666+
]
667+
});
668+
});
669+
648670
test("invalid - schema", async () => {
649671
registerSchema({
650672
unevaluatedProperties: { type: "string" }
@@ -705,6 +727,25 @@ describe("Basic Output Format", () => {
705727
});
706728
});
707729

730+
test("invalid - doesn't apply if the schema fails", async () => {
731+
registerSchema({
732+
prefixItems: [true, false],
733+
unevaluatedItems: false
734+
}, schemaUri, dialectUri);
735+
const output = await validate(schemaUri, [42, true, null], BASIC);
736+
737+
expect(output).to.eql({
738+
valid: false,
739+
errors: [
740+
{
741+
keyword: "https://json-schema.org/evaluation/validate",
742+
absoluteKeywordLocation: `${schemaUri}#/prefixItems/1`,
743+
instanceLocation: "#/1"
744+
}
745+
]
746+
});
747+
});
748+
708749
test("valid", async () => {
709750
registerSchema({ unevaluatedItems: false }, schemaUri, dialectUri);
710751
const output = await validate(schemaUri, [], BASIC);

lib/output-detailed.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,35 @@ describe("Detailed Output Format", () => {
788788
});
789789
});
790790

791+
test("invalid - doesn't apply if the schema fails", async () => {
792+
registerSchema({
793+
properties: {
794+
foo: true,
795+
bar: false
796+
},
797+
unevaluatedProperties: false
798+
}, schemaUri, dialectUri);
799+
const output = await validate(schemaUri, { foo: 42, bar: true, baz: null }, DETAILED);
800+
801+
expect(output).to.eql({
802+
valid: false,
803+
errors: [
804+
{
805+
keyword: "https://json-schema.org/keyword/properties",
806+
absoluteKeywordLocation: `${schemaUri}#/properties`,
807+
instanceLocation: "#",
808+
errors: [
809+
{
810+
keyword: "https://json-schema.org/evaluation/validate",
811+
absoluteKeywordLocation: `${schemaUri}#/properties/bar`,
812+
instanceLocation: "#/bar"
813+
}
814+
]
815+
}
816+
]
817+
});
818+
});
819+
791820
test("valid", async () => {
792821
registerSchema({ unevaluatedProperties: false }, schemaUri, dialectUri);
793822
const output = await validate(schemaUri, {}, DETAILED);
@@ -844,6 +873,32 @@ describe("Detailed Output Format", () => {
844873
});
845874
});
846875

876+
test("invalid - doesn't apply if the schema fails", async () => {
877+
registerSchema({
878+
prefixItems: [true, false],
879+
unevaluatedItems: false
880+
}, schemaUri, dialectUri);
881+
const output = await validate(schemaUri, [42, true, null], DETAILED);
882+
883+
expect(output).to.eql({
884+
valid: false,
885+
errors: [
886+
{
887+
keyword: "https://json-schema.org/keyword/prefixItems",
888+
absoluteKeywordLocation: `${schemaUri}#/prefixItems`,
889+
instanceLocation: "#",
890+
errors: [
891+
{
892+
keyword: "https://json-schema.org/evaluation/validate",
893+
absoluteKeywordLocation: `${schemaUri}#/prefixItems/1`,
894+
instanceLocation: "#/1"
895+
}
896+
]
897+
}
898+
]
899+
});
900+
});
901+
847902
test("valid", async () => {
848903
registerSchema({ unevaluatedItems: false }, schemaUri, dialectUri);
849904
const output = await validate(schemaUri, [], DETAILED);

0 commit comments

Comments
 (0)