mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-11-04 09:47:31 +03:00 
			
		
		
		
	Merge c5fa72c351 into 34623575ce
				
					
				
			This commit is contained in:
		
						commit
						6a29cb4be4
					
				| 
						 | 
					@ -1,5 +1,6 @@
 | 
				
			||||||
import * as React from 'react';
 | 
					import * as React from 'react';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { Markdown } from '../Markdown/Markdown';
 | 
				
			||||||
import { DarkRightPanel, MiddlePanel, MimeLabel, Row, Section } from '../../common-elements';
 | 
					import { DarkRightPanel, MiddlePanel, MimeLabel, Row, Section } from '../../common-elements';
 | 
				
			||||||
import { MediaTypeModel, OpenAPIParser, RedocNormalizedOptions } from '../../services';
 | 
					import { MediaTypeModel, OpenAPIParser, RedocNormalizedOptions } from '../../services';
 | 
				
			||||||
import styled from '../../styled-components';
 | 
					import styled from '../../styled-components';
 | 
				
			||||||
| 
						 | 
					@ -15,6 +16,7 @@ export interface ObjectDescriptionProps {
 | 
				
			||||||
  showReadOnly?: boolean;
 | 
					  showReadOnly?: boolean;
 | 
				
			||||||
  showWriteOnly?: boolean;
 | 
					  showWriteOnly?: boolean;
 | 
				
			||||||
  showExample?: boolean;
 | 
					  showExample?: boolean;
 | 
				
			||||||
 | 
					  showDescription?: boolean;
 | 
				
			||||||
  parser: OpenAPIParser;
 | 
					  parser: OpenAPIParser;
 | 
				
			||||||
  options: RedocNormalizedOptions;
 | 
					  options: RedocNormalizedOptions;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -54,11 +56,19 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  render() {
 | 
					  render() {
 | 
				
			||||||
    const { showReadOnly = true, showWriteOnly = false, showExample = true } = this.props;
 | 
					    const {
 | 
				
			||||||
 | 
					      showReadOnly = true,
 | 
				
			||||||
 | 
					      showWriteOnly = false,
 | 
				
			||||||
 | 
					      showExample = true,
 | 
				
			||||||
 | 
					      showDescription = false,
 | 
				
			||||||
 | 
					    } = this.props;
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <Section>
 | 
					      <Section>
 | 
				
			||||||
        <Row>
 | 
					        <Row>
 | 
				
			||||||
          <MiddlePanel>
 | 
					          <MiddlePanel>
 | 
				
			||||||
 | 
					            {showDescription && this.mediaModel.schema?.description && (
 | 
				
			||||||
 | 
					              <Markdown source={this.mediaModel.schema.description} />
 | 
				
			||||||
 | 
					            )}
 | 
				
			||||||
            <Schema
 | 
					            <Schema
 | 
				
			||||||
              skipWriteOnly={!showWriteOnly}
 | 
					              skipWriteOnly={!showWriteOnly}
 | 
				
			||||||
              skipReadOnly={!showReadOnly}
 | 
					              skipReadOnly={!showReadOnly}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,6 +22,15 @@ describe('Components', () => {
 | 
				
			||||||
        components: {
 | 
					        components: {
 | 
				
			||||||
          schemas: {
 | 
					          schemas: {
 | 
				
			||||||
            test: {
 | 
					            test: {
 | 
				
			||||||
 | 
					              description: 'schema_description',
 | 
				
			||||||
 | 
					              type: 'object',
 | 
				
			||||||
 | 
					              properties: {
 | 
				
			||||||
 | 
					                id: {
 | 
				
			||||||
 | 
					                  type: 'string',
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            test_no_description: {
 | 
				
			||||||
              type: 'object',
 | 
					              type: 'object',
 | 
				
			||||||
              properties: {
 | 
					              properties: {
 | 
				
			||||||
                id: {
 | 
					                id: {
 | 
				
			||||||
| 
						 | 
					@ -78,5 +87,68 @@ describe('Components', () => {
 | 
				
			||||||
        expect(component.html().includes('<code>')).toBe(false);
 | 
					        expect(component.html().includes('<code>')).toBe(false);
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    describe('Show description constraints', () => {
 | 
				
			||||||
 | 
					      it('should hide the description as default', () => {
 | 
				
			||||||
 | 
					        const component = shallow(
 | 
				
			||||||
 | 
					          withTheme(
 | 
				
			||||||
 | 
					            <SchemaDefinition
 | 
				
			||||||
 | 
					              schemaRef="#/components/schemas/test"
 | 
				
			||||||
 | 
					              parser={parser}
 | 
				
			||||||
 | 
					              options={options}
 | 
				
			||||||
 | 
					              showExample={false}
 | 
				
			||||||
 | 
					            />,
 | 
				
			||||||
 | 
					          ),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        expect(component.html().includes('schema_description')).toBe(false);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it('should hide the description if `showDescription` is `false`', () => {
 | 
				
			||||||
 | 
					        const component = shallow(
 | 
				
			||||||
 | 
					          withTheme(
 | 
				
			||||||
 | 
					            <SchemaDefinition
 | 
				
			||||||
 | 
					              schemaRef="#/components/schemas/test"
 | 
				
			||||||
 | 
					              parser={parser}
 | 
				
			||||||
 | 
					              options={options}
 | 
				
			||||||
 | 
					              showExample={false}
 | 
				
			||||||
 | 
					              showDescription={false}
 | 
				
			||||||
 | 
					            />,
 | 
				
			||||||
 | 
					          ),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        expect(component.html().includes('schema_description')).toBe(false);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it('should show the description if `showDescription` is `true`', () => {
 | 
				
			||||||
 | 
					        const component = shallow(
 | 
				
			||||||
 | 
					          withTheme(
 | 
				
			||||||
 | 
					            <SchemaDefinition
 | 
				
			||||||
 | 
					              schemaRef="#/components/schemas/test"
 | 
				
			||||||
 | 
					              parser={parser}
 | 
				
			||||||
 | 
					              options={options}
 | 
				
			||||||
 | 
					              showExample={false}
 | 
				
			||||||
 | 
					              showDescription={true}
 | 
				
			||||||
 | 
					            />,
 | 
				
			||||||
 | 
					          ),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        expect(component.html().includes('schema_description')).toBe(true);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      it('not to thrown error if `showDescription` is `true` and without description', () => {
 | 
				
			||||||
 | 
					        const component = shallow(
 | 
				
			||||||
 | 
					          withTheme(
 | 
				
			||||||
 | 
					            <SchemaDefinition
 | 
				
			||||||
 | 
					              schemaRef="#/components/schemas/test_no_description"
 | 
				
			||||||
 | 
					              parser={parser}
 | 
				
			||||||
 | 
					              options={options}
 | 
				
			||||||
 | 
					              showExample={false}
 | 
				
			||||||
 | 
					              showDescription={true}
 | 
				
			||||||
 | 
					            />,
 | 
				
			||||||
 | 
					          ),
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        expect(() => {
 | 
				
			||||||
 | 
					          component.html();
 | 
				
			||||||
 | 
					        }).not.toThrow();
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user