Skip to content

Commit

Permalink
fix(core): anyOf schema validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
dmk1111 committed Feb 2, 2023
1 parent 8477607 commit 254e2e8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 32 additions & 0 deletions packages/nx/src/utils/params.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/nx/src/utils/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,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)
Expand Down Expand Up @@ -337,7 +337,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) => {
Expand Down

0 comments on commit 254e2e8

Please sign in to comment.