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

"oneOf" set of objects in "additionalProperties" #2538

Closed
3 tasks done
RAM92 opened this issue Sep 6, 2021 · 3 comments · Fixed by #3392
Closed
3 tasks done

"oneOf" set of objects in "additionalProperties" #2538

RAM92 opened this issue Sep 6, 2021 · 3 comments · Fixed by #3392
Labels
additionalProperties any-one-all-of Related to fixing anyOf, oneOf or allOf bug core

Comments

@RAM92
Copy link
Contributor

RAM92 commented Sep 6, 2021

Prerequisites

Description

It is not possible to specify "additionalProperties" where the property key(s) is customizable and the value is "oneOf" a set of given object structures.

Steps to Reproduce

https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJ0ZXN0UHJvcGVydHkiOnt9fSwic2NoZW1hIjp7IiRzY2hlbWEiOiJodHRwOi8vanNvbi1zY2hlbWEub3JnL3NjaGVtYSMiLCJpZCI6Imh0dHA6Ly9ibGFoLmNvbS9zY2hlbWFzL2JsYWguanNvbiIsInRpdGxlIjoiVGVzdCBzY2hlbWEgdGl0bGUiLCJkZXNjcmlwdGlvbiI6IlRlc3Qgc2NoZW1hIGRlc2NyaXB0aW9uIiwidHlwZSI6Im9iamVjdCIsInByb3BlcnRpZXMiOnsidGVzdFByb3BlcnR5Ijp7ImRlc2NyaXB0aW9uIjoiQW55IGtleSBuYW1lLCBmaXhlZCBzZXQgb2YgcG9zc2libGUgdmFsdWVzIiwidHlwZSI6Im9iamVjdCIsIm1pblByb3BlcnRpZXMiOjEsImFkZGl0aW9uYWxQcm9wZXJ0aWVzIjp7Im9uZU9mIjpbeyJ0aXRsZSI6Im15IGNob2ljZSAxIiwidHlwZSI6Im9iamVjdCIsInByb3BlcnRpZXMiOnsicHJvcDEiOnsiZGVzY3JpcHRpb24iOiJwcm9wMSBkZXNjcmlwdGlvbiIsInR5cGUiOiJzdHJpbmcifX0sInJlcXVpcmVkIjpbInByb3AxIl0sImFkZGl0aW9uYWxQcm9wZXJ0aWVzIjpmYWxzZX0seyJ0aXRsZSI6Im15IGNob2ljZSAyIiwidHlwZSI6Im9iamVjdCIsInByb3BlcnRpZXMiOnsicHJvcDIiOnsiZGVzY3JpcHRpb24iOiJwcm9wMiBkZXNjcmlwdGlvbiIsInR5cGUiOiJzdHJpbmcifX0sInJlcXVpcmVkIjpbInByb3AyIl0sImFkZGl0aW9uYWxQcm9wZXJ0aWVzIjpmYWxzZX1dfX19LCJyZXF1aXJlZCI6WyJ0ZXN0UHJvcGVydHkiXSwiYWRkaXRpb25hbFByb3BlcnRpZXMiOmZhbHNlfSwidWlTY2hlbWEiOnt9LCJ0aGVtZSI6ImRlZmF1bHQiLCJsaXZlU2V0dGluZ3MiOnsidmFsaWRhdGUiOmZhbHNlLCJkaXNhYmxlIjpmYWxzZSwib21pdEV4dHJhRGF0YSI6ZmFsc2UsImxpdmVPbWl0IjpmYWxzZX19

Expected behavior

UI Should show a dropdown with ability to add properties of type "my choice 1" or "my choice 2", and the ability to change the key. Also "prop1" or "prop2" should be visible.

@newt10
Copy link
Collaborator

newt10 commented Sep 6, 2021

Marking this as a bug as object schemas seem to work with additionalProperties and based on that this schema should have generated a dropdown widget to select between the different object schemas.

Screen Shot 2021-09-06 at 9 59 45 AM

@RAM92 feel free to create a PR once you are able to fix this.

@RAM92
Copy link
Contributor Author

RAM92 commented Sep 16, 2021

I can confirm that this issue still occurs when using basic types in the "oneOf" clause.

playground example

@RAM92
Copy link
Contributor Author

RAM92 commented Sep 16, 2021

Here is an example of a "oneOf" clause not working when loading data. There should be one of each type described, but RJSF treats them both as the first item in the oneOf clause - in this case, a string.
If you change the order in the schema, it will render as if they were both booleans.

playground example

image

@heath-freenome heath-freenome added any-one-all-of Related to fixing anyOf, oneOf or allOf and removed multiSchema labels Jan 20, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 22, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 22, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 22, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 22, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Jan 23, 2023
heath-freenome added a commit that referenced this issue Jan 24, 2023
* fix: fixed several issue in oneOf/anyOf functions
Fixes #2944, #3236, #2978 and possibly others
- In `@rjsf/utils`, added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
  - Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
  - Added 100% unit tests for all new functions, renaming the old `getMatchingOptionsTest.ts` file to `getFirstMatchingOptionsTest.ts`
  - Updated `createSchemaUtils()` and it's associated type to add the three new functions
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated the `schema.tests.ts` to add the new tests for the new schema-based utility functions
- In `@rjsf/core`, updated the `MultiSchemaField` to use the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` utility functions
  - Also updated the render to properly pass props to the widget and the schema field
- In `@rjsf/playground`, updated `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different
  - Also updated the `npm start` command to add the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
- Updated the `utility-functions.md` file to document the new schema-based functions and to fix up incorrect strike-through caused by the unescaped `<S>` generic
- Updated the `5.x upgrade guide.md` file to document the new utility functions and the deprecation of `getMatchingOption()`

* - Fixed a few small issues exposed by trying to use the playground in #2375
- Also updated the `CHANGELOG.md` to include all of the fixed issues

* - Fix #2538 by fixing additionalProperties to deal with allOf/anyOf/oneOf

* - Updated `getSchemaType()` to grab the type of the first element of a `oneOf`/`anyOf`

* - Allow `formData` in `getClosestMatchingOption()` to accept `undefined`

* - Responded to reviewer feedback

* - Deal with sanitizing data when both `array.items` elements are booleans and have the same value

* - Fixed issue with const being assigned default value incorrectly and handle readOnly default values like const
- Updated some documentation in the types and createSchemaUtils
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
* fix: fixed several issue in oneOf/anyOf functions
Fixes rjsf-team#2944, rjsf-team#3236, rjsf-team#2978 and possibly others
- In `@rjsf/utils`, added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
  - Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
  - Added 100% unit tests for all new functions, renaming the old `getMatchingOptionsTest.ts` file to `getFirstMatchingOptionsTest.ts`
  - Updated `createSchemaUtils()` and it's associated type to add the three new functions
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated the `schema.tests.ts` to add the new tests for the new schema-based utility functions
- In `@rjsf/core`, updated the `MultiSchemaField` to use the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` utility functions
  - Also updated the render to properly pass props to the widget and the schema field
- In `@rjsf/playground`, updated `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different
  - Also updated the `npm start` command to add the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
- Updated the `utility-functions.md` file to document the new schema-based functions and to fix up incorrect strike-through caused by the unescaped `<S>` generic
- Updated the `5.x upgrade guide.md` file to document the new utility functions and the deprecation of `getMatchingOption()`

* - Fixed a few small issues exposed by trying to use the playground in rjsf-team#2375
- Also updated the `CHANGELOG.md` to include all of the fixed issues

* - Fix rjsf-team#2538 by fixing additionalProperties to deal with allOf/anyOf/oneOf

* - Updated `getSchemaType()` to grab the type of the first element of a `oneOf`/`anyOf`

* - Allow `formData` in `getClosestMatchingOption()` to accept `undefined`

* - Responded to reviewer feedback

* - Deal with sanitizing data when both `array.items` elements are booleans and have the same value

* - Fixed issue with const being assigned default value incorrectly and handle readOnly default values like const
- Updated some documentation in the types and createSchemaUtils
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this issue Jun 8, 2023
* fix: fixed several issue in oneOf/anyOf functions
Fixes rjsf-team#2944, rjsf-team#3236, rjsf-team#2978 and possibly others
- In `@rjsf/utils`, added new `getClosestMatchingOption()`, `getFirstMatchingOption()` and `sanitizeDataForNewSchema()` schema-based utility functions
  - Deprecated `getMatchingOption()` and updated all calls to it in other utility functions to use `getFirstMatchingOption()`
  - Added 100% unit tests for all new functions, renaming the old `getMatchingOptionsTest.ts` file to `getFirstMatchingOptionsTest.ts`
  - Updated `createSchemaUtils()` and it's associated type to add the three new functions
- In `@rjsf/validator-ajv6` and `@rjsf/validator-ajv8`, updated the `schema.tests.ts` to add the new tests for the new schema-based utility functions
- In `@rjsf/core`, updated the `MultiSchemaField` to use the new `getClosestMatchingOption()` and `sanitizeDataForNewSchema()` utility functions
  - Also updated the render to properly pass props to the widget and the schema field
- In `@rjsf/playground`, updated `onFormDataEdited()` to only change the formData in the state if the `JSON.stringify()` of the old and new values are different
  - Also updated the `npm start` command to add the `--force` option to avoid issues where changes made to other packages weren't getting picked up due to `vite` caching
- Updated the `utility-functions.md` file to document the new schema-based functions and to fix up incorrect strike-through caused by the unescaped `<S>` generic
- Updated the `5.x upgrade guide.md` file to document the new utility functions and the deprecation of `getMatchingOption()`

* - Fixed a few small issues exposed by trying to use the playground in rjsf-team#2375
- Also updated the `CHANGELOG.md` to include all of the fixed issues

* - Fix rjsf-team#2538 by fixing additionalProperties to deal with allOf/anyOf/oneOf

* - Updated `getSchemaType()` to grab the type of the first element of a `oneOf`/`anyOf`

* - Allow `formData` in `getClosestMatchingOption()` to accept `undefined`

* - Responded to reviewer feedback

* - Deal with sanitizing data when both `array.items` elements are booleans and have the same value

* - Fixed issue with const being assigned default value incorrectly and handle readOnly default values like const
- Updated some documentation in the types and createSchemaUtils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
additionalProperties any-one-all-of Related to fixing anyOf, oneOf or allOf bug core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants