voxpupuli / json-schema

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

"additionalProperties: false" is ignored if type specified in array #404

Open elasti-ron opened 6 years ago

elasti-ron commented 6 years ago

Given the object

object = {
  "a_string": "this property is allowed by the schema",
  "an_extra_string": "the schema does not allow this property"
}

The following schema should raise a validation error but doen't:

// should raise error but doesn't
{
  "type": [ "object", "null" ],
  "properties": {
    "a_string": {
      "type": "string"
    }
  },
  "additionalProperties": false
}

This occurs even if only a single type is specified in the array of type options:

// should raise error but doesn't
{
  "type": [ "object" ],
  "properties": {
    "a_string": {
      "type": "string"
    }
  },
  "additionalProperties": false
}

Note that this does not occur when the type is specified directly and not in an array. In other words, the following schema does raise the expected error:

// raises error as expected
{
  "type": "object",
  "properties": {
    "a_string": {
      "type": "string"
    }
  },
  "additionalProperties": false
}

This issue may be related to #369