Skip to content

Commit

Permalink
fix: Fixes #3808 and #3787 Duplicate AnyOf/OneOf Field (#3821)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendtxealth authored Aug 14, 2023
1 parent dabdae4 commit 5684e36
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ should change the heading of the (upcoming) version to include a major version b
-->
# 5.12.1

## @rjsf/core

- Updated `MultiSchemaField` to merge all top level fields except properties for anyOf/oneOf options, fixing [#3808](https://github.com/rjsf-team/react-jsonschema-form/issues/3808) and [#3787](https://github.com/rjsf-team/react-jsonschema-form/issues/3787)

## @rjsf/utils

- Updated `retrieveSchemaInternal` allOf logic for precompiled schemas to resolve top level properties fixing [#3817](https://github.com/rjsf-team/react-jsonschema-form/issues/3817)
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/components/fields/MultiSchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class AnyOfField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
let optionSchema: S;

if (option) {
const { oneOf, anyOf, ...remaining } = schema;
// merge all top level fields except properties
const { oneOf, anyOf, properties, ...remaining } = schema;
// Merge in all the non-oneOf/anyOf properties and also skip the special ADDITIONAL_PROPERTY_FLAG property
unset(remaining, ADDITIONAL_PROPERTY_FLAG);
optionSchema = !isEmpty(remaining) ? (mergeSchemas(remaining, option) as S) : option;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/anyOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('anyOf', () => {

expect(node.querySelectorAll('select')).to.have.length.of(1);
expect(node.querySelector('select').id).eql('root__anyof_select');
expect(node.querySelectorAll('span.required')).to.have.length.of(2);
expect(node.querySelectorAll('span.required')).to.have.length.of(1);
});

it('should render a select element if the anyOf keyword is present, merges top level and anyOf required', () => {
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('anyOf', () => {

expect(node.querySelectorAll('select')).to.have.length.of(1);
expect(node.querySelector('select').id).eql('root__anyof_select');
expect(node.querySelectorAll('span.required')).to.have.length.of(3);
expect(node.querySelectorAll('span.required')).to.have.length.of(2);
});

it('should render a root select element with default value', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/oneOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('oneOf', () => {

expect(node.querySelectorAll('select')).to.have.length.of(1);
expect(node.querySelector('select').id).eql('root__oneof_select');
expect(node.querySelectorAll('span.required')).to.have.length.of(2);
expect(node.querySelectorAll('span.required')).to.have.length.of(1);
});

it('should render a select element if the oneOf keyword is present, merges top level and oneOf required', () => {
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('oneOf', () => {

expect(node.querySelectorAll('select')).to.have.length.of(1);
expect(node.querySelector('select').id).eql('root__oneof_select');
expect(node.querySelectorAll('span.required')).to.have.length.of(3);
expect(node.querySelectorAll('span.required')).to.have.length.of(2);
});

it('should assign a default value and set defaults on option change', () => {
Expand Down

0 comments on commit 5684e36

Please sign in to comment.