Skip to content

Commit c0b2a95

Browse files
authored
Fix additionalProperties can handle true as value #41 (#43)
1 parent ba1b9be commit c0b2a95

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/ObjectSchema.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,23 @@ const ObjectSchema = ({ schema = initialState, ...options } = {}) => {
4747
*/
4848

4949
additionalProperties: value => {
50-
if (typeof value !== 'boolean' && !isFluentSchema(value))
51-
throw new Error("'additionalProperties' must be a boolean or a S")
52-
if (value === false) {
50+
if (typeof value === 'boolean') {
5351
return setAttribute({ schema, ...options }, [
5452
'additionalProperties',
55-
false,
53+
value,
5654
'object',
5755
])
5856
}
59-
const { $schema, ...rest } = value.valueOf()
60-
return setAttribute({ schema, ...options }, [
61-
'additionalProperties',
62-
{ ...rest },
63-
'array',
64-
])
57+
if (isFluentSchema(value)) {
58+
const { $schema, ...rest } = value.valueOf()
59+
return setAttribute({ schema, ...options }, [
60+
'additionalProperties',
61+
{ ...rest },
62+
'array',
63+
])
64+
}
65+
66+
throw new Error("'additionalProperties' must be a boolean or a S")
6567
},
6668

6769
/**

src/ObjectSchema.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,16 @@ describe('ObjectSchema', () => {
292292
})
293293

294294
describe('additionalProperties', () => {
295+
it('true', () => {
296+
const value = true
297+
expect(
298+
ObjectSchema()
299+
.additionalProperties(value)
300+
.prop('prop')
301+
.valueOf().additionalProperties
302+
).toEqual(value)
303+
})
304+
295305
it('false', () => {
296306
const value = false
297307
expect(

0 commit comments

Comments
 (0)