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(@rjsf/core): Nested into items schema allOf blocks with multiple … #3025

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/package.json
Expand Up @@ -44,7 +44,7 @@
"@types/json-schema": "^7.0.7",
"ajv": "^6.7.0",
"core-js-pure": "^3.6.5",
"json-schema-merge-allof": "^0.6.0",
"json-schema-merge-allof": "^0.8.1",
"jsonpointer": "^5.0.0",
"lodash": "^4.17.15",
"lodash-es": "^4.17.15",
Expand Down
32 changes: 1 addition & 31 deletions packages/core/src/utils.js
Expand Up @@ -755,39 +755,9 @@ export function retrieveSchema(schema, rootSchema = {}, formData = {}) {
return resolveCondition(schema, rootSchema, formData);
}

// For each level of the dependency, we need to recursively determine the appropriate resolved schema given the current state of formData.
// Otherwise, nested allOf subschemas will not be correctly displayed.
if (resolvedSchema.properties) {
const properties = {};

Object.entries(resolvedSchema.properties).forEach(entries => {
const propName = entries[0];
const propSchema = entries[1];
const rawPropData = formData && formData[propName];
const propData = isObject(rawPropData) ? rawPropData : {};
const resolvedPropSchema = retrieveSchema(
propSchema,
rootSchema,
propData
);

properties[propName] = resolvedPropSchema;

if (
propSchema !== resolvedPropSchema &&
resolvedSchema.properties !== properties
) {
resolvedSchema = { ...resolvedSchema, properties };
}
});
}

if ("allOf" in schema) {
try {
resolvedSchema = mergeAllOf({
...resolvedSchema,
allOf: resolvedSchema.allOf,
});
resolvedSchema = mergeAllOf(resolvedSchema, { deep: false });
} catch (e) {
console.warn("could not merge subschemas in allOf:\n" + e);
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
Expand Down
52 changes: 45 additions & 7 deletions packages/core/test/utils_test.js
Expand Up @@ -2671,14 +2671,52 @@ describe("utils", () => {
title: "Breed name",
type: "string",
},
Spots: {
default: "small",
enum: ["large", "small"],
title: "Spots",
type: "string",
},
},
required: ["BreedName", "Spots"],
allOf: [
{
if: {
required: ["BreedName"],
properties: {
BreedName: {
const: "Alsatian",
},
},
},
then: {
properties: {
Fur: {
default: "brown",
enum: ["black", "brown"],
title: "Fur",
type: "string",
},
},
required: ["Fur"],
},
},
{
if: {
required: ["BreedName"],
properties: {
BreedName: {
const: "Dalmation",
},
},
},
then: {
properties: {
Spots: {
default: "small",
enum: ["large", "small"],
title: "Spots",
type: "string",
},
},
required: ["Spots"],
},
},
],
required: ["BreedName"],
title: "Breed",
},
},
Expand Down
1 change: 0 additions & 1 deletion packages/playground/package.json
Expand Up @@ -54,7 +54,6 @@
"core-js": "^3.19.2",
"dayjs": "^1.8.28",
"framer-motion": "^5.5.5",
"json-schema-merge-allof": "^0.6.0",
"jss": "^10.0.3",
"less": "^3.11.3",
"less-loader": "^5.0.0",
Expand Down