1
1
import { observer } from 'mobx-react' ;
2
2
import * as React from 'react' ;
3
3
4
+ import styled from '../../styled-components' ;
5
+
4
6
import { SchemaModel } from '../../services/models' ;
5
7
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' ;
7
11
import { Field } from '../Fields/Field' ;
8
12
import { DiscriminatorDropdown } from './DiscriminatorDropdown' ;
9
13
import { SchemaProps } from './Schema' ;
@@ -18,6 +22,18 @@ export interface ObjectSchemaProps extends SchemaProps {
18
22
} ;
19
23
}
20
24
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
+
21
37
@observer
22
38
export class ObjectSchema extends React . Component < ObjectSchemaProps > {
23
39
static contextType = OptionsContext ;
@@ -29,55 +45,65 @@ export class ObjectSchema extends React.Component<ObjectSchemaProps> {
29
45
render ( ) {
30
46
const {
31
47
schema : { fields = [ ] } ,
32
- showTitle,
33
48
discriminator,
34
49
} = this . props ;
35
50
36
51
const needFilter = this . props . skipReadOnly || this . props . skipWriteOnly ;
37
52
38
53
const filteredFields = needFilter
39
54
? 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
+ } )
45
60
: fields ;
46
61
47
62
const expandByDefault = this . context . expandSingleSchemaField && filteredFields . length === 1 ;
48
63
49
64
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 >
81
107
) ;
82
108
}
83
109
}
0 commit comments