-
Notifications
You must be signed in to change notification settings - Fork 266
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
Provide path to schema in ValidationError #365
Comments
@ri0ter validate("instance", {type:"number"}).errors[0].name // "type" |
Not really, for the schema I mentioned in my first message, with input:
I get 3 errors:
As you can see you cannot differentiate what's the source of first and last error. |
Can you please describe the exact information you're expecting? Maybe you're looking for the "path" property? An empty array indicates an error in the root. The "foo" item indicates it is within that property in the instance. |
Or if you need to know which subschema is applied, the "schema" property in the error is a reference to the original schema. |
Well, the path property describes the instance and subschema is not telling me where it came from, I could try to match the subschema, but that would require deep compare and doesn't guarantee me what I search for. |
@ri0ter Ok, that makes sense. Let's call this property "schemaPath" and have it work similar to "path". The best you can do right now is you can use strict equality const schema = {
type: 'object',
properties: {
foo: { type: 'string', minLength: 2 },
bar: { type: 'array' },
},
allOf: [
{
properties: {
foo: {
minLength: 1,
},
},
}
]
};
const result = validate({
foo: '',
}, schema);
result.errors[0].schema === schema.properties.foo; // true
result.errors[0].schema === schema.allOf[0].properties.foo; // false |
It would be nice to include source of an error referring to schema.
So for e.g. in following schema it would be easy to say where it came from:
At the moment, the schema will tell you that the problem is with the length of the value
foo
, but it's hard to tell which rule triggered actual error.The text was updated successfully, but these errors were encountered: