react-jsonschema-form
react-jsonschema-form copied to clipboard
array with items field in oneOf
Prerequisites
- [X] I have searched the existing issues
- [X] I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [X] I have read the documentation
- [X] Ideally, I'm providing a sample JSFiddle, Codesandbox.io or preferably a shared playground link demonstrating the issue.
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
Link to the playground with this error
@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"
}
]
}
}
}
}
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 Good point. I believe that this playground example does what you want
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.