Skip to content

Commit

Permalink
fix: Fixes #3808 Duplciate AnyOf/OneOf Description (#3841)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendtxealth committed Aug 28, 2023
1 parent 0456cde commit 89df5cd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
should change the heading of the (upcoming) version to include a major version bump.
-->
# 5.12.2

## @rjsf/core

- Updated `MultiSchemaField` to only merge top level required field fixing duplicate field and description.

# 5.12.1

## @rjsf/validator-ajv8
Expand Down
9 changes: 3 additions & 6 deletions packages/core/src/components/fields/MultiSchemaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Component } from 'react';
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';
import omit from 'lodash/omit';
import unset from 'lodash/unset';
import {
ADDITIONAL_PROPERTY_FLAG,
deepEquals,
ERRORS_KEY,
FieldProps,
Expand Down Expand Up @@ -172,11 +170,10 @@ class AnyOfField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
let optionSchema: S;

if (option) {
// merge all top level fields except properties
const { oneOf, anyOf, properties, ...remaining } = schema;
// merge top level required field
const { required } = 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;
optionSchema = required ? (mergeSchemas({ required }, option) as S) : option;
}

const translateEnum: TranslatableString = title
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/anyOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('anyOf', () => {
properties: {
baz: { type: 'number' },
},
description: 'top level description',
anyOf: [
{
properties: {
Expand All @@ -61,6 +62,8 @@ 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(1);
expect(node.querySelectorAll('#root__description')).to.have.length.of(1);
expect(node.querySelectorAll('#root_baz')).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
3 changes: 3 additions & 0 deletions packages/core/test/oneOf.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('oneOf', () => {
properties: {
baz: { type: 'number' },
},
description: 'top level description',
oneOf: [
{
properties: {
Expand All @@ -62,6 +63,8 @@ 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(1);
expect(node.querySelectorAll('#root__description')).to.have.length.of(1);
expect(node.querySelectorAll('#root_baz')).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

0 comments on commit 89df5cd

Please sign in to comment.