-
Notifications
You must be signed in to change notification settings - Fork 46
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 with different path got overwritten #81
Comments
@a1png it would be really helpful if you can provide an example 🙂 |
@torifat Here is an example: const schema = {
type: 'object',
properties: {
test: {
anyOf: [
{
type: "object",
properties: {
a: {
type: "string",
enum: ["test_1", "test_2"]
}
},
required: [ "a" ],
"additionalProperties": false
},
{
type: "object",
properties: {
a: {
type: "string",
enum: ["b"]
},
b: {
type: "string",
enum: ["test_1"]
}
},
required: ["a", "b"],
"additionalProperties": false
}
],
},
},
"additionalProperties": false
}; The validated data: const test_data = {
test: {
a: "wrong input",
}
} The error in ajv.erros: [ { keyword: 'enum',
dataPath: '/test/a',
schemaPath: '#/properties/test/anyOf/0/properties/a/enum',
params: { allowedValues: [Array] },
message: 'should be equal to one of the allowed values' },
{ keyword: 'enum',
dataPath: '/test/a',
schemaPath: '#/properties/test/anyOf/1/properties/a/enum',
params: { allowedValues: [Array] },
message: 'should be equal to one of the allowed values' },
{ keyword: 'required',
dataPath: '/test',
schemaPath: '#/properties/test/anyOf/1/required',
params: { missingProperty: 'b' },
message: 'should have required property \'b\'' },
{ keyword: 'anyOf',
dataPath: '/test',
schemaPath: '#/properties/test/anyOf',
params: {},
message: 'should match some schema in anyOf' } ] The error message returned from the library: [ '/test should have required property \'b\'' ] |
@torifat After looking into the code, I found that the problem is actually not with the tree generation, but in /**
* If there is a `required` error then we can just skip everythig else.
* And, also `required` should have more priority than `anyOf`. @see #8
*/
(0, _utils.getErrors)(root).forEach(error => {
if ((0, _utils.isRequiredError)(error)) {
root.errors = [error];
root.children = {};
}
}); So in this situation, the error tree generated is: {
"children": {
"/test": {
"children": {
"/a": {
"children": {},
"errors": [
{
"keyword": "enum",
"dataPath": "/test/a",
"schemaPath": "#/properties/test/anyOf/0/properties/a/enum",
"params": {
"allowedValues": [
"test_1",
"test_2"
]
},
"message": "should be equal to one of the allowed values"
},
{
"keyword": "enum",
"dataPath": "/test/a",
"schemaPath": "#/properties/test/anyOf/1/properties/a/enum",
"params": {
"allowedValues": [
"b"
]
},
"message": "should be equal to one of the allowed values"
}
]
}
},
"errors": [
{
"keyword": "required",
"dataPath": "/test",
"schemaPath": "#/properties/test/anyOf/1/required",
"params": {
"missingProperty": "b"
},
"message": "should have required property 'b'"
},
{
"keyword": "anyOf",
"dataPath": "/test",
"schemaPath": "#/properties/test/anyOf",
"params": {},
"message": "should match some schema in anyOf"
}
]
}
}
} When 'required' is detected under /test, the errors under /test/a is removed. However, in this case |
When there are errors of more than one different paths in ajv error list, the
helpers.makeTree
function will overwrite the previous errors in the path with the new one in the reduce function:Is this an intended design?
The text was updated successfully, but these errors were encountered: