Skip to content

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

@yogat3ch

Description

@yogat3ch

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?

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