eclipsesource / jsonforms

Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
http://jsonforms.io
Other
2.23k stars 375 forks source link

required keyword doesn't work with oneOf fields #2222

Open DrewHoo opened 1 year ago

DrewHoo commented 1 year ago

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

sdirix commented 12 months ago

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?

DrewHoo commented 12 months ago

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 =)

dwrBad commented 1 month ago

Hi, let me add another example for a conditional required field:

codesandbox

The example is missing the asterisk indicator for this case (the renderer field does not get an update required attribute).