6
votes

how can I override the validation rules which are defined in a json schema which is inherited by the "allOf" keyword?

Example:

{
  "$schema": "http://json-schema.org/draft-06/schema",
  "title": "My JSON Schema",
  "description": "",
  "definitions": {
    "a": {
      "type": "object",
      "properties": {
        "b": {
          "type": "object",
          "properties": {
            "c": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            }
          },
          "required": [
            "c"
          ]
        }
      },
      "required": [
        "b"
      ]
    }
  },
  "properties": {
    "main": {
      "type": "object",
      "allOf": [
        {
          "$ref": "#/definitions/a"
        }
      ]
    },
    "sub": {
      "type": "object",
      "allOf": [
        {
          "$ref": "#/definitions/a"
        }
      ]
    }
  }
}

The json schema defines two objects:

  • main
  • sub

Both objects inherit their properties from the defined object "a" But the object "sub" should have other validation rules for property b.c (currently it is minLength 1 and maxLength 100).

So of course following json is invalid:

{
  "main" :{
    "b": {
      "c": "This property has a min length"
    }
  },"sub" : {
    "b": {
      "c": ""
    }
  }
}

How can I override the validation rules for property b.c?

1

1 Answers

3
votes

There is currently no way to do this perscribed by the JSON Schema specification.