Skip to content

Commit 74662f6

Browse files
committed
fix(json-schema): improve anyOf selection of primitive types
fix #3980
1 parent 4fbc367 commit 74662f6

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/core/json-schema/src/formly-json-schema.service.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,30 @@ describe('Service: FormlyJsonschema', () => {
18001800

18011801
expect(field.model).toEqual({ foo: 'bar' });
18021802
});
1803+
1804+
it('should support anyOf using mixed type', () => {
1805+
const { field } = renderComponent({
1806+
model: { foo: [] },
1807+
schema: {
1808+
type: 'object',
1809+
properties: {
1810+
foo: {
1811+
anyOf: [{ type: 'object' }, { type: 'array' }],
1812+
},
1813+
},
1814+
},
1815+
});
1816+
1817+
const [
1818+
,
1819+
{
1820+
fieldGroup: [foo1Field, foo2Field],
1821+
},
1822+
] = field.fieldGroup[0].fieldGroup[0].fieldGroup;
1823+
1824+
expect(foo1Field.hide).toBeTruthy();
1825+
expect(foo2Field.hide).toBeFalsy();
1826+
});
18031827
});
18041828
});
18051829

src/core/json-schema/src/formly-json-schema.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,10 @@ export class FormlyJsonschema {
498498
];
499499
}
500500

501-
if (schema.oneOf && !field.type) {
501+
if (schema.anyOf && !field.type) {
502502
delete field.key;
503503
field.fieldGroup = [
504-
this.resolveMultiSchema('oneOf', <JSONSchema7[]>schema.oneOf, { ...options, key, shareFormControl: false }),
504+
this.resolveMultiSchema('oneOf', <JSONSchema7[]>schema.anyOf, { ...options, key, shareFormControl: false }),
505505
];
506506
}
507507

0 commit comments

Comments
 (0)