Skip to content

Commit d3cc636

Browse files
authored
Merge pull request #3868 from thompsongl/ft/3052-extensions
parameter & operation extensions display
2 parents 7b13f41 + 32ff344 commit d3cc636

File tree

19 files changed

+130
-15
lines changed

19 files changed

+130
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ deepLinking | If set to `true`, enables dynamic deep linking for tags and operat
165165
requestInterceptor | MUST be a function. Function to intercept try-it-out requests. Accepts one argument requestInterceptor(request) and must return the potentially modified request.
166166
responseInterceptor | MUST be a function. Function to intercept try-it-out responses. Accepts one argument responseInterceptor(response) and must return the potentially modified response.
167167
showMutatedRequest | If set to `true` (the default), uses the mutated request returned from a rquestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used.
168+
showExtensions | Controls the display of vendor extension (`x-`) fields and values for Operations, Parameters, and Schema. The default is `false`.
168169

169170
### Plugins
170171

src/core/components/array-model.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class ArrayModel extends Component {
77
static propTypes = {
88
schema: PropTypes.object.isRequired,
99
getComponent: PropTypes.func.isRequired,
10+
getConfigs: PropTypes.func.isRequired,
1011
specSelectors: PropTypes.object.isRequired,
1112
name: PropTypes.string,
1213
required: PropTypes.bool,
@@ -15,7 +16,7 @@ export default class ArrayModel extends Component {
1516
}
1617

1718
render(){
18-
let { getComponent, schema, depth, expandDepth, name } = this.props
19+
let { getComponent, getConfigs, schema, depth, expandDepth, name } = this.props
1920
let description = schema.get("description")
2021
let items = schema.get("items")
2122
let title = schema.get("title") || name
@@ -46,7 +47,7 @@ export default class ArrayModel extends Component {
4647
!description ? null :
4748
<Markdown source={ description } />
4849
}
49-
<span><Model { ...this.props } name={null} schema={ items } required={ false } depth={ depth + 1 } /></span>
50+
<span><Model { ...this.props } getConfigs={ getConfigs } name={null} schema={ items } required={ false } depth={ depth + 1 } /></span>
5051
]
5152
</ModelCollapse>
5253
</span>

src/core/components/model-example.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export default class ModelExample extends React.Component {
5252
{
5353
!isExecute && this.state.activeTab === "model" && <ModelWrapper schema={ schema }
5454
getComponent={ getComponent }
55+
getConfigs={ getConfigs }
5556
specSelectors={ specSelectors }
5657
expandDepth={ defaultModelExpandDepth } />
5758

src/core/components/model-wrapper.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ export default class ModelComponent extends Component {
66
schema: PropTypes.object.isRequired,
77
name: PropTypes.string,
88
getComponent: PropTypes.func.isRequired,
9+
getConfigs: PropTypes.func.isRequired,
910
specSelectors: PropTypes.object.isRequired,
1011
expandDepth: PropTypes.number
1112
}
1213

1314
render(){
14-
let { getComponent } = this.props
15+
let { getComponent, getConfigs } = this.props
1516
const Model = getComponent("Model")
1617

1718
return <div className="model-box">
18-
<Model { ...this.props } depth={ 1 } expandDepth={ this.props.expandDepth || 0 }/>
19+
<Model { ...this.props } getConfigs={ getConfigs } depth={ 1 } expandDepth={ this.props.expandDepth || 0 }/>
1920
</div>
2021
}
2122
}
22-
23-

src/core/components/model.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default class Model extends PureComponent {
66
static propTypes = {
77
schema: ImPropTypes.orderedMap.isRequired,
88
getComponent: PropTypes.func.isRequired,
9+
getConfigs: PropTypes.func.isRequired,
910
specSelectors: PropTypes.object.isRequired,
1011
name: PropTypes.string,
1112
isRef: PropTypes.bool,
@@ -30,7 +31,7 @@ export default class Model extends PureComponent {
3031
}
3132

3233
render () {
33-
let { getComponent, specSelectors, schema, required, name, isRef } = this.props
34+
let { getComponent, getConfigs, specSelectors, schema, required, name, isRef } = this.props
3435
const ObjectModel = getComponent("ObjectModel")
3536
const ArrayModel = getComponent("ArrayModel")
3637
const PrimitiveModel = getComponent("PrimitiveModel")
@@ -54,13 +55,15 @@ export default class Model extends PureComponent {
5455
case "object":
5556
return <ObjectModel
5657
className="object" { ...this.props }
58+
getConfigs={ getConfigs }
5759
schema={ schema }
5860
name={ name }
5961
deprecated={deprecated}
6062
isRef={ isRef } />
6163
case "array":
6264
return <ArrayModel
6365
className="array" { ...this.props }
66+
getConfigs={ getConfigs }
6467
schema={ schema }
6568
name={ name }
6669
deprecated={deprecated}
@@ -73,6 +76,7 @@ export default class Model extends PureComponent {
7376
return <PrimitiveModel
7477
{ ...this.props }
7578
getComponent={ getComponent }
79+
getConfigs={ getConfigs }
7680
schema={ schema }
7781
name={ name }
7882
deprecated={deprecated}

src/core/components/models.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default class Models extends Component {
3636
expandDepth={ defaultModelExpandDepth }
3737
schema={ model }
3838
getComponent={ getComponent }
39+
getConfigs={ getConfigs }
3940
specSelectors={ specSelectors }/>
4041
</div>
4142
}).toArray()

src/core/components/object-model.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default class ObjectModel extends Component {
99
static propTypes = {
1010
schema: PropTypes.object.isRequired,
1111
getComponent: PropTypes.func.isRequired,
12+
getConfigs: PropTypes.func.isRequired,
1213
specSelectors: PropTypes.object.isRequired,
1314
name: PropTypes.string,
1415
isRef: PropTypes.bool,
@@ -17,7 +18,7 @@ export default class ObjectModel extends Component {
1718
}
1819

1920
render(){
20-
let { schema, name, isRef, getComponent, depth, expandDepth, ...otherProps } = this.props
21+
let { schema, name, isRef, getComponent, getConfigs, depth, expandDepth, ...otherProps } = this.props
2122
let { specSelectors } = otherProps
2223
let { isOAS3 } = specSelectors
2324

@@ -91,6 +92,7 @@ export default class ObjectModel extends Component {
9192
<Model key={ `object-${name}-${key}_${value}` } { ...otherProps }
9293
required={ isRequired }
9394
getComponent={ getComponent }
95+
getConfigs={ getConfigs }
9496
schema={ value }
9597
depth={ depth + 1 } />
9698
</td>
@@ -104,6 +106,7 @@ export default class ObjectModel extends Component {
104106
<td>
105107
<Model { ...otherProps } required={ false }
106108
getComponent={ getComponent }
109+
getConfigs={ getConfigs }
107110
schema={ additionalProperties }
108111
depth={ depth + 1 } />
109112
</td>
@@ -117,6 +120,7 @@ export default class ObjectModel extends Component {
117120
{anyOf.map((schema, k) => {
118121
return <div key={k}><Model { ...otherProps } required={ false }
119122
getComponent={ getComponent }
123+
getConfigs={ getConfigs }
120124
schema={ schema }
121125
depth={ depth + 1 } /></div>
122126
})}
@@ -131,6 +135,7 @@ export default class ObjectModel extends Component {
131135
{oneOf.map((schema, k) => {
132136
return <div key={k}><Model { ...otherProps } required={ false }
133137
getComponent={ getComponent }
138+
getConfigs={ getConfigs }
134139
schema={ schema }
135140
depth={ depth + 1 } /></div>
136141
})}
@@ -146,9 +151,10 @@ export default class ObjectModel extends Component {
146151
<Model { ...otherProps }
147152
required={ false }
148153
getComponent={ getComponent }
154+
getConfigs={ getConfigs }
149155
schema={ not }
150156
depth={ depth + 1 } />
151-
</div>
157+
</div>
152158
</td>
153159
</tr>
154160
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
4+
export const OperationExtRow = ({ xKey, xVal }) => {
5+
return (<tr>
6+
<td>{ xKey }</td>
7+
<td>{ String(xVal) }</td>
8+
</tr>)
9+
}
10+
OperationExtRow.propTypes = {
11+
xKey: PropTypes.string,
12+
xVal: PropTypes.any
13+
}
14+
15+
export default OperationExtRow
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from "react"
2+
import PropTypes from "prop-types"
3+
4+
export const OperationExt = ({ extensions, getComponent }) => {
5+
let OperationExtRow = getComponent("OperationExtRow")
6+
return (
7+
<div className="opblock-section">
8+
<div className="opblock-section-header">
9+
<h4>Extensions</h4>
10+
</div>
11+
<div className="table-container">
12+
13+
<table>
14+
<thead>
15+
<tr>
16+
<td className="col col_header">Field</td>
17+
<td className="col col_header">Value</td>
18+
</tr>
19+
</thead>
20+
<tbody>
21+
{
22+
extensions.entrySeq().map(([k, v]) => <OperationExtRow key={`${k}-${v}`} xKey={k} xVal={v} />)
23+
}
24+
</tbody>
25+
</table>
26+
</div>
27+
</div>
28+
)
29+
}
30+
OperationExt.propTypes = {
31+
extensions: PropTypes.object.isRequired,
32+
getComponent: PropTypes.func.isRequired
33+
}
34+
35+
export default OperationExt

src/core/components/operation.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { PureComponent } from "react"
22
import PropTypes from "prop-types"
33
import { getList } from "core/utils"
4-
import { sanitizeUrl } from "core/utils"
4+
import { getExtensions, sanitizeUrl } from "core/utils"
55
import { Iterable } from "immutable"
66

77
export default class Operation extends PureComponent {
@@ -85,6 +85,7 @@ export default class Operation extends PureComponent {
8585
let parameters = getList(operation, ["parameters"])
8686
let operationScheme = specSelectors.operationScheme(path, method)
8787
let isShownKey = ["operations", tag, operationId]
88+
let extensions = getExtensions(operation)
8889

8990
const Responses = getComponent("responses")
9091
const Parameters = getComponent( "parameters" )
@@ -95,6 +96,9 @@ export default class Operation extends PureComponent {
9596
const Collapse = getComponent( "Collapse" )
9697
const Markdown = getComponent( "Markdown" )
9798
const Schemes = getComponent( "schemes" )
99+
const OperationExt = getComponent( "OperationExt" )
100+
101+
const { showExtensions } = getConfigs()
98102

99103
// Merge in Live Response
100104
if(responses && response && response.size > 0) {
@@ -160,6 +164,7 @@ export default class Operation extends PureComponent {
160164
</div>
161165
</div> : null
162166
}
167+
163168
<Parameters
164169
parameters={parameters}
165170
operation={operation}
@@ -225,6 +230,10 @@ export default class Operation extends PureComponent {
225230
displayRequestDuration={ displayRequestDuration }
226231
fn={fn} />
227232
}
233+
234+
{ !showExtensions || !extensions.size ? null :
235+
<OperationExt extensions={ extensions } getComponent={ getComponent } />
236+
}
228237
</div>
229238
</Collapse>
230239
</div>

0 commit comments

Comments
 (0)