Skip to content

Bug: incorrect handling of minProperties and maxProperties in optional attribute #215

@rtucek

Description

@rtucek

Given schema:

{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "session",
    "include_hotel",
    "arrival",
    "departure",
    "ip",
    "travellers",
    "language_iso_code"
  ],
  "properties": {
    "session": {
      "type": "string"
    },
    "campaign": {
      "type": "integer"
    },
    "service_provider": {
      "type": "integer"
    },
    "include_hotel": {
      "type": "boolean"
    },
    "arrival": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
    },
    "departure": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
    },
    "ip": {
      "type": "string"
    },
    "offerId": {
      "type": "integer",
      "minimum": 1
    },
    "quiet": {
      "type": "boolean"
    },
    "language_iso_code": {
      "type": "string"
    },
    "travellers": {
      "type": "array",
      "minItems": 1,
      "maxItems": 16,
      "items": {
        "type": "integer"
      }
    },
    "rooms": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "maxProperties": 2,
      "properties": {
        "size_1": {
          "type": "number"
        },
        "size_2": {
          "type": "number"
        }
      }
    },
    "offset": {
      "type": "integer"
    }
  }
}

And this data:

{
  "campaign": 1,
  "offset": 0,
  "service_provider": 3,
  "include_hotel": false,
  "arrival": "2016-01-20",
  "departure": "2016-01-27",
  "session": "foo",
  "ip": "bar",
  "language_iso_code": "de",
  "travellers": [
    18,
    18,
    18
  ]
}

Proofed by http://jsonschemalint.com/draft4/ the json is valid.
However the validator is returning the following error:

[
    0 =>  [
        "property" => "rooms",
        "message" => "Must contain no more than 2 properties",
        "constraint" => "maxProperties",
        "maxProperties" => 2
    ]
];

This should not happen because the property rooms is not given.
Thus their is no reason for a check on maxProperties constraint.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions