diff --git a/packages/nx/src/utils/params.spec.ts b/packages/nx/src/utils/params.spec.ts index 2dbed648579b4..b9528605264c6 100644 --- a/packages/nx/src/utils/params.spec.ts +++ b/packages/nx/src/utils/params.spec.ts @@ -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( diff --git a/packages/nx/src/utils/params.ts b/packages/nx/src/utils/params.ts index d51be2741a7bf..c9ab3b783a88e 100644 --- a/packages/nx/src/utils/params.ts +++ b/packages/nx/src/utils/params.ts @@ -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) => {