Skip to content

Commit

Permalink
fix(json-schema): improve anyOf selection of primitive types
Browse files Browse the repository at this point in the history
fix #3980
  • Loading branch information
aitboudad committed Oct 13, 2024
1 parent 4fbc367 commit 74662f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/core/json-schema/src/formly-json-schema.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,30 @@ describe('Service: FormlyJsonschema', () => {

expect(field.model).toEqual({ foo: 'bar' });
});

it('should support anyOf using mixed type', () => {
const { field } = renderComponent({
model: { foo: [] },
schema: {
type: 'object',
properties: {
foo: {
anyOf: [{ type: 'object' }, { type: 'array' }],
},
},
},
});

const [
,
{
fieldGroup: [foo1Field, foo2Field],
},
] = field.fieldGroup[0].fieldGroup[0].fieldGroup;

expect(foo1Field.hide).toBeTruthy();
expect(foo2Field.hide).toBeFalsy();
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/core/json-schema/src/formly-json-schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,10 @@ export class FormlyJsonschema {
];
}

if (schema.oneOf && !field.type) {
if (schema.anyOf && !field.type) {
delete field.key;
field.fieldGroup = [
this.resolveMultiSchema('oneOf', <JSONSchema7[]>schema.oneOf, { ...options, key, shareFormControl: false }),
this.resolveMultiSchema('oneOf', <JSONSchema7[]>schema.anyOf, { ...options, key, shareFormControl: false }),
];
}

Expand Down

0 comments on commit 74662f6

Please sign in to comment.