tdegrunt / jsonschema

JSON Schema validation
Other
1.83k stars 262 forks source link

Not validating undefined inside array correctly #266

Open amotzte opened 6 years ago

amotzte commented 6 years ago

Reproduce

json={
    "common": {
        "availability": [
            undefined
        ]
    }
}
schema=
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "common": {
      "type": "object",
      "properties": {
        "availability": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "localeId": {"type": "string"},
              "startDateTime": {"type": "string", "format": "date-time"},
              "endDateTime":  {"type": "string", "format": "date-time"}
            },
            "required": [
              "localeId",
              "startDateTime",
              "endDateTime"
            ]
          }
        },}}}
}
const validate = require('jsonschema').validate;
resValidate = validate(json, schema);
> resValidate.valid
true // Expected to be false
awwright commented 4 years ago

Technically, undefined is not a valid JSON value; so the behavior is undefined. What should the behavior be?