Open
Description
A question regarding oneOf
in filter
operation.
Given the example
const validator = require('is-my-json-valid');
const schema = {
type : 'object',
additionalProperties : false,
properties : {
bar : {
type : 'object'
},
baz : {
type : 'object'
}
},
oneOf : [{
properties : {
bar : {
type : 'object',
additionalProperties : false,
properties : {
a : {
type : 'array',
items : {
type : 'number'
}
}
}
},
baz : {
type : 'object',
additionalProperties : false,
properties : {
z : {
type : 'object'
}
}
}
}
}, {
properties : {
bar : {
type : 'object',
additionalProperties : false,
properties : {
a : {
type : 'array',
items : {
type : 'number'
}
},
b : {
type : 'array',
items : {
type : 'number'
}
}
}
},
baz : {
type : 'object',
additionalProperties : false,
properties : {
y : {
type : 'object'
}
}
}
}
}]
};
const obj = {
bar : {
a : [1],
b : [1]
},
baz : {
z : {}
}
};
const filter = validator.filter(schema);
const validate = validator(schema);
console.log(filter(obj));
// { bar: { a: [ 1 ], b: [ 1 ] }, baz: { z: {} } }
validate(obj);
console.log(validate.errors);
//[ { field: 'data',
// message: 'no (or more than one) schemas match' } ]
It seems that filter ignores the oneOf
completely.
Is this an expected behaviour?
Metadata
Metadata
Assignees
Labels
No labels