Skip to content

Commit 375fa32

Browse files
committed
Fix description for allOf-inheriting child schemas
Fixes #2810
1 parent 81f0876 commit 375fa32

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

packages/elements-core/src/components/Docs/Model/Model.spec.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ describe('Model', () => {
135135
expect(textboxDescription).toHaveTextContent('example schema description');
136136
});
137137

138+
it('displays child description at top of doc for allOf-inheriting objects', async () => {
139+
const desc = 'child schema description';
140+
// allOf-inheriting properties from parent but having its own description
141+
const allOfSchema: JSONSchema7 = {
142+
allOf: [exampleSchema],
143+
description: desc,
144+
};
145+
render(<Model data={allOfSchema} />);
146+
const description = screen.queryAllByText(desc);
147+
const textboxDescription = screen.getByRole('textbox');
148+
149+
expect(description).toHaveLength(1);
150+
expect(textboxDescription).toHaveTextContent(desc);
151+
});
152+
138153
it('does not display description at top of doc for non-objects', async () => {
139154
render(<Model data={exampleStringSchema} />);
140155
const description = screen.queryByRole('textbox');

packages/elements-core/src/components/Docs/Model/Model.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ const ModelComponent: React.FC<ModelProps> = ({
9393

9494
const description = (
9595
<VStack spacing={10}>
96-
{data.description && data.type === 'object' && (
97-
<Box pos="relative">
98-
<MarkdownViewer role="textbox" markdown={data.description} />
99-
<NodeAnnotation change={descriptionChanged} />
100-
</Box>
101-
)}
96+
{data.description &&
97+
(data.type === 'object' || (data.allOf || []).some(s => (s as JSONSchema7).type === 'object')) && (
98+
<Box pos="relative">
99+
<MarkdownViewer role="textbox" markdown={data.description} />
100+
<NodeAnnotation change={descriptionChanged} />
101+
</Box>
102+
)}
102103

103104
<NodeVendorExtensions data={data} />
104105

0 commit comments

Comments
 (0)