Open vladyslav2 opened 6 years ago
@vladyslav2 I think you should comment on this issue 396 in: https://github.com/json-schema-org/json-schema-spec
There is a goal to standardise a suggested implementation for the json-schema error format.
For making switching less painful we want the results to be the same, if a standard is reached then ajv will most likely also update as well.
Yes djv is the best :)
@Anthropic I'm not sure if they would understand me. I'm from my side cannot understand approach they took.
Why don't you make it in a simple way:
{
fieldPath: [{
keyword,
message,
params
}, ... ],
...
}
Instead, fieldPath is floating from one parameter to other based on the error.
I've the same issue. The first time that I try the library.
const schema = {
creds: {
required: ['username', 'password'],
properties: {
username: {
type: 'string',
},
password: {
type: 'string',
},
},
},
};
env.addSchema('creds', schema);
env.validate('creds#/creds', {});
// => { keyword: 'required', dataPath: '', schemaPath: '#/required' }
So there is no way to know what did failed? Ajv have better errors but it has such a bad implementation. The way that it works makes compiling schemas before hand pretty much useless.
Please do not do same error messages as ajv did, they are not really helpful. I'm moving away from ajv cause it's hard to understand the problem based just on error message. You have to check the source code to get useful info. And whats harder is to create user-friendly error messages. I guess with ajv it's not really possible.
I tested your library, I decide to modify a home page example, simply pass empty object to validation function:
I got in return:
With does not really useful - there is no actual name of the field which is required, which means it's not possible to build user-friendly error either.
But your library looks much easier and flexible then ajv, hope you will fix this issue!