Skip to content

Commit

Permalink
fix: #3961 resolve all recurse list for object properties (#3981)
Browse files Browse the repository at this point in the history
* fix: resolve all recurse list for object properties

* update test

* simplfy logic

* revert

* update change log
  • Loading branch information
cwendtxealth committed Nov 28, 2023
1 parent bc16e29 commit ac6b3b0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ should change the heading of the (upcoming) version to include a major version b
-->
# 5.14.4

## @rjsf/utils

- Updated `resolveAllReferences()` to use own recurse list for each object properties, fixing [#3961](https://github.com/rjsf-team/react-jsonschema-form/issues/3961)

## Dev

- add missing typescript project reference for `utils` in `validator-ajv6` and `validator-ajv8` packages tsconfigs

# 5.14.3
Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/Form.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1354,23 +1354,23 @@ describeRepeated('Form common', (createFormComponent) => {
name: 'required',
params: { missingProperty: 'street_address' },
property: '.shipping_address.street_address',
schemaPath: '#/definitions/address/required',
schemaPath: '#/properties/shipping_address/required',
stack: "must have required property 'street_address'",
},
{
message: "must have required property 'city'",
name: 'required',
params: { missingProperty: 'city' },
property: '.shipping_address.city',
schemaPath: '#/definitions/address/required',
schemaPath: '#/properties/shipping_address/required',
stack: "must have required property 'city'",
},
{
message: "must have required property 'state'",
name: 'required',
params: { missingProperty: 'state' },
property: '.shipping_address.state',
schemaPath: '#/definitions/address/required',
schemaPath: '#/properties/shipping_address/required',
stack: "must have required property 'state'",
},
]);
Expand Down
9 changes: 8 additions & 1 deletion packages/utils/src/schema/retrieveSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import isEqual from 'lodash/isEqual';
import set from 'lodash/set';
import times from 'lodash/times';
import transform from 'lodash/transform';
import merge from 'lodash/merge';
import flattenDeep from 'lodash/flattenDeep';
import uniq from 'lodash/uniq';
import mergeAllOf, { Options } from 'json-schema-merge-allof';

import {
Expand Down Expand Up @@ -265,13 +268,17 @@ export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(
}

if (PROPERTIES_KEY in resolvedSchema) {
const childrenLists: string[][] = [];
const updatedProps = transform(
resolvedSchema[PROPERTIES_KEY]!,
(result, value, key: string) => {
result[key] = resolveAllReferences(value as S, rootSchema, recurseList);
const childList: string[] = [...recurseList];
result[key] = resolveAllReferences(value as S, rootSchema, childList);
childrenLists.push(childList);
},
{} as RJSFSchema
);
merge(recurseList, uniq(flattenDeep(childrenLists)));
resolvedSchema = { ...resolvedSchema, [PROPERTIES_KEY]: updatedProps };
}

Expand Down

0 comments on commit ac6b3b0

Please sign in to comment.