Validation not happening for properties defined inside anyOf field

I have the following schema and some how none of the properties defined in the anyOf section are getting validated by JSONForms. (specifically “days”, “hours” and “minutes”)

Schema

{
  "title": "rent",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Generated for lease signing",
  "type": "object",
  "properties": {
    "rent": {
      "type": "object",
      "properties": {
        "pool": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "lease": {
                "type": "object",
                "properties": {
                  "lease-choice": {
                    "anyOf": [
                      {
                          "type":"object",
                          "title": "lease-value",
                          "properties" :{
                              "days": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 365
                              },
                              "hours": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 23
                              },
                              "minutes": {
                                  "type": "integer",
                                  "minimum": 0,
                                  "maximum": 59
                              }
                          }
                      },
                      {
                          "type": "object",
                          "title": "infinite",
                          "properties": {
                              "infinite": {
                                  "type": "boolean"
                              }
                          }
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Attached below is the screenshot of the UI:


As you can see there is no validation happening.

Let me know if you need more information. Any help is much appreciated.

Which version of JsonForm are you using Angular or React?

If you are using Angular then it’s not supported I guess.

I am using JSONForms with React

Hi!

In JSON Forms we use AJV which validates the whole data object at once. We then map the reported errors to the UI. In the case of the anyOf/oneOf UI this might be misleading as the UI suggests a specific validation which is not actually taken place.

In the schema posted above the minimum/maximum properties have no effect. You can verify this outside of JSON Forms, for example with this online validator.
This is the case because of the anyOf construct. In case for example days falls outside the range of 0-365, it’s still a valid property for the other anyOf entry where no such restrictions exist and therefore no validation error is generated.

An easy fix for this is to add additionalProperties: false to each entry. Then the infinite entry is no longer able to “take over” invalid days/hours/minutes, i.e. the following schema will lead to validation errors being shown in the UI

{
  "title": "rent",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Generated for lease signing",
  "type": "object",
  "properties": {
    "rent": {
      "type": "object",
      "properties": {
        "pool": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "lease": {
                "type": "object",
                "properties": {
                  "lease-choice": {
                    "anyOf": [
                      {
                        "type": "object",
                        "title": "lease-value",
                        "properties": {
                          "days": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 365
                          },
                          "hours": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 23
                          },
                          "minutes": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 59
                          }
                        },
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "title": "infinite",
                        "properties": {
                          "infinite": {
                            "type": "boolean"
                          }
                        },
                        "additionalProperties": false
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

image


All things validation related is handled within the JSON Forms Core and should therefore behave the same for all renderer sets.

This makes sense.
Thanks for the quick reply @sdirix