fix(core): anyOf should validate if at least 1 condition passes (#14769)
Co-authored-by: AgentEnder <craigorycoppola@gmail.com>
This commit is contained in:
parent
db0fd2f453
commit
c3ba5ab66f
@ -877,6 +877,38 @@ describe('params', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
it('should not throw if one of the anyOf conditions is met', () => {
|
||||
expect(() =>
|
||||
validateOptsAgainstSchema(
|
||||
{
|
||||
a: true,
|
||||
},
|
||||
|
||||
{
|
||||
properties: {
|
||||
a: {
|
||||
type: 'boolean',
|
||||
},
|
||||
|
||||
b: {
|
||||
type: 'boolean',
|
||||
},
|
||||
},
|
||||
|
||||
anyOf: [
|
||||
{
|
||||
required: ['a'],
|
||||
},
|
||||
|
||||
{
|
||||
required: ['b'],
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('should throw if found an unknown property', () => {
|
||||
expect(() =>
|
||||
validateOptsAgainstSchema(
|
||||
|
||||
@ -234,7 +234,7 @@ export function validateObject(
|
||||
errors.push(e);
|
||||
}
|
||||
}
|
||||
if (errors.length > 0) {
|
||||
if (errors.length === schema.anyOf.length) {
|
||||
throw new Error(
|
||||
`Options did not match schema. Please fix any of the following errors:\n${errors
|
||||
.map((e) => ' - ' + e.message)
|
||||
@ -339,7 +339,7 @@ function validateProperty(
|
||||
|
||||
if (schema.allOf) {
|
||||
if (!Array.isArray(schema.allOf))
|
||||
throw new Error(`Invalid schema file. anyOf must be an array.`);
|
||||
throw new Error(`Invalid schema file. allOf must be an array.`);
|
||||
|
||||
if (
|
||||
!schema.allOf.every((r) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user