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

fix: #3961 resolve all recurse list for object properties #3981

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the updated code, it will now resolve the property ref that was used multiple times.

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