Skip to content

Commit

Permalink
Compiled/ExpandAllBranches Resolve AllOf Schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendtxealth committed Jul 13, 2023
1 parent 6d330ec commit 011153c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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 schema) {
// resolve allOf schemas
if (expandAllBranches) {
return [...(resolvedSchema.allOf as S[])];
}
try {
resolvedSchema = mergeAllOf(s, {
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 011153c

Please sign in to comment.