voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.52k stars 242 forks source link

AdditionalProperties not being applied when value could be object or array #369

Open derigible opened 7 years ago

derigible commented 7 years ago

Given the following schema:

{
   type: 'object',
   required: ['value'],
   properties: {
      value: {
         type: %w(array object),
        items: {
            type: %w(string boolean number)
        },
        properties: { a: { type: 'string' },
        additionalProperties: false
     }
  }
}

the additionalProperties does not get applied. The sample data I am using is:

{ value: { b: 1, a: 'a'} }

The extra b property should have failed the schema. Additionally, if you change the schema to look as follows:

{
   type: 'object',
   required: ['value'],
   properties: {
      value: {
         type: %w(array object),
        items: {
            type: %w(string boolean number)
        },
        properties: { a: { type: 'string' },
        additionalProperties: { type: 'string' }
     }
  }
}

does not validate against the following:

{ value: { b: 1, a: 'a'} }

where b should fail as it is a zero.

derigible commented 7 years ago

Note that the array validation does work with this schema.

derigible commented 7 years ago

Finally, should the following schema

{
   type: 'object',
   required: ['value'],
   properties: {
      value: {
         type: %w(array object),
        items: {
            type: %w(string boolean number)
        },
        additionalProperties: { type: 'string' }
     }
  }
}

also supposed to throw an error on { value: { b: 1, a: 'a'} } ? Because currently it does not.