diff --git a/packages/core/src/components/fields/SchemaField.js b/packages/core/src/components/fields/SchemaField.js index 526c008b28..5f4087be23 100644 --- a/packages/core/src/components/fields/SchemaField.js +++ b/packages/core/src/components/fields/SchemaField.js @@ -362,7 +362,9 @@ function SchemaFieldRender(props) { onBlur={props.onBlur} onChange={props.onChange} onFocus={props.onFocus} - options={schema.anyOf} + options={schema.anyOf.map(_schema => + retrieveSchema(_schema, rootSchema, formData) + )} baseType={schema.type} registry={registry} schema={schema} @@ -380,7 +382,9 @@ function SchemaFieldRender(props) { onBlur={props.onBlur} onChange={props.onChange} onFocus={props.onFocus} - options={schema.oneOf} + options={schema.oneOf.map(_schema => + retrieveSchema(_schema, rootSchema, formData) + )} baseType={schema.type} registry={registry} schema={schema} diff --git a/packages/core/test/anyOf_test.js b/packages/core/test/anyOf_test.js index a7bc43e388..5a4349456b 100644 --- a/packages/core/test/anyOf_test.js +++ b/packages/core/test/anyOf_test.js @@ -639,6 +639,52 @@ describe("anyOf", () => { }); }); + it("should use title from refs schema before using fallback generated value as title", () => { + const schema = { + definitions: { + address: { + title: "Address", + type: "object", + properties: { + street: { + title: "Street", + type: "string", + }, + }, + }, + person: { + title: "Person", + type: "object", + properties: { + name: { + title: "Name", + type: "string", + }, + }, + }, + nested: { + $ref: "#/definitions/person", + }, + }, + anyOf: [ + { + $ref: "#/definitions/address", + }, + { + $ref: "#/definitions/nested", + }, + ], + }; + + const { node } = createFormComponent({ + schema, + }); + + let options = node.querySelectorAll("option"); + expect(options[0].firstChild.nodeValue).eql("Address"); + expect(options[1].firstChild.nodeValue).eql("Person"); + }); + describe("Arrays", () => { it("should correctly render form inputs for anyOf inside array items", () => { const schema = {