voxpupuli/json-schema

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

elasti-ron opened this issue · 0 comments

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