Skip to content

Contains not working as expected with array of objects #144

@alessio-greco

Description

@alessio-greco

Using the following schema:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "properties": {
    "elements": {
      "type": "array",
      "items": {
        "type": "object"
      },
      "contains": {
        "properties": {
          "somePropertyA": {
            "type": "string",
            "enum": [
              "true"
            ]
          }
        }
      }
    }
  }
}

the following object is considered valid

{
  "elements": [
    {
      "somePropertyB": "false"
    },
    {
      "somePropertyA": "false"
    }
  ]
}

despite the schema saying "elements should contain a "somePropertyA":"true" object.

Is this the normal behaviour? most validators I tried will consider it valid (despite being intended not to be valid). The only way to make this work is passing an array with just the "intended" property, like

{
  "elements": [
    {
      "somePropertyA": "false"
    }
  ]
}

this will correctly be considered invalid.

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