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

liveOmit & omitExtraData not work with empty oneOf

Open YuJianghao opened this issue 1 year ago • 1 comments

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

With both liveOmit and omitExtraData set to true and a field with oneOf: [], changing form will cause error (playground reproduction):

{
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "style": {
      "type": "string",
      "oneOf": []
    }
  }
}
index-90aec295.js:43 Uncaught TypeError: Cannot use 'in' operator to search for '$ref' in undefined
    at ug (index-90aec295.js:43:9733)
    at ug (index-90aec295.js:43:9972)
    at ug (index-90aec295.js:43:10407)
    at Eet (index-90aec295.js:43:10484)
    at Pet.toPathSchema (index-90aec295.js:43:11713)
    at onChange (index-90aec295.js:64:28374)
    at index-90aec295.js:64:5148
    at index-90aec295.js:64:1174
    at index-90aec295.js:64:5148
    at index-90aec295.js:64:11289

After add an option to oneOf, it will work: playground

{
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "style": {
      "type": "string",
      "oneOf": [
        {
          "const": "abc"
        }
      ]
    }
  }
}

Expected Behavior

change the form without error

Steps To Reproduce

  1. set both liveOmit and omitExtraData Form props to true
  2. set a field's schema to oneOf: []
  3. change form values through other field
  4. error Cannot use 'in' operator to search for '$ref' in undefined

Environment

- OS:
- Node:
- npm:

Anything else?

Maybe this line throw the error

https://github.com/rjsf-team/react-jsonschema-form/blob/d58775b444b04465a6ae01300e1f3e18e6145c95/packages/utils/src/schema/toPathSchema.ts#L41

YuJianghao avatar Jan 26 '24 04:01 YuJianghao

@YuJianghao This is not a valid JSON Schema per the spec:

This keyword's value MUST be a non-empty array.

We can accept a PR to handle this case and log a warning if it would improve the experience of using RJSF

nickgros avatar Jan 26 '24 21:01 nickgros