Skip to content

Commit

Permalink
fix: Fixes rjsf-team#3817 Precompiled schema allOf
Browse files Browse the repository at this point in the history
  • Loading branch information
cwendtxealth committed Aug 10, 2023
1 parent f51ce0c commit e0ebe71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/utils/src/schema/retrieveSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ export function retrieveSchemaInternal<
if (ALL_OF_KEY in resolvedSchema) {
// resolve allOf schemas
if (expandAllBranches) {
return [...(resolvedSchema.allOf as S[])];
const { allOf, ...restOfSchema } = resolvedSchema;
return [...(allOf as S[]), restOfSchema as S];
}
try {
resolvedSchema = mergeAllOf(resolvedSchema, {
Expand Down
9 changes: 7 additions & 2 deletions packages/utils/test/schema/retrieveSchemaTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,13 +688,18 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) {
expect.any(Error)
);
});
it('should return allOf as individual schemas when expand all', () => {
it('should return allOf and top level schemas when expand all', () => {
const schema: RJSFSchema = {
properties: { test: { type: 'string' } },
allOf: [{ type: 'string' }, { type: 'boolean' }],
};
const rootSchema: RJSFSchema = { definitions: {} };
const formData = {};
expect(retrieveSchemaInternal(testValidator, schema, rootSchema, formData, true)).toEqual(schema.allOf);
const { allOf, ...restOfSchema } = schema;
expect(retrieveSchemaInternal(testValidator, schema, rootSchema, formData, true)).toEqual([
...allOf!,
restOfSchema,
]);
});
it('should merge types with $ref in them', () => {
const schema: RJSFSchema = {
Expand Down

0 comments on commit e0ebe71

Please sign in to comment.