jsonvalidate icon indicating copy to clipboard operation
jsonvalidate copied to clipboard

Nesting an array inside an object in JSON schema always returns valid (even when it's not)

Open yogat3ch opened this issue 6 months ago • 2 comments

Directory structure is as follows:

├── main.json
├── objects.json
└── test.json

main.json:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$id": "1.1.0",
    "title": "My Main Schema",
    "description": "reprex schema",
    "type": "object",
    "properties": {
      "the_object": {
        "type": "object",
        "properties": {
            "my_nested_object": {
                "$ref": "./objects.json#/properties/objects"               
            }
        }
      }
    }
}

objects.json:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$id": "objects",
    "title": "My Main Schema",
    "description": "reprex schema",
    "type": "object",
    "properties": {
      "objects": {
        "type": "array",
            "items": {
                "type": "string",
                "enum": ["a","b","c"]
            }
      }
    }
}

test.json:

{
    "the_object": {
        "my_nested_object": ["d", "e"]
    }
}
jsonvalidate::json_validate("test.json", "main.json")

This will always evaluate to TRUE, disregarding the mismatch between the values in the array in test_json/the_object/my_nested_object and the enum specified in the objects reference. It seems like nested objects disregard the specified constraints of referenced schema?

yogat3ch avatar Feb 08 '24 18:02 yogat3ch