Skip to content

Commit

Permalink
Compiled/ExpandAllBranches Resolve AllOf Schemas (#3764)
Browse files Browse the repository at this point in the history
* Compiled/ExpandAllBranches Resolve AllOf Schemas

* update changelog.md
  • Loading branch information
cwendtxealth committed Jul 13, 2023
1 parent 0d5aab0 commit 2f891e7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 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.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

0 comments on commit 2f891e7

Please sign in to comment.