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
Good day, I have observed a strange behavior when using ajv-errors with singleError flag turned on. Honestly, I can't remember why even it was turned on in my code but when I turn it off, this unexpected behavior stops.
The code below is the minimum reproducible example for the issue I am describing. I had a fairly complex schema but I have simplified to the most basic example I could to illustrate the issue.
When I have two errorMessage properties, set as follows - one in the top level and the other in one of the fields, an extraneous empty error is reported.
(In my case there were a lot more).
I hope you'd shed some light on this unexpected behavior. Many thanks!
Code
constAJV=require('ajv').default;constajvErrors=require('ajv-errors');constvalidator=newAJV({allErrors: true});// Add AJV errors with singleError: trueajvErrors(validator,{singleError:true});validator.addSchema({$id: 'pizzaOrder',type:'object',additionalProperties: false,errorMessage:{additionalProperties:'Pizza order is invalid'},properties:{price:{type:'number'},toppings:{type:'object',additionalProperties: false,errorMessage: {_: 'Unsupported topping'},properties: {pineapple:{type: 'boolean'}}}}});validator.validate('pizzaOrder',{somethingBad: true,toppings:{pineapple:true}});console.log(JSON.stringify(validator.errors,null,2));;
Expected Result:
Since I have deliberately put an additionalProperty called somethingBad I would expect it to be reported as follows:
But actually, as highlighted below, there's an extra error that creeps in with an empty message and empty params.errors for toppings which actually is totally valid.
Package Versions:
Tested the following combinations:
[email protected]
with[email protected]
[email protected]
with[email protected]
Background
Good day, I have observed a strange behavior when using
ajv-errors
withsingleError
flag turned on. Honestly, I can't remember why even it was turned on in my code but when I turn it off, this unexpected behavior stops.The code below is the minimum reproducible example for the issue I am describing. I had a fairly complex schema but I have simplified to the most basic example I could to illustrate the issue.
When I have two
errorMessage
properties, set as follows - one in the top level and the other in one of the fields, an extraneous empty error is reported.(In my case there were a lot more).
I hope you'd shed some light on this unexpected behavior. Many thanks!
Code
Expected Result:
Since I have deliberately put an
additionalProperty
calledsomethingBad
I would expect it to be reported as follows:Actual Result:
But actually, as highlighted below, there's an extra error that creeps in with an empty message and empty
params.errors
fortoppings
which actually is totally valid.Temporal Workarounds:
Currently I have turned of
singleError
completely, hopefully it won't affect my other schema's error reportsajvErrors(validator, { - singleError:true // removed });
Another thing I have noticed, which may aid finding the issue is that when I did changed the schema this way:
The problem went away too. In my case it's not possible however, since I have other error keyword in my full example.
Let me know if any clarifications are required
The text was updated successfully, but these errors were encountered: