Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Workaround for "minContains" & "maxContains" in JSON Schema validation draft-07?

The latest JSON schema validation release (2019-09) allows one to put conditions (sub-schema) using contains keyword and also how many times that condition can appear in the JSON schema using minContains & maxContains. This functionality is not available in draft-07. Is there any way to attain this without using these keywords? For e.g.

"answers": [
    {
      "id": 1,
      "text": "choice1",
      "isCorrect": true
    },
    {
      "id": 1,
      "text": "choice2",
      "isCorrect": false
    },
    {
      "id": 1,
      "text": "choice3",
      "isCorrect": false
    },
    {
      "id": 1,
      "text": "choice4",
      "isCorrect": false
    }
  ]
}

A condition with contains as below:

"contains":{
  "properties":{
    "isCorrect":{
      "enum":["true"]
     }
  }
}

This checks that isCorrect is true at least once. But if I would like the validation to pass only when the value of isCorrect is true at least twice, how can I achieve that? Any help is appreciated! Thanks.

like image 929
Avani Agrawal Nath Avatar asked Dec 13 '25 14:12

Avani Agrawal Nath


1 Answers

No there is not, that is why we added the keywords for draft 2019-09. Sorry.

like image 105
Relequestual Avatar answered Dec 16 '25 15:12

Relequestual