Skip to content

Validation of referenced object skipped #225

@jagoral

Description

@jagoral

I've got a JSON Schema. One of property of this schema is referenced, and the problem is, that this reference is not included in validation.
This is my Schema (taken from http://json-schema.org/learn/miscellaneous-examples.html)

{
  "id": "https://example.com/arrays.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "A representation of a person, company, organization, or place",
  "type": "object",
  "properties": {
    "fruits": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "vegetables": {
      "type": "array",
      "items": { "$ref": "#/definitions/veggie" }
    }
  },
  "definitions": {
    "veggie": {
      "type": "object",
      "required": [ "veggieName", "veggieLike" ],
      "properties": {
        "veggieName": {
          "type": "string",
          "description": "The name of the vegetable."
        },
        "veggieLike": {
          "type": "boolean",
          "description": "Do I like this vegetable?"
        }
      }
    }
  }
}

and this is example of wrong validated JSON.

{
  "fruits": [ "apple", "orange", "pear" ],
  "vegetables": [
    {
      "veggieName": "potato"
    },
    {
      "veggieName": "broccoli",
      "veggieLike": false
    }
  ]
}

image

I'm expecting ValidationException, because property "veggieLike" is missing in first vegetable object, but actually there is no error.

This is my JAVA code

Schema schema = SchemaLoader.builder().schemaJson(new JSONObject(new JSONTokener(rawSchema))).build().load().build();
schema.validate(new JSONObject(json));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions