rjsf-team/react-jsonschema-form

oneOf + const is handled differently when nested in a property vs as a root object property

Chiusa

#4963 aperta il 19 feb 2026

 (9 commenti) (0 reazioni) (0 assegnatari)TypeScript (2136 fork)batch import
bughelp wanted

Metriche repository

Star
 (13.175 stelle)
Metriche merge PR
 (Merge medio 3g 17h) (32 PR mergiate in 30 g)

Descrizione

Prerequisites

What theme are you using?

mantine

Version

6.3.1

Current Behavior

It's possible there's something I don't understand about JSON Schema or RJSF here, but this seems like a bug to me.

This is with the following feature flag:

experimental_defaultFormStateBehavior={{
  constAsDefaults: 'always',
}}

The first schema will have the behavior of enforcing food equals "fish" if animal equals "Cat". Even if the user uses the dropdown to select a different value, it forces it back to the const value. The second schema is essentially the same schema, except nested inside a property nested. The above behavior is no longer observed.

Validation is not broken, but the UX behavior changes.

Working playground with the schema below:

{
  "type": "object",
  "properties": {
    "animal": {
      "enum": [
        "Cat",
        "Fish"
      ]
    },
    "food": {
      "type": "string",
      "enum": [
        "meat",
        "grass",
        "fish"
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "animal": {
            "const": "Cat"
          }
        }
      },
      "then": {
        "properties": {
          "food": {
            "const": "fish"
          }
        },
        "required": [
          "food"
        ]
      }
    },
    {
      "required": [
        "animal"
      ]
    }
  ]
}

Bugged playground with the schema below:

{
  "type": "object",
  "properties": {
    "nested": {
      "type": "object",
      "properties": {
        "animal": {
          "enum": [
            "Cat",
            "Fish"
          ]
        },
        "food": {
          "type": "string",
          "enum": [
            "meat",
            "grass",
            "fish"
          ]
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "animal": {
                  "const": "Cat"
                }
              }
            },
            "then": {
              "properties": {
                "food": {
                  "const": "fish"
                }
              },
              "required": [
                "food"
              ]
            }
          },
          {
            "required": [
              "animal"
            ]
          }
        ]
      }
    }
  }
}

Expected Behavior

Consistent UX behavior whether the allOf is the root object or a nested object property.

Steps To Reproduce

Observable in the plaground via the two links above

Environment

- OS: Windows 11
- Node: 22.13.1
- npm: 11.7.0

Anything else?

No response

Guida contributor