mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-28 19:43:43 +03:00
feat: add option to hide the example code when using the SchemaDefinition
component (#2157)
This commit is contained in:
parent
1697d2ce78
commit
168189b2fd
|
@ -14,6 +14,7 @@ export interface ObjectDescriptionProps {
|
||||||
exampleRef?: string;
|
exampleRef?: string;
|
||||||
showReadOnly?: boolean;
|
showReadOnly?: boolean;
|
||||||
showWriteOnly?: boolean;
|
showWriteOnly?: boolean;
|
||||||
|
showExample?: boolean;
|
||||||
parser: OpenAPIParser;
|
parser: OpenAPIParser;
|
||||||
options: RedocNormalizedOptions;
|
options: RedocNormalizedOptions;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +54,7 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { showReadOnly = true, showWriteOnly = false } = this.props;
|
const { showReadOnly = true, showWriteOnly = false, showExample = true } = this.props;
|
||||||
return (
|
return (
|
||||||
<Section>
|
<Section>
|
||||||
<Row>
|
<Row>
|
||||||
|
@ -64,11 +65,16 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
|
||||||
schema={this.mediaModel.schema}
|
schema={this.mediaModel.schema}
|
||||||
/>
|
/>
|
||||||
</MiddlePanel>
|
</MiddlePanel>
|
||||||
<DarkRightPanel>
|
{showExample && (
|
||||||
<MediaSamplesWrap>
|
<DarkRightPanel>
|
||||||
<MediaTypeSamples renderDropdown={this.renderDropdown} mediaType={this.mediaModel} />
|
<MediaSamplesWrap>
|
||||||
</MediaSamplesWrap>
|
<MediaTypeSamples
|
||||||
</DarkRightPanel>
|
renderDropdown={this.renderDropdown}
|
||||||
|
mediaType={this.mediaModel}
|
||||||
|
/>
|
||||||
|
</MediaSamplesWrap>
|
||||||
|
</DarkRightPanel>
|
||||||
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
|
82
src/components/__tests__/SchemaDefinition.test.tsx
Normal file
82
src/components/__tests__/SchemaDefinition.test.tsx
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/* tslint:disable:no-implicit-dependencies */
|
||||||
|
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { SchemaDefinition } from '..';
|
||||||
|
import { OpenAPIParser } from '../../services';
|
||||||
|
import { RedocNormalizedOptions } from '../../services/RedocNormalizedOptions';
|
||||||
|
import { withTheme } from '../testProviders';
|
||||||
|
|
||||||
|
const options = new RedocNormalizedOptions({});
|
||||||
|
describe('Components', () => {
|
||||||
|
describe('SchemaDefinition', () => {
|
||||||
|
const parser = new OpenAPIParser(
|
||||||
|
{
|
||||||
|
openapi: '3.0',
|
||||||
|
info: {
|
||||||
|
title: 'test',
|
||||||
|
version: '0',
|
||||||
|
},
|
||||||
|
paths: {},
|
||||||
|
components: {
|
||||||
|
schemas: {
|
||||||
|
test: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
id: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
undefined,
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
|
describe('Show example constraints', () => {
|
||||||
|
it('should show the example as default', () => {
|
||||||
|
const component = shallow(
|
||||||
|
withTheme(
|
||||||
|
<SchemaDefinition
|
||||||
|
schemaRef="#/components/schemas/test"
|
||||||
|
parser={parser}
|
||||||
|
options={options}
|
||||||
|
/>,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(component.html().includes('<code>')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show the example if `showExample` is `true`', () => {
|
||||||
|
const component = shallow(
|
||||||
|
withTheme(
|
||||||
|
<SchemaDefinition
|
||||||
|
schemaRef="#/components/schemas/test"
|
||||||
|
parser={parser}
|
||||||
|
options={options}
|
||||||
|
showExample={true}
|
||||||
|
/>,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(component.html().includes('<code>')).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should hide the example if `showExample` is `false`', () => {
|
||||||
|
const component = shallow(
|
||||||
|
withTheme(
|
||||||
|
<SchemaDefinition
|
||||||
|
schemaRef="#/components/schemas/test"
|
||||||
|
parser={parser}
|
||||||
|
options={options}
|
||||||
|
showExample={false}
|
||||||
|
/>,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(component.html().includes('<code>')).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user