Skip to content

Commit

Permalink
fix: References added under anyOf/oneOf/allOf remove the model descri…
Browse files Browse the repository at this point in the history
…ption
  • Loading branch information
SB-harshitajadhav committed Dec 6, 2024
1 parent f01e454 commit e56c51e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
57 changes: 57 additions & 0 deletions packages/elements-core/src/components/Docs/Model/Model.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,54 @@ const exampleStringSchema: JSONSchema7 = {
description: 'example schema description that should only show once :)',
};

const model_data: JSONSchema7 = {
title: 'operator_reference',
description: 'description from allOf Operator',
allOf: [
{
$ref: '#/%24defs/bird',
},
{
$ref: '#/%24defs/animal',
},
],

$defs: {
bird: {
type: 'object',
title: 'bird',
description: 'this is bird model',
properties: {
id: {
type: 'string',
},
bird_type: {
type: 'string',
},
},
},
animal: {
$ref: '#/%24defs/bird',
title: 'animal',
description: 'This is from Animal model',
},
},
};
const props = {
nodeTitle: 'operator_reference',
layoutOptions: {
hideExport: false,
},
exportProps: {
original: {
href: 'https://stoplight-local.com:8443/api/v1/projects/venkat/stop-95/nodes/models/operator_reference.yaml?fromExportButton=true&snapshotType=model',
},
bundled: {
href: 'https://api.stoplight-local.com:8443/projects/cHJqOjE2NA/branches/main/export/models/operator_reference.yaml',
},
},
};

describe('Model', () => {
it('displays examples', async () => {
const { container } = render(<Model data={exampleSchema} />);
Expand Down Expand Up @@ -237,5 +285,14 @@ describe('Model', () => {

unmount();
});
it('CombineSchema must have description', () => {
render(<Model data={model_data} {...props} />);
// const elem = screen.getByRole('paragraph', { name: /This is from Operaror_reference/ });
const elem = screen.getAllByText(/description from allOf Operator/);

// expect('This is from Operaror_reference').toBeInTheDocument();
// expect(elem).toBeInTheDocument();
expect(elem[0]).toBeInTheDocument();
});
});
});
2 changes: 1 addition & 1 deletion packages/elements-core/src/components/Docs/Model/Model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const ModelComponent: React.FC<ModelProps> = ({
const descriptionChanged = nodeHasChanged?.({ nodeId, attr: 'description' });
const description = (
<VStack spacing={10}>
{data.description && data.type === 'object' && (
{data.description && (
<Box pos="relative">
<MarkdownViewer role="textbox" markdown={data.description} />
<NodeAnnotation change={descriptionChanged} />
Expand Down

0 comments on commit e56c51e

Please sign in to comment.