Skip to content

Commit 9b6f2a1

Browse files
committed
Apply changes from Redocly#1035
1 parent 040ce72 commit 9b6f2a1

File tree

6 files changed

+181
-138
lines changed

6 files changed

+181
-138
lines changed

src/common-elements/fields-layout.ts

-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
import styled, { extensionsHook, media } from '../styled-components';
44
import { deprecatedCss } from './mixins';
55

6-
export const PropertiesTableCaption = styled.caption`
7-
text-align: right;
8-
font-size: 0.9em;
9-
font-weight: normal;
10-
color: ${props => props.theme.colors.text.secondary};
11-
`;
126

137
export const PropertyCell = styled.td<{ kind?: string }>`
148
border-left: 1px solid ${props => props.theme.schema.linesColor};

src/components/Fields/Field.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class Field extends React.Component<FieldProps> {
9393
schema={field.schema}
9494
skipReadOnly={this.props.skipReadOnly}
9595
skipWriteOnly={this.props.skipWriteOnly}
96-
showTitle={this.props.showTitle}
96+
hideObjectTitle={this.props.hideObjectTitle}
9797
/>
9898
</InnerPropertiesWrap>
9999
</PropertyCellWithInner>
+64-38
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { observer } from 'mobx-react';
22
import * as React from 'react';
33

4+
import styled from '../../styled-components';
5+
46
import { SchemaModel } from '../../services/models';
57

6-
import { PropertiesTable, PropertiesTableCaption } from '../../common-elements/fields-layout';
8+
import { H3 } from '../../common-elements/headers';
9+
import { Markdown } from '../Markdown/Markdown';
10+
import { PropertiesTable } from '../../common-elements/fields-layout';
711
import { Field } from '../Fields/Field';
812
import { DiscriminatorDropdown } from './DiscriminatorDropdown';
913
import { SchemaProps } from './Schema';
@@ -18,6 +22,18 @@ export interface ObjectSchemaProps extends SchemaProps {
1822
};
1923
}
2024

25+
export const ObjectSchemaDetails = styled.div`
26+
margin: 0 0 0.5em 0;
27+
`;
28+
29+
export const ObjectSchemaTitle = styled(H3)`
30+
margin: 0.5em 0 0 0;
31+
`;
32+
33+
export const ObjectSchemaDescription = styled.div`
34+
margin: 0.5em 0 0 0;
35+
`;
36+
2137
@observer
2238
export class ObjectSchema extends React.Component<ObjectSchemaProps> {
2339
static contextType = OptionsContext;
@@ -29,55 +45,65 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
2945
render() {
3046
const {
3147
schema: { fields = [] },
32-
showTitle,
3348
discriminator,
3449
} = this.props;
3550

3651
const needFilter = this.props.skipReadOnly || this.props.skipWriteOnly;
3752

3853
const filteredFields = needFilter
3954
? fields.filter(item => {
40-
return !(
41-
(this.props.skipReadOnly && item.schema.readOnly) ||
42-
(this.props.skipWriteOnly && item.schema.writeOnly)
43-
);
44-
})
55+
return !(
56+
(this.props.skipReadOnly && item.schema.readOnly) ||
57+
(this.props.skipWriteOnly && item.schema.writeOnly)
58+
);
59+
})
4560
: fields;
4661

4762
const expandByDefault = this.context.expandSingleSchemaField && filteredFields.length === 1;
4863

4964
return (
50-
<PropertiesTable>
51-
{showTitle && <PropertiesTableCaption>{this.props.schema.title}</PropertiesTableCaption>}
52-
<tbody>
53-
{mapWithLast(filteredFields, (field, isLast) => {
54-
return (
55-
<Field
56-
key={field.name}
57-
isLast={isLast}
58-
field={field}
59-
expandByDefault={expandByDefault}
60-
renderDiscriminatorSwitch={
61-
(discriminator &&
62-
discriminator.fieldName === field.name &&
63-
(() => (
64-
<DiscriminatorDropdown
65-
parent={this.parentSchema}
66-
enumValues={field.schema.enum}
67-
/>
68-
))) ||
69-
undefined
70-
}
71-
className={field.expanded ? 'expanded' : undefined}
72-
showExamples={false}
73-
skipReadOnly={this.props.skipReadOnly}
74-
skipWriteOnly={this.props.skipWriteOnly}
75-
showTitle={this.props.showTitle}
76-
/>
77-
);
78-
})}
79-
</tbody>
80-
</PropertiesTable>
65+
<div>
66+
<ObjectSchemaDetails>
67+
{!this.props.hideObjectTitle && (
68+
<ObjectSchemaTitle>{this.props.schema.title}</ObjectSchemaTitle>
69+
)}
70+
{!this.props.hideObjectDescription && (
71+
<ObjectSchemaDescription>
72+
<Markdown compact={true} source={this.props.schema.description} />
73+
</ObjectSchemaDescription>
74+
)}
75+
</ObjectSchemaDetails>
76+
77+
<PropertiesTable>
78+
<tbody>
79+
{mapWithLast(filteredFields, (field, isLast) => {
80+
return (
81+
<Field
82+
key={field.name}
83+
isLast={isLast}
84+
field={field}
85+
expandByDefault={expandByDefault}
86+
renderDiscriminatorSwitch={
87+
(discriminator &&
88+
discriminator.fieldName === field.name &&
89+
(() => (
90+
<DiscriminatorDropdown
91+
parent={this.parentSchema}
92+
enumValues={field.schema.enum}
93+
/>
94+
))) ||
95+
undefined
96+
}
97+
className={field.expanded ? 'expanded' : undefined}
98+
showExamples={false}
99+
skipReadOnly={this.props.skipReadOnly}
100+
skipWriteOnly={this.props.skipWriteOnly}
101+
/>
102+
);
103+
})}
104+
</tbody>
105+
</PropertiesTable>
106+
</div>
81107
);
82108
}
83109
}

src/components/Schema/Schema.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import { OneOfSchema } from './OneOfSchema';
1313
import { l } from '../../services/Labels';
1414

1515
export interface SchemaOptions {
16-
showTitle?: boolean;
1716
skipReadOnly?: boolean;
1817
skipWriteOnly?: boolean;
18+
hideObjectTitle?: boolean;
19+
hideObjectDescription?: boolean;
1920
}
2021

2122
export interface SchemaProps extends SchemaOptions {

src/components/SchemaDefinition/SchemaDefinition.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export interface ObjectDescriptionProps {
1414
exampleRef?: string;
1515
showReadOnly?: boolean;
1616
showWriteOnly?: boolean;
17+
showObjectTitle?: boolean;
18+
showObjectDescription?: boolean;
1719
parser: OpenAPIParser;
1820
options: RedocNormalizedOptions;
1921
}
@@ -53,14 +55,21 @@ export class SchemaDefinition extends React.PureComponent<ObjectDescriptionProps
5355
}
5456

5557
render() {
56-
const { showReadOnly = true, showWriteOnly = false } = this.props;
58+
const {
59+
showReadOnly = true,
60+
showWriteOnly = false,
61+
showObjectTitle = false,
62+
showObjectDescription = false,
63+
} = this.props;
5764
return (
5865
<Section>
5966
<Row>
6067
<MiddlePanel>
6168
<Schema
6269
skipWriteOnly={!showWriteOnly}
6370
skipReadOnly={!showReadOnly}
71+
hideObjectTitle={!showObjectTitle}
72+
hideObjectDescription={!showObjectDescription}
6473
schema={this.mediaModel.schema}
6574
/>
6675
</MiddlePanel>

0 commit comments

Comments
 (0)