-
-
Notifications
You must be signed in to change notification settings - Fork 886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiled validators lack dataPath field #212
Comments
That may be a bug. Could you post some example here that produces such result?
If
JavaScript is a single-threaded environment and the validation is synchronous. So while the same function can be called many times, it can't be called during its execution. So all you have to do is to re-assign errors array after validation to any variable, particularly in async environment (there is a note in readme). The existing api was copied from jsen and is-my-json-valid, the fastest validators existing at the time I was doing it. The alternative api implemented by validators of the previous generation (return result object with boolean and errors) has a substantial negative performance impact. |
Sorry, it looks like a user error. I had existing code that used Thanks for the other notes. Good points. |
That's why I think it may be some bug. Schema or not, you are passing something that is not valid, but errors should still be correct, and they are not. |
Great. I'll work up an example tomorrow and post. |
I have a very simple test case that reproduces the problem. The schema I have supplied is the same one that I used originally. I could likely be pared down to a smaller version, but I haven't attempted yet. Hope that this helps. |
Thank you. |
If I use a compiled validator and get an error, the
errors
object (associated with the validator function), has adataPath
field which has the value[object Object]
. I suspect that it is being copied in the process of validation.I also enjoyed having the
errorsText()
function to produce a helpful error message. Apparently, this feature is not afforded to compiled validation functions. That's unfortunate and unexpected (as compiled validator functions have the same needs as those invoked via theajv
instance method).Finally, for thread safety purposes (since I would expected compiled functions to be reused by many threads), why not simply return an
errors
object instead of a boolean?The text was updated successfully, but these errors were encountered: