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

Odd behaviour of anyOf/oneOf #3744

Closed
3 of 4 tasks
harkiratsm opened this issue Jun 26, 2023 · 2 comments · Fixed by #3763
Closed
3 of 4 tasks

Odd behaviour of anyOf/oneOf #3744

harkiratsm opened this issue Jun 26, 2023 · 2 comments · Fixed by #3763
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf bug help wanted

Comments

@harkiratsm
Copy link

harkiratsm commented Jun 26, 2023

Prerequisites

What theme are you using?

core, material-ui

Version

5.8.1

Current Behavior

We are treating anyOf/oneOf incorrectly right now their subschemas should merge with the schema where they are defined based on selection.

clearly there is alot of duplication. in the oneOf selector
anyOf/oneOf Example

Expected Behavior

Have a consistent behavior of anyOf/oneOf like we have for allOf.

allOf_example

Steps To Reproduce

rjsf_playground_example

Environment

- OS:
- Node:
- npm:

Anything else?

No response

@harkiratsm harkiratsm added bug needs triage Initial label given, to be assigned correct labels and assigned labels Jun 26, 2023
@harkiratsm harkiratsm changed the title Odd behaviour of anyOf/oneOf <title> Odd behaviour of anyOf/oneOf Jun 26, 2023
@harkiratsm
Copy link
Author

@heath-freenome @nickgros ^^

@heath-freenome
Copy link
Member

@harkiratsm This is a good catch and we probably do want to merge oneOf/anyOf like we do allOf. You are welcome to come up with a fix for this. I'm guessing the place to fix it is in @rjsf/utils in the retrieveSchema.ts file within the resolveAnyOrOneOfSchemas() method.

@heath-freenome heath-freenome 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 Jun 30, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jul 12, 2023
Fixes rjsf-team#3744 as well as an issue associated with anyOf/oneOf in precompiled schema
- In `@rjsf/util`, fixed part of rjsf-team#3744 and the precompiled schema issue as follows:
  - Updated `getClosestMatchingOption()` to resolve refs in the options before computing the correct index, as well as supporting `anyOf` and discriminators in `calculateIndexScore()`
  - Updated `getDefaultFormState()` to merge in the remaining schema into the selected anyOf/oneOf option prior to computing new defaults
  - Updated `retrieveSchema()` to merge in the remaining schema into the anyOf/oneOf options when resolving dependencies
  - Added/updated tests to verify all the fixes
- In `@rjsf/core`, fixed the rest of rjsf-team#3744 by updating `MultiSchemaField` to merge the remaining schema into the selected anyOf/oneOf selected option
  - Also updated `SchemaField` to no longer pass in `baseType` to `MultiSchemaField` since it is no longer used
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jul 12, 2023
Fixes rjsf-team#3744 as well as an issue associated with anyOf/oneOf in precompiled schema
- In `@rjsf/util`, fixed part of rjsf-team#3744 and the precompiled schema issue as follows:
  - Updated `getClosestMatchingOption()` to resolve refs in the options before computing the correct index, as well as supporting `anyOf` and discriminators in `calculateIndexScore()`
  - Updated `getDefaultFormState()` to merge in the remaining schema into the selected anyOf/oneOf option prior to computing new defaults
  - Updated `retrieveSchema()` to merge in the remaining schema into the anyOf/oneOf options when resolving dependencies
  - Added/updated tests to verify all the fixes
- In `@rjsf/core`, fixed the rest of rjsf-team#3744 by updating `MultiSchemaField` to merge the remaining schema into the selected anyOf/oneOf selected option
  - Also updated `SchemaField` to no longer pass in `baseType` to `MultiSchemaField` since it is no longer used
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jul 12, 2023
Fixes rjsf-team#3744 as well as an issue associated with anyOf/oneOf in precompiled schema
- In `@rjsf/util`, fixed part of rjsf-team#3744 and the precompiled schema issue as follows:
  - Updated `getClosestMatchingOption()` to resolve refs in the options before computing the correct index, as well as supporting `anyOf` and discriminators in `calculateIndexScore()`
  - Updated `getDefaultFormState()` to merge in the remaining schema into the selected anyOf/oneOf option prior to computing new defaults
  - Updated `retrieveSchema()` to merge in the remaining schema into the anyOf/oneOf options when resolving dependencies
  - Added/updated tests to verify all the fixes
- In `@rjsf/core`, fixed the rest of rjsf-team#3744 by updating `MultiSchemaField` to merge the remaining schema into the selected anyOf/oneOf selected option
  - Also updated `SchemaField` to no longer pass in `baseType` to `MultiSchemaField` since it is no longer used
heath-freenome added a commit that referenced this issue Jul 13, 2023
* fix: Fixed #3744 and another precompiled schema issue
Fixes #3744 as well as an issue associated with anyOf/oneOf in precompiled schema
- In `@rjsf/util`, fixed part of #3744 and the precompiled schema issue as follows:
  - Updated `getClosestMatchingOption()` to resolve refs in the options before computing the correct index, as well as supporting `anyOf` and discriminators in `calculateIndexScore()`
  - Updated `getDefaultFormState()` to merge in the remaining schema into the selected anyOf/oneOf option prior to computing new defaults
  - Updated `retrieveSchema()` to merge in the remaining schema into the anyOf/oneOf options when resolving dependencies
  - Added/updated tests to verify all the fixes
- In `@rjsf/core`, fixed the rest of #3744 by updating `MultiSchemaField` to merge the remaining schema into the selected anyOf/oneOf selected option
  - Also updated `SchemaField` to no longer pass in `baseType` to `MultiSchemaField` since it is no longer used

* Update packages/utils/test/schema/getClosestMatchingOptionTest.ts

Co-authored-by: Nick Grosenbacher <nickgrosenbacher@gmail.com>

---------

Co-authored-by: Nick Grosenbacher <nickgrosenbacher@gmail.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