Skip to content

Nested oneOf/anyOf not rendered #4666

@phemmer

Description

@phemmer

Prerequisites

What theme are you using?

antd

Version

5.x

Current Behavior

This is a bit of a mix of a bug report and a feature request. A bug report in that a nested oneOf/anyOf don't work, and a feature request to make them work in a certain way.

The issue is that currently RJSF does not handle nested oneOf/anyOf lists. When doing so, the nested list fails to render in any way. So making this functionality work at all is the bug report.

Expected Behavior

The simple way of doing it would be to render the first drop down, and then when the option for the nested list is selected, to render another drop down.

The feature request is to instead allow merging/concatenating nested lists. For example if you have a oneOf inside a oneOf, to allow merging of all the options as if they were a single oneOf list.

Steps To Reproduce

{
  "type": "object",
  "properties": {
    "myprop": {
      "oneOf": [
        {
          "title": "none",
          "type": "object"
        },
        {
          "$ref": "#/$defs/some"
        },
        {
          "$ref": "#/$defs/mylist"
        }
      ]
    }
  },
  "$defs": {
    "some": {
      "title": "some",
      "const": "some"
    },
    "mylist": {
      "oneOf": [
        {
          "const": "foo"
        },
        {
          "const": "bar"
        }
      ]
    }
  }
}

playground

In the above, if you select "Option 3", there is no drop-down presented to select foo or bar. However the following are all valid against the schema:

{"myprop": {}}
{"myprop": "some"}
{"myprop": "foo"}
{"myprop": "bar"}

Environment

- OS:
- Node:
- npm:

Anything else?

As a side note, one of the main reasons for this was I wanted to prevent RJSF from automatically selecting the first item in the oneOf list (for myprop) and rendering it. And all the options for the list are defined in $defs. "none" isn't meant to be a valid option in the list, and is only applicable to the property, so I didn't want to put it in the list itself, and instead keep it on the property definition. Thus the property with a oneOf containing none, and then a reference to the real list.

However that said, it is not my only use case for this functionality. I also have other lists, where sometimes I want to only allow a subset of options, and other times I want to allow all options. For example think of a country selector. You might have a list in $defs for all the countries in Europe, and another list for North America. Sometimes you only want to allow selecting the European countries, but sometimes you want to allow selecting all countries. So the solution would be to define an "all" list, which contains references to each of the continental lists.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions