Nick ONeill
Nick ONeill

Reputation: 7381

JSON Schema Validation Failing ... "The property did not contain a required property"

Below is a partial version of my json schema. I currently am using the json-schema Gem to validate the following (partial) schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "botSettings": {
      "type": "object",
      "properties": {
        "welcomeMessage": {
          "type": "object",
          "required": ["body"],
          "properties": {
            "title": { "type": "string" },
            "body": { "type": "string" },
            "image": { "#ref": "#/definitions/image" }
          }
        },
        "invalidCommandMessage": { "type": "string" }
      }
    }
  }
}

against the following (partial) json:

{
  "botSettings": {
    "welcomeMessage": {
      "title": "Welcome to the bot",
      "body": "This is the body right here"
    }
  }
}

When validating in strict mode, it states "The property '#/botSettings/welcomeMessage' did not contain a required property of 'image'", however I only have required set to "body". So what am I missing here?

Upvotes: 1

Views: 2461

Answers (2)

Jonatan Lindén
Jonatan Lindén

Reputation: 1485

You write that you are using strict mode. On the json-schema github page, I found the following:

with the :strict option, all properties are considered to have "required": true and all objects "additionalProperties": false

Upvotes: 0

Jason Desrosiers
Jason Desrosiers

Reputation: 24479

You're not missing anything. A standard JSON Schema validator should consider your JSON valid. Failure to validate could be either a bug in the validator, some non-standard behavior in the validator (check configuration), or it's not validating against the schema you think it is (cache issue).

Upvotes: 1

Related Questions