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

array with items field in oneOf

Open aurelien-brevet opened this issue 2 years ago • 5 comments

Prerequisites

What theme are you using?

core

Version

5.13.0

Current Behavior

Error: Unsupported field schema for field root_possibleValues: Missing items definition.

Expected Behavior

No error. Array with either elements of type number or string.

Steps To Reproduce

"possibleValues": {
      "type": "array",
      "oneOf": [
        {
          "items": {
            "type": "number"
          }
        },
        {
          "items": {
            "type": "string"
          }
        }
      ]
}

Environment

- OS:
- Node:
- npm:

Anything else?

No response

aurelien-brevet avatar Sep 21 '23 12:09 aurelien-brevet

Link to the playground with this error

heath-freenome avatar Oct 06 '23 19:10 heath-freenome

@aurelien-brevet I switched around the JSON Schema a little bit in this playground and am wondering if this works for you? Note that oneOfs are turned into dropdowns by default since the user needs to select the type.

{
  "type": "object",
  "properties": {
    "possibleValues": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "title": "Number",
            "type": "number"
          },
          {
            "title": "String",
            "type": "string"
          }
        ]
      }
    }
  }
}

heath-freenome avatar Oct 06 '23 20:10 heath-freenome

HI @heath-freenome, Thanks for your suggestion, but the result is not the same. I want to prohibit mixing values of different types.

Using my schema:

{
     "possibleValues": [1, "string"]
}

is not valid but valid with yours.

aurelien-brevet avatar Oct 10 '23 08:10 aurelien-brevet

@aurelien-brevet Good point. I believe that this playground example does what you want

heath-freenome avatar Oct 13 '23 19:10 heath-freenome

I'm also encountering this issue with a number of JSON schemas in the STAC ecoystem

When I paste in this JSON Schema, it parses a few fields but then errors with

Unsupported field schema for field root_stac_extensions: Missing items definition.

the section with the missing items definition

{
  "type": "array",
  "contains": {
    "const": "https://crim-ca.github.io/mlm-extension/v1.2.0/schema.json"
  }
}

I had some trouble figuring out the source of this issue since I'm not too familiar with JS. So I tested out another extension, the EO extension JSON Schema, and it also has this same issue with the same field and error.

When the schema is edited to add an items definition to the stac_extensions field, rendering the EO schame.json works in the form filler playground.

Adding this renders the field

"items": {
        "type": "string"
      },

like so

"stac_extensions": {
  "type": "object",
  "required": [
    "stac_extensions"
  ],
  "properties": {
    "stac_extensions": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "contains": {
        "const": "https://stac-extensions.github.io/eo/v1.1.0/schema.json"
      }
    }
  }
},

However I'm hoping that there can be a way to not require updates to all the schemas for these to work in this tool.

I think this issue is related to https://github.com/rjsf-team/react-jsonschema-form/pull/3843 because with these JSON schemas sometimes the array contains a const and therefore might not need an explicit item field with a type definition in order to render it in the form.

rbavery avatar Jul 23 '24 22:07 rbavery