Skip to content

Commit d0ffb2b

Browse files
authored
Merge pull request #4010 from heldersepu/master
Add defaultModelsExpandDepth
2 parents 5e72f68 + 87572a8 commit d0ffb2b

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

docs/usage/configuration.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ Parameter Name | Description
4949
--- | ---
5050
`deepLinking` | `Boolean=false`. If set to `true`, enables deep linking for tags and operations. See the [Deep Linking documentation](/docs/usage/deep-linking.md) for more information.
5151
`displayOperationId` | `Boolean=false`. Controls the display of operationId in operations list. The default is `false`.
52-
`defaultModelExpandDepth` | `Number=1`. The default expansion depth for models.
53-
`defaultModelRendering` | `String=["example"*, "model"]`. Controls how models are shown when the API is first rendered. (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links.)
52+
`defaultModelsExpandDepth` | `Number=1`. The default expansion depth for models (set to -1 completely hide the models).
53+
`defaultModelExpandDepth` | `Number=1`. The default expansion depth for the model on the model-example section.
54+
`defaultModelRendering` | `String=["example"*, "model"]`. Controls how the model is shown when the API is first rendered. (The user can always switch the rendering for a given model by clicking the 'Model' and 'Example Value' links.)
5455
`displayRequestDuration` | `Boolean=false`. Controls the display of the request duration (in milliseconds) for Try-It-Out requests.
5556
`docExpansion` | `String=["list"*, "full", "none"]`. Controls the default expansion setting for the operations and tags. It can be 'list' (expands only the tags), 'full' (expands the tags and operations) or 'none' (expands nothing).
5657
`filter` | `Boolean=false OR String`. If set, enables filtering. The top bar will show an edit box that you can use to filter the tagged operations that are shown. Can be Boolean to enable or disable, or a string, in which case filtering will be enabled using that string as the filter expression. Filtering is case sensitive matching the filter expression anywhere inside the tag.

src/core/components/models.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ export default class Models extends Component {
1313
render(){
1414
let { specSelectors, getComponent, layoutSelectors, layoutActions, getConfigs } = this.props
1515
let definitions = specSelectors.definitions()
16-
let { docExpansion, defaultModelExpandDepth } = getConfigs()
17-
let showModels = layoutSelectors.isShown("models", docExpansion === "full" || docExpansion === "list" )
16+
let { docExpansion, defaultModelsExpandDepth } = getConfigs()
17+
if (!definitions.size || defaultModelsExpandDepth < 0) return null
18+
19+
let showModels = layoutSelectors.isShown("models", defaultModelsExpandDepth > 0 && docExpansion !== "none")
1820
const specPathBase = specSelectors.isOAS3() ? ["components", "schemas"] : ["definitions"]
1921

2022
const ModelWrapper = getComponent("ModelWrapper")
21-
const Collapse = getComponent("Collapse")
22-
23-
if (!definitions.size) return null
23+
const Collapse = getComponent("Collapse")
2424

2525
return <section className={ showModels ? "models is-open" : "models"}>
2626
<h4 onClick={() => layoutActions.show("models", !showModels)}>
@@ -35,7 +35,7 @@ export default class Models extends Component {
3535

3636
return <div id={ `model-${name}` } className="model-container" key={ `models-section-${name}` }>
3737
<ModelWrapper name={ name }
38-
expandDepth={ defaultModelExpandDepth }
38+
expandDepth={ defaultModelsExpandDepth }
3939
schema={ model }
4040
specPath={[...specPathBase, name]}
4141
getComponent={ getComponent }

src/core/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module.exports = function SwaggerUI(opts) {
4747
showMutatedRequest: true,
4848
defaultModelRendering: "example",
4949
defaultModelExpandDepth: 1,
50+
defaultModelsExpandDepth: 1,
5051
showExtensions: false,
5152

5253
// Initial set of plugins ( TODO rename this, or refactor - we don't need presets _and_ plugins. Its just there for performance.

test/components/models.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ describe("<Models/>", function(){
3232
layoutActions: {},
3333
getConfigs: () => ({
3434
docExpansion: "list",
35-
defaultModelExpandDepth: 0
35+
defaultModelsExpandDepth: 0
3636
})
3737
}
3838

3939

40-
it("passes defaultModelExpandDepth to ModelWrapper", function(){
40+
it("passes defaultModelsExpandDepth to ModelWrapper", function(){
4141
// When
4242
let wrapper = shallow(<Models {...props}/>)
4343

0 commit comments

Comments
 (0)