-
-
Notifications
You must be signed in to change notification settings - Fork 868
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
Errors for 'required' validation should include missing property #18
Comments
On it. |
It is a design choice for performance rather than shortcoming :) Having said that I agree that one wants to know what exactly is missing, not just that something is missing :) I'll see how I can improve it without damaging performance. Maybe it should be an option. Or I have another idea... Thank you for pointing it out. |
Hi, I understand performance is an important consideration, but precise error reporting is also really valuable. I'm currently building a format specification using JSONSchema, and as the multiple schemas involved are subject to many changes at this point, I've set up a test suite automating validation of valid/invalid data samples and generating a primitive documentation above it. The current error reporting of ajv forces me to make assertions on error messages, which aren't always precise, and the whole approach of relying on message strings is quite fragile. I'd really like to have something like error codes/constants along with better data paths and messages. @cdmcnamara's proposal:
would allow cleaner assertions on errors like:
|
I agree. I have a solution in mind - it will have missing properties in dataPath without affecting performance. If you use allErrors=true then each missing property will create an error (not one error as it is now). If allErrors is not passed it will return the error with the name of the first missing property. Just need a little time for that. And thanks for using it :) |
Thanks for the quick reply! This solution sounds ideal. |
done in 0.6.1 |
Thanks :) |
you're welcome. Thanks for the motivation to improve it :) |
By the way, the error message for "required" was simply listing all required properties, not just missing ones. So making assertions on it wasn't the right thing to do. |
… points to the object that is validated and not to the missing property; old (<=1.4.10 ) error reporting of dataPath for "required" keyword is available with option errorDataPath == "property"
Hi, I'm trying to get some clarity on a potential issue I'm seeing. In running the following:
I get the following:
Ideally I would like to see something more along the lines of:
I was wondering if this was an issue with my implementation / schemas or if it is a shortcoming of ajv?
Thanks in advance.
My schemas are as follows:
Party.json
Amount.json
PositiveFloatString.json
Currency.json
The text was updated successfully, but these errors were encountered: