diff --git a/src/ObjectSchema.js b/src/ObjectSchema.js index c9871bb..fc3aea5 100644 --- a/src/ObjectSchema.js +++ b/src/ObjectSchema.js @@ -47,21 +47,23 @@ const ObjectSchema = ({ schema = initialState, ...options } = {}) => { */ additionalProperties: value => { - if (typeof value !== 'boolean' && !isFluentSchema(value)) - throw new Error("'additionalProperties' must be a boolean or a S") - if (value === false) { + if (typeof value === 'boolean') { return setAttribute({ schema, ...options }, [ 'additionalProperties', - false, + value, 'object', ]) } - const { $schema, ...rest } = value.valueOf() - return setAttribute({ schema, ...options }, [ - 'additionalProperties', - { ...rest }, - 'array', - ]) + if (isFluentSchema(value)) { + const { $schema, ...rest } = value.valueOf() + return setAttribute({ schema, ...options }, [ + 'additionalProperties', + { ...rest }, + 'array', + ]) + } + + throw new Error("'additionalProperties' must be a boolean or a S") }, /** diff --git a/src/ObjectSchema.test.js b/src/ObjectSchema.test.js index d12e86c..9b76fc3 100644 --- a/src/ObjectSchema.test.js +++ b/src/ObjectSchema.test.js @@ -292,6 +292,16 @@ describe('ObjectSchema', () => { }) describe('additionalProperties', () => { + it('true', () => { + const value = true + expect( + ObjectSchema() + .additionalProperties(value) + .prop('prop') + .valueOf().additionalProperties + ).toEqual(value) + }) + it('false', () => { const value = false expect(