voxpupuli / json-schema

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

optional attributes are not being parsed as optional #324

Closed biznickman closed 8 years ago

biznickman commented 8 years ago

I have the following schema:

{
  "type": "object",
  "required": ["twilio_account"],
  "properties": {
    "twilio_account" : {
      "type" : "object",
      "required" : [
        "twilio_account_id"
      ],
      "properties" : {
        "twilio_account_id": { "type": "integer" },
        "sid": { "type": ["string","null"] }
      }
    }
  }
}

My API response is as follows:

{"twilio_account":{"twilio_account_id":2}}

However when I run it through the validator it raises the error: The property '#/twilio_account' did not contain a required property of 'sid'

I do happen to be using the validator in strict mode, however I've clearly specified which attributes are required. Are all still required?

iainbeeston commented 8 years ago

@biznickman When you use strict mode, all properties are required, regardless of what you've specified in the required property. Perhaps you'd be better adding additionalProperties: false and not using strict mode.