From e685ae88298b646a62f20674d594a43f9b1fd058 Mon Sep 17 00:00:00 2001 From: Drew Hoover Date: Fri, 11 Aug 2023 05:51:26 -0400 Subject: [PATCH] Prevent TypeError for missing labels in render info combinator (#2169) - Prevent TypeError in case sub schema doesn't have a title and there is no resolved sub schema - Add test case --- packages/core/src/util/combinators.ts | 2 +- packages/core/test/util/combinators.test.ts | 31 +++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/core/src/util/combinators.ts b/packages/core/src/util/combinators.ts index 9ebb3b6cc..60cb0f7f9 100644 --- a/packages/core/src/util/combinators.ts +++ b/packages/core/src/util/combinators.ts @@ -62,7 +62,7 @@ export const createCombinatorRenderInfos = ( ), label: subSchema.title ?? - resolvedSubSchema.title ?? + resolvedSubSchema?.title ?? `${keyword}-${subSchemaIndex}`, }; }); diff --git a/packages/core/test/util/combinators.test.ts b/packages/core/test/util/combinators.test.ts index 548760967..8b9115683 100644 --- a/packages/core/test/util/combinators.test.ts +++ b/packages/core/test/util/combinators.test.ts @@ -80,3 +80,34 @@ test('createCombinatorRenderInfos - uses overrides for labels when subschemas ar t.deepEqual(duaRenderInfo.label, 'DuaOverride'); t.deepEqual(lipaRenderInfo.label, 'LipaOverride'); }); + +const schemaWithoutRefs = { + type: 'object', + properties: { + widget: { + anyOf: [ + { + type: 'object', + properties: { name: { type: 'string' } }, + }, + { + type: 'object', + properties: { name: { type: 'string' } }, + }, + ], + }, + }, +}; + +test('createCombinatorRenderInfos - uses keyword + index when no labels provided', (t) => { + const [duaRenderInfo, lipaRenderInfo] = createCombinatorRenderInfos( + schemaWithoutRefs.properties.widget.anyOf, + schemaWithoutRefs, + 'anyOf', + control, + 'widget', + [] + ); + t.deepEqual(duaRenderInfo.label, 'anyOf-0'); + t.deepEqual(lipaRenderInfo.label, 'anyOf-1'); +});