Skip to content

Commit

Permalink
Fix additionalProperties can handle true as value #41 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
aboutlo authored Aug 26, 2019
1 parent ba1b9be commit c0b2a95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/ObjectSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},

/**
Expand Down
10 changes: 10 additions & 0 deletions src/ObjectSchema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c0b2a95

Please sign in to comment.