jsen icon indicating copy to clipboard operation
jsen copied to clipboard

oneOf with empty enum fails validation

Open pcflmb opened this issue 7 years ago • 1 comments

Issue

Validation always fails when an empty enum validation is included inside of a oneOf validation.

Empty enum's are allowed in the spec (http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.23), even though they are discouraged.

Example

const jsen = require('jsen')
const fail_schema = {
  "oneOf": [{
    "additionalProperties": false,
    "required": ["hour", "minute"],
    "type": "object",
    "properties": {
      "minute": {
        "minimum": 0,
        "type": "integer",
        "maximum": 59
      },
      "hour": {
        "minimum": 9,
        "type": "integer",
        "maximum": 9
      }
    }
  }, {
    "additionalProperties": false,
    "required": ["hour", "minute"],
    "type": "object",
    "properties": {
      "minute": {
        "minimum": 0,
        "type": "integer",
        "maximum": 31
      },
      "hour": {
        "minimum": 10,
        "type": "integer",
        "maximum": 10
      }
    }
  }, {
    "additionalProperties": false,
    "required": ["hour", "minute"],
    "type": "object",
    "properties": {
      "minute": {
        "minimum": 0,
        "type": "integer",
        "maximum": 59
      },
      "hour": {
        "enum": [],
        "type": "integer"
      }
    }
  }],
  "type": "object"
}

const validate = jsen(fail_schema)
validate({"hour":10,"minute":0}) // false, but should be true
validate({"hour":9,"minute":0}) // false, but should be true

pcflmb avatar Sep 26 '17 20:09 pcflmb

I'll try to look into making a PR to fix this

pcflmb avatar Sep 26 '17 20:09 pcflmb