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

Compiled/ExpandAllBranches Resolve AllOf Schemas #3764

Merged
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
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.10.1

## @rjsf/utils

- Updated `retrieveSchemaInternal()` to always resolve allOf schema without merging when `expandAllBranches` is set, fixing compiled schema issue always throwing error with `mergeAllOf`

# 5.10.0

## @rjsf/core
Expand Down
7 changes: 4 additions & 3 deletions packages/utils/src/schema/retrieveSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,16 +280,17 @@ export function retrieveSchemaInternal<
return resolveCondition<T, S, F>(validator, resolvedSchema, rootSchema, expandAllBranches, rawFormData as T);
}
if (ALL_OF_KEY in resolvedSchema) {
// resolve allOf schemas
if (expandAllBranches) {
return [...(resolvedSchema.allOf as S[])];
}
try {
resolvedSchema = mergeAllOf(resolvedSchema, {
deep: false,
} as Options) as S;
} catch (e) {
console.warn('could not merge subschemas in allOf:\n', e);
const { allOf, ...resolvedSchemaWithoutAllOf } = resolvedSchema;
if (expandAllBranches && allOf) {
return [resolvedSchemaWithoutAllOf as S, ...(allOf as S[])];
}
return resolvedSchemaWithoutAllOf as S;
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/utils/test/schema/retrieveSchemaTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getAllPermutationsOfXxxOf,
resolveAnyOrOneOfSchemas,
resolveCondition,
retrieveSchemaInternal,
stubExistingAdditionalProperties,
withDependentProperties,
withExactlyOneSubschema,
Expand Down Expand Up @@ -687,6 +688,14 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {
expect.any(Error)
);
});
it('should return allOf as individual schemas when expand all', () => {
const schema: RJSFSchema = {
allOf: [{ type: 'string' }, { type: 'boolean' }],
};
const rootSchema: RJSFSchema = { definitions: {} };
const formData = {};
expect(retrieveSchemaInternal(testValidator, schema, rootSchema, formData, true)).toEqual(schema.allOf);
});
it('should merge types with $ref in them', () => {
const schema: RJSFSchema = {
allOf: [{ $ref: '#/definitions/1' }, { $ref: '#/definitions/2' }],
Expand Down