Skip to content

Mixing properties and patternProperties fails for properties not matching the patternProperties definition #705

@fabian-mcfly

Description

@fabian-mcfly

Schema (incomplete, just the important part):

"link": {
  {
    "type": "object",
    "properties": {
      "controller": {
        "type": "string",
        "pattern": "^[A-Z][a-zA-Z0-9]+$"
      },
      "action": {
        "type": "string",
        "pattern": "^[a-z][a-z0-9-]+$"
      }
    },
    "patternProperties": {
      "^[a-z][a-z0-9-]+$": {"pattern": "^[a-z0-9-]+$"}
    },
    "required": ["controller", "action"],
    "additionalProperties": false
  }
}

Data:

"link": {
  "controller": "Dashboard",
  "action": "overview",
  "param1": 123,
  "param2": "foobar"
}

Validating this data will result in an error:
Violations: [link.controller] Does not match the regex pattern ^[a-z0-9-]+$
Maybe I am the problem here, but I understand the "patternProperties" to only require validation for properties that aren't explicitly defined.
Since "controller" already is set, no validation with the regex pattern in patternProperties should occur.

I already found a fix, but I'd like to wait with a PR until someone can tell me whether this is, indeed, a bug or just my misunderstanding of how properties & patternProperties work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions