Skip to content

Commit

Permalink
Prevent TypeError for missing labels in render info combinator (#2169)
Browse files Browse the repository at this point in the history
- Prevent TypeError in case sub schema doesn't have a title and there is no resolved sub schema
- Add test case
  • Loading branch information
DrewHoo authored Aug 11, 2023
1 parent 22d14d3 commit e685ae8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/core/src/util/combinators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const createCombinatorRenderInfos = (
),
label:
subSchema.title ??
resolvedSubSchema.title ??
resolvedSubSchema?.title ??
`${keyword}-${subSchemaIndex}`,
};
});
31 changes: 31 additions & 0 deletions packages/core/test/util/combinators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit e685ae8

Please sign in to comment.