Skip to content

Commit e685ae8

Browse files
authored
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
1 parent 22d14d3 commit e685ae8

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/core/src/util/combinators.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const createCombinatorRenderInfos = (
6262
),
6363
label:
6464
subSchema.title ??
65-
resolvedSubSchema.title ??
65+
resolvedSubSchema?.title ??
6666
`${keyword}-${subSchemaIndex}`,
6767
};
6868
});

packages/core/test/util/combinators.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,34 @@ test('createCombinatorRenderInfos - uses overrides for labels when subschemas ar
8080
t.deepEqual(duaRenderInfo.label, 'DuaOverride');
8181
t.deepEqual(lipaRenderInfo.label, 'LipaOverride');
8282
});
83+
84+
const schemaWithoutRefs = {
85+
type: 'object',
86+
properties: {
87+
widget: {
88+
anyOf: [
89+
{
90+
type: 'object',
91+
properties: { name: { type: 'string' } },
92+
},
93+
{
94+
type: 'object',
95+
properties: { name: { type: 'string' } },
96+
},
97+
],
98+
},
99+
},
100+
};
101+
102+
test('createCombinatorRenderInfos - uses keyword + index when no labels provided', (t) => {
103+
const [duaRenderInfo, lipaRenderInfo] = createCombinatorRenderInfos(
104+
schemaWithoutRefs.properties.widget.anyOf,
105+
schemaWithoutRefs,
106+
'anyOf',
107+
control,
108+
'widget',
109+
[]
110+
);
111+
t.deepEqual(duaRenderInfo.label, 'anyOf-0');
112+
t.deepEqual(lipaRenderInfo.label, 'anyOf-1');
113+
});

0 commit comments

Comments
 (0)