Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array with items field in oneOf #3877

Open
4 tasks done
aurelien-brevet opened this issue Sep 21, 2023 · 5 comments
Open
4 tasks done

array with items field in oneOf #3877

aurelien-brevet opened this issue Sep 21, 2023 · 5 comments

Comments

@aurelien-brevet
Copy link

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 aurelien-brevet added bug needs triage Initial label given, to be assigned correct labels and assigned labels Sep 21, 2023
@heath-freenome
Copy link
Member

heath-freenome commented Oct 6, 2023

Link to the playground with this error

@heath-freenome
Copy link
Member

heath-freenome commented Oct 6, 2023

@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 heath-freenome added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Oct 6, 2023
@aurelien-brevet
Copy link
Author

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.

@heath-freenome
Copy link
Member

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

@rbavery
Copy link

rbavery commented Jul 23, 2024

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 #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants