jsonforms icon indicating copy to clipboard operation
jsonforms copied to clipboard

required keyword doesn't work with oneOf fields

Open DrewHoo opened this issue 1 year ago • 2 comments

Describe the bug

If you have a oneOf field that contains both object and string type schemas, requiring that field has no effect on the string-type schema, and AFAICT there's no way to make the string-type schema required.

Expected behavior

when requiring a oneOf field that contains multiple schema types, non-object types show up as required.

Steps to reproduce the issue

Used schema:

{
  "title": "Oratrice",
  "type": "object",
  "properties": {
    "mecanique": {
      "title": "Mecanique",
      "oneOf": [
        {
          "title": "d'Analyse",
          "type": "string"
        },
        {
          "title": "Cardinale",
          "type": "object",
          "properties": {
            "cardinale": {
              "title": "name",
              "type": "string"
            }
          },
          "required": ["cardinale"]
        }
      ]
    }
  },
  "required": ["mecanique"]
}

If a (string) control is rendered for the first entry of the oneOf, the JSON Forms bindings will not indicate that this control is required.

I created a minimal reproduction in this codesandbox: https://codesandbox.io/p/sandbox/wizardly-darkness-vhrlwt?file=%2Fsrc%2FApp.tsx%3A50%2C27

Screenshots

No response

In which browser are you experiencing the issue?

Firefox 120.0

Which Version of JSON Forms are you using?

v3.1.0

Framework

Core, React

RendererSet

Other (please specify in the Additional context field)

Additional context

This is a bug in either the Core library or the React library--it happens with multiple renderer sets

DrewHoo avatar Nov 29 '23 11:11 DrewHoo

Hi @DrewHoo,

Thanks for providing the codesandbox for reproduction. However in general it would be nice to have the reproduction steps self-contained in the issue description too ;) I edited the description to include it.

Our required analysis is very basic, and we're bailing very fast if conditionals or if/then/else are involved. However here, as the whole oneOf is required always, we should be able to still determine this.

The code can be found here. Would you like to contribute a fix?

sdirix avatar Dec 07 '23 08:12 sdirix

Hi @sdirix,

Yeah, I'll take a look at adding a fix! Thanks for adding the repro steps to the description, will be sure to include the schema here next time =)

DrewHoo avatar Dec 07 '23 17:12 DrewHoo