Skip to content

oneOf filter #174

Open
Open
@juneidy

Description

@juneidy

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions