json schema validation patternProperties and properties conflict

640 views Asked by At

i 've this JSON schema

{
  "title": "JSON Schema for revues subscribtion",
  "type": "object",
  "properties": {
    "lab": {
      "type": "string"
    }
  },
  "patternProperties": {
    "[A-Za-z][A-Za-z_]*[A-Za-z]": {
      "type": "boolean"
    }
  },
  "required": [
    "lab"
  ]
}

i want to match a json data like

{
 "SP": false,
 "lab": "labri"
}

but it failed because "lab" value is expected as boolean. that's mean "lab" is matched by the patternProperties.

Do someone have a solution for this ?

PS : Sorry i'm not good at english

1

There are 1 answers

0
esp On BEST ANSWER

One way is to use regexp that would match what you need but won't match 'lab'. At best it is not trivial.

Another is this schema:

{
    "title" : "JSON Schema for revues subscribtion",
    "type" : "object",
    "properties" : {
        "lab" : { "type" : "string" }
    },
    "additionalProperties" : { "type": "boolean" },
    "required" : [ "lab" ]
}

It will require all properties but lab to be boolean. I don't think you can do any better.