Skip to content

oneOf/anyOf with parent-level type renders an extra input and produces incorrect formData #5119

@echarbeto

Description

@echarbeto

Prerequisites

What theme are you using?

validator-ajv8

Version

6.6.2

Current Behavior

Hi rjsf team,

I found an issue when using oneOf or anyOf with a field that already defines its type at the parent level.

I will include a playground example, but the schema looks like this:

{
  "title": "Network config",
  "type": "object",
  "required": ["ipAddress"],
  "properties": {
    "ipAddress": {
      "title": "IP address",
      "type": "string",
      "oneOf": [
        {
          "title": "IPv4",
          "pattern": "^(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(\\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}$",
          "examples": ["192.168.1.10"]
        },
        {
          "title": "IPv6",
          "pattern": "^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::1|::)$",
          "examples": ["2001:0db8:85a3:0000:0000:8a2e:0370:7334"]
        }
      ]
    }
  }
}

The same issue also happens if oneOf is replaced with anyOf.

Since ipAddress is declared as "type": "string", I would expect rjsf to render it as a string field and use the selected oneOf/anyOf branch only to apply the additional validation rules.

Current behavior

rjsf renders an unexpected extra input above the oneOf/anyOf selector.

It also renders the selector and then shows an unsupported field error for the selected branch:

Unsupported field schema for field root_ipAddress: Unknown field type undefined.

The unsupported schema shown is only the selected branch:

{
  "title": "IPv4",
  "pattern": "^(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(\\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}$",
  "examples": ["192.168.1.10"]
}

The bigger issue is that typing into the unexpected input can produce form data like this:

{
  "ipAddress": {
    "XxxOf": "192.168.1.10"
  }
}

This does not match the schema, because ipAddress is explicitly declared as a string.

Expected Behavior

I would expect rjsf to:

  • Use the parent-level type when rendering oneOf/anyOf branches that do not define their own type.
  • Avoid rendering the extra input above the oneOf/anyOf selector.
  • Preserve the declared data type in formData.

The resulting form data should remain a string:

{
  "ipAddress": "192.168.1.10"
}

Since the parent schema already declares "type": "string", rjsf should be able to treat each oneOf/anyOf branch as string-based for rendering purposes, unless a branch explicitly defines a different type.

For this example, a reasonable default UI could be:

IP address type: [IPv4 | IPv6]
IP address:      [________________]

or any other layout decided by rjsf, but there should be only one real input bound to ipAddress.

Steps To Reproduce

Playground: https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6e30sInNjaGVtYSI6eyJ0aXRsZSI6Ik5ldHdvcmsgY29uZmlnIiwidHlwZSI6Im9iamVjdCIsInJlcXVpcmVkIjpbImlwQWRkcmVzcyJdLCJwcm9wZXJ0aWVzIjp7ImlwQWRkcmVzcyI6eyJ0aXRsZSI6IklQIGFkZHJlc3MiLCJ0eXBlIjoic3RyaW5nIiwib25lT2YiOlt7InRpdGxlIjoiSVB2NCIsInBhdHRlcm4iOiJeKDI1WzAtNV18MlswLTRdWzAtOV18MT9bMC05XXsxLDJ9KShcXC4oMjVbMC01XXwyWzAtNF1bMC05XXwxP1swLTldezEsMn0pKXszfSQiLCJleGFtcGxlcyI6WyIxOTIuMTY4LjEuMTAiXX0seyJ0aXRsZSI6IklQdjYiLCJwYXR0ZXJuIjoiXigoWzAtOWEtZkEtRl17MSw0fTopezd9WzAtOWEtZkEtRl17MSw0fXw6OjF8OjopJCIsImV4YW1wbGVzIjpbIjIwMDE6MGRiODo4NWEzOjAwMDA6MDAwMDo4YTJlOjAzNzA6NzMzNCJdfV19fX0sInVpU2NoZW1hIjp7fSwidGhlbWUiOiJkZWZhdWx0IiwibGl2ZVNldHRpbmdzIjp7InNob3dFcnJvckxpc3QiOiJ0b3AiLCJ2YWxpZGF0ZSI6ZmFsc2UsImRpc2FibGVkIjpmYWxzZSwibm9IdG1sNVZhbGlkYXRlIjpmYWxzZSwicmVhZG9ubHkiOmZhbHNlLCJvbWl0RXh0cmFEYXRhIjpmYWxzZSwibGl2ZU9taXQiOmZhbHNlLCJleHBlcmltZW50YWxfZGVmYXVsdEZvcm1TdGF0ZUJlaGF2aW9yIjp7ImFycmF5TWluSXRlbXMiOiJwb3B1bGF0ZSIsImFsbE9mIjoic2tpcERlZmF1bHRzIiwiY29uc3RBc0RlZmF1bHRzIjoiYWx3YXlzIiwiZW1wdHlPYmplY3RGaWVsZHMiOiJwb3B1bGF0ZUFsbERlZmF1bHRzIiwibWVyZ2VEZWZhdWx0c0ludG9Gb3JtRGF0YSI6InVzZUZvcm1EYXRhSWZQcmVzZW50In0sInVzZUZhbGxiYWNrVWlGb3JVbnN1cHBvcnRlZFR5cGUiOmZhbHNlLCJsaXZlVmFsaWRhdGUiOmZhbHNlLCJpZFByZWZpeCI6InJvb3QiLCJpZFNlcGFyYXRvciI6Il8ifSwidmFsaWRhdG9yIjoiQUpWOCIsInNhbXBsZU5hbWUiOiJCbGFuayJ9

Environment

- OS: Ubuntu 24.04
- Node: 22.22.3
- npm: 10.9.8

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triageInitial label given, to be assigned correct labels and assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions