You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"indata&&hasOwn(data,"some_level")){letpasses0=0letsuberr0=nullconstsub0=(()=>{leterrorCount=0if(!(data.some_level===null)){if(suberr0===null)suberr0=[]suberr0.push({keywordLocation: "#/properties/some_level/oneOf/0/const",instanceLocation: "#/some_level"})errorCount++}returnerrorCount===0})()if(sub0)passes0++constsub1=(()=>{leterrorCount=0consterr0=validate.errorsconstres0=ref1(data.some_level)constsuberr1=ref1.errorsvalidate.errors=err0if(!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++}returnerrorCount===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)}}
The text was updated successfully, but these errors were encountered:
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:The text was updated successfully, but these errors were encountered: