jayschema
jayschema copied to clipboard
Combining oneOf + enum causes the rejection of enum fields
Hi,
Given the following schema:
var schema = {
'type': 'object',
'properties': {
'foo': {
'oneOf': [
{
'type': 'integer'
},
{
'type': {'enum': ['bar', 'baz']}
}
]
}
},
'additionalProperties': false
};
The following does not work as I would expect:
js.validate({foo: 'bar'}, schema);
More precisely, the error reads:
js.validate({foo: 'bar'}, schema)[0].subSchemaValidationErrors
{ 'sub-schema-1':
[ { [Error]
instanceContext: '#/foo',
resolutionScope: 'anon-schema://e4d7cffef264084baaaceaa96437195d3e63275c/#/properties/foo/oneOf/0',
constraintName: 'type',
constraintValue: 'integer',
testedValue: 'string' } ],
'sub-schema-2':
[ { [Error]
instanceContext: '#/foo',
resolutionScope: 'anon-schema://e4d7cffef264084baaaceaa96437195d3e63275c/#/properties/foo/oneOf/1',
constraintName: 'type',
constraintValue: [Object],
testedValue: 'string' } ] }
Apparently, the foo
property is wrongly recognized as a string
instead of one of the possible enum values.
Thanks.