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

Possible bug with anyOf/oneOf when the selected schema changes from type:string to type:object #3922

Closed
4 tasks done
lindolo25 opened this issue Oct 25, 2023 · 1 comment · Fixed by #3947
Closed
4 tasks done
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug help wanted

Comments

@lindolo25
Copy link
Contributor

Prerequisites

What theme are you using?

bootstrap-4

Version

5.1.0

Current Behavior

Given an anyOf or a oneOf composition schema with two options. First an object with one property of type string and second just a string value. When option 2 has a value (example "adsads") and the dropdown is changed to the option 1. The value is set to this:

{
  "0": "a",
  "1": "d",
  "2": "s",
  "3": "a",
  "4": "d",
  "5": "s"
}

It continues to keep those added properties after a value is give to option 1 string property:

{
  "0": "a",
  "1": "d",
  "2": "s",
  "3": "a",
  "4": "d",
  "5": "s",
  "foo": "werwer"
}

Even if the "additionalProperties": false is set the an error will not be presented.

image

The scenario will work as expected if option 2 has another type of value, I tested number and boolean.

Expected Behavior

After switching to the Option 1, the value should be and empty object {}.

Steps To Reproduce

  1. Open the setup
  2. Select Option 1
  3. Type a value for "foo"

Environment

- OS: Fedora 38 (Workstation Edition)
- Node: v18.16.0
- npm: v9.5.1

Anything else?

I narrow it down to the result of the function schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData) in line 122 of the MultiSchemaField.tsx file.

let newFormData = schemaUtils.sanitizeDataForNewSchema(newOption, oldOption, formData);

After that function is executed, newFormData takes that value and later on is used to update the field value in line 128. I'll update later if I'm able to find out more about this issue.

@lindolo25 lindolo25 added bug needs triage Initial label given, to be assigned correct labels and assigned labels Oct 25, 2023
@nickgros
Copy link
Contributor

nickgros commented Nov 3, 2023

Definitely something unusual happening here. Thanks for the report @lindolo25 ! If you can open a PR to fix this we would be happy to review and accept it.

@nickgros nickgros added help wanted any-one-all-of Related to fixing anyOf, oneOf or allOf and removed needs triage Initial label given, to be assigned correct labels and assigned labels Nov 3, 2023
lindolo25 added a commit to lindolo25/react-jsonschema-form that referenced this issue Nov 9, 2023
… creating the newFormData in sanitizeDataForNewSchema(
lindolo25 added a commit to lindolo25/react-jsonschema-form that referenced this issue Nov 12, 2023
… creating the newFormData in sanitizeDataForNewSchema(
heath-freenome added a commit that referenced this issue Nov 15, 2023
* Fix: #3922 by addind a condition to the spread operator when creating the newFormData in sanitizeDataForNewSchema(

* Add test cases to cover the changes required for the fix.

* Added CHANGELOG description of the fix.

* Add heath-freenome recommendation.

Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>

---------

Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants