remoteoss / json-schema-form

https://json-schema-form.vercel.app
MIT License
70 stars 7 forks source link

fix(conditionals): Certain conditions were failing due to lack of context #65

Closed brennj closed 5 months ago

brennj commented 5 months ago

Consider the following schema:

{
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "salary": {
            "maximum": 119999
          }
        },
        "required": ["salary"]
      },
      "then": {
        "required": ["reason"]
      },
      "else": {
        "properties": {
          "reason": false
        }
      }
    }
  ],
  "properties": {
    "salary": {
      "type": "number",
      "x-jsf-presentation": {
        "inputType": "money"
      }
    },
    "reason": {
      "oneOf": [
        {
          "const": "reason_one"
        },
        {
          "const": "reason_two"
        }
      ],
      "type": "string"
    }
  },
  "required": ["salary"],
  "type": "object"
}

Check it out on the playground.

With the presence of the x-jsf-presentation in the salary field, it is causing a Error: Cannot read properties of undefined (reading 'isValidSync') error to occur.

To fix this in this PR, we must ensure all existing properties are being passed down to further conditionals being evaluated.

brennj commented 5 months ago

@sandrina-p can i get you to approve these changes when you have a chance please? :)