Skip to content

Commit b35d522

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

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

packages/elements-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stoplight/elements-core",
3-
"version": "9.0.6",
3+
"version": "9.0.7",
44
"sideEffects": [
55
"web-components.min.js",
66
"src/web-components/**",

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

packages/elements-dev-portal/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stoplight/elements-dev-portal",
3-
"version": "3.0.6",
3+
"version": "3.0.7",
44
"description": "UI components for composing beautiful developer documentation.",
55
"keywords": [],
66
"sideEffects": [
@@ -66,7 +66,7 @@
6666
"dependencies": {
6767
"@stoplight/markdown-viewer": "^5.7.1",
6868
"@stoplight/mosaic": "^1.53.4",
69-
"@stoplight/elements-core": "~9.0.6",
69+
"@stoplight/elements-core": "~9.0.7",
7070
"@stoplight/path": "^1.3.2",
7171
"@stoplight/types": "^14.0.0",
7272
"classnames": "^2.2.6",

packages/elements/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stoplight/elements",
3-
"version": "9.0.6",
3+
"version": "9.0.7",
44
"description": "UI components for composing beautiful developer documentation.",
55
"keywords": [],
66
"sideEffects": [
@@ -63,7 +63,7 @@
6363
]
6464
},
6565
"dependencies": {
66-
"@stoplight/elements-core": "~9.0.4",
66+
"@stoplight/elements-core": "~9.0.7",
6767
"@stoplight/http-spec": "^7.1.0",
6868
"@stoplight/json": "^3.18.1",
6969
"@stoplight/mosaic": "^1.53.4",
@@ -109,4 +109,4 @@
109109
"release": {
110110
"extends": "@stoplight/scripts/release"
111111
}
112-
}
112+
}

0 commit comments

Comments
 (0)