Comments (9)
Thanks :)
from ajv.
you're welcome. Thanks for the motivation to improve it :)
from ajv.
On it.
from ajv.
It is a design choice for performance rather than shortcoming :) Required
keyword is validated in a single expression (conditions for each property are connected with &&), not in the loop, so ajv has no knowledge of which specific property is missing.
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.
from ajv.
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:
{
keyword: 'required',
dataPath: '.amount.value',
message: 'property value is required'
}
would allow cleaner assertions on errors like:
keyword === 'required'
dataPath === '.amount.value
from ajv.
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 :)
from ajv.
Thanks for the quick reply! This solution sounds ideal.
from ajv.
done in 0.6.1
from ajv.
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.
from ajv.
Related Issues (20)
- Ref within def does not act consistently
- JSONSchemaType $ref doesn't work in array type. HOT 5
- oneOf returns unwanted errors HOT 1
- Description key set as boolean returns error that it must be string HOT 2
- Validate and infer JSON Schema validated data type: introducing type providers HOT 3
- JTD schema parser errors on empty properties field HOT 1
- Implement x-inOrder subschema for in order or sequential processing HOT 3
- additionalProperties shouldn't affect TypeScript types from JTDDataType HOT 10
- option compile from addKeyword doesn't change on a remove and then add again HOT 1
- OneOf validation issue HOT 1
- Cannot find module 'ajv/dist/compile/codegen' HOT 4
- How can I make a property value depend on the value of another property? HOT 1
- Error using multipleOf with decimals HOT 1
- Using if/then/else fails validation HOT 2
- compileParser does not appear to support properties with type `field?: Record<string, unknown>` via `JTDSchemaType`. HOT 6
- Integers as Discriminators HOT 7
- How can I access `definitions` in schema-store using `$ref`? HOT 1
- DeprecationWarning: The punycode module is deprecated #96 HOT 2
- `maxLength` constraint checking seems to not code (Hindi) unicode characters properly HOT 7
- ajv 8.13.0 upgrade doesn't work with ajv-formats 3.0.1 with TypeScript HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ajv.