react-json-form icon indicating copy to clipboard operation
react-json-form copied to clipboard

Using both integer and boolean types together inside oneOf doesn't work as expected

Open oOhyeahh opened this issue 2 years ago • 1 comments

I have this following schema

{
  "type": "object",
  "properties": {
    "secret_code": {
      "oneOf": [
        {
          "type": "integer",
          "title": "Numeric value"
        },
        {
          "type": "string",
          "title": "String value"
        },
        {
          "type": "boolean",
          "title": "boolean value"
        },
        {
          "type": "list",
          "title": "list value",
          "items": {
            "type": "string"
          }
        }
      ]
    }
  }
}

When I copy the schema and try to select boolean value in the playground. It doesn't allow me to select. It changes to numeric value. However, when I remove one of the options from the list, it works perfectly fine.

oOhyeahh avatar Jul 17 '23 03:07 oOhyeahh

Problem:

The number and boolean types get null as the default value in the output.

To generate UI for oneOf, we look at the data and then try to find the matching subschema.

The problem here is that when you select boolean value, in the output you can see it gets the null value. The UI generator matches this null value to the numeric value.

It's a hard problem to solve because there's no way by looking at a null value to certainly determine whether it's for a number or a boolean. So we just generate the UI for the first matching subschema.


Temporary solution:

Provide a default value for the boolean value input:

{
    "type": "boolean",
    "title": "boolean value",
    "default": false
}

bhch avatar Jul 17 '23 05:07 bhch