When validating a schema that includes oneOf with a ref, an error is pushed to the final validator.errors array even if the oneOf schema passes validation. The overall validation result (true/false) is correct, but when validation fails, one of the errors is not correct.
When I inspect the compiled validator, it looks like the error from the failed $ref is pushed onto validate.errors instead of being held in suberr1 to determine later whether it should land in validate.errors depending on the overall oneOf status. See comments in code snippet below:
if ("some_level" in data && hasOwn(data, "some_level")) {
let passes0 = 0
let suberr0 = null
const sub0 = (() => {
let errorCount = 0
if (!(data.some_level === null)) {
if (suberr0 === null) suberr0 = []
suberr0.push({ keywordLocation: "#/properties/some_level/oneOf/0/const", instanceLocation: "#/some_level" })
errorCount++
}
return errorCount === 0
})()
if (sub0) passes0++
const sub1 = (() => {
let errorCount = 0
const err0 = validate.errors
const res0 = ref1(data.some_level)
const suberr1 = ref1.errors
validate.errors = err0
if (!res0) {
if (validate.errors === null) validate.errors = []
/** START: Possible reason for issue */
validate.errors.push(...suberr1.map(e => errorMerge(e, "#/properties/some_level/oneOf/1/$ref", "#/some_level")))
/** END: Possible reason for issue */
errorCount++
}
return errorCount === 0
})()
if (sub1) passes0++
if (passes0 !== 1) {
if (validate.errors === null) validate.errors = []
validate.errors.push({ keywordLocation: "#/properties/some_level/oneOf", instanceLocation: "#/some_level" })
errorCount++
}
if (passes0 === 0) {
if (suberr0) validate.errors.push(...suberr0)
}
}
When validating a schema that includes
oneOf
with aref
, an error is pushed to the finalvalidator.errors
array even if theoneOf
schema passes validation. The overall validation result (true/false) is correct, but when validation fails, one of the errors is not correct.Steps to reproduce
sample.schema.json
sample.json
main.js
Output
some_level
is reported to have an error even though it doesn't.Notes
When I inspect the compiled validator, it looks like the error from the failed
$ref
is pushed ontovalidate.errors
instead of being held insuberr1
to determine later whether it should land invalidate.errors
depending on the overalloneOf
status. See comments in code snippet below: