Merge pull request #3159 from gwynjudd/doc-expansion

Added support for docExpansion config
This commit is contained in:
shockey
2017-06-05 20:17:57 -07:00
committed by GitHub
5 changed files with 17 additions and 10 deletions

View File

@@ -120,6 +120,7 @@ operationsSorter | Apply a sort to the operation list of each API. It can be 'al
configUrl | Configs URL configUrl | Configs URL
parameterMacro | MUST be a function. Function to set default value to parameters. Accepts two arguments parameterMacro(operation, parameter). Operation and parameter are objects passed for context, both remain immutable parameterMacro | MUST be a function. Function to set default value to parameters. Accepts two arguments parameterMacro(operation, parameter). Operation and parameter are objects passed for context, both remain immutable
modelPropertyMacro | MUST be a function. Function to set default values to each property in model. Accepts one argument modelPropertyMacro(property), property is immutable modelPropertyMacro | MUST be a function. Function to set default values to each property in model. Accepts one argument modelPropertyMacro(property), property is immutable
docExpansion | 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). The default is 'list'.
### Plugins ### Plugins

View File

@@ -27,7 +27,8 @@ export default class Operation extends React.Component {
specSelectors: PropTypes.object.isRequired, specSelectors: PropTypes.object.isRequired,
layoutActions: PropTypes.object.isRequired, layoutActions: PropTypes.object.isRequired,
layoutSelectors: PropTypes.object.isRequired, layoutSelectors: PropTypes.object.isRequired,
fn: PropTypes.object.isRequired fn: PropTypes.object.isRequired,
getConfigs: PropTypes.func.isRequired
} }
static defaultProps = { static defaultProps = {
@@ -76,8 +77,10 @@ export default class Operation extends React.Component {
} }
isShown =() => { isShown =() => {
let { layoutSelectors, isShownKey } = this.props let { layoutSelectors, isShownKey, getConfigs } = this.props
return layoutSelectors.isShown(isShownKey, false ) // Here is where we set the default let { docExpansion } = getConfigs()
return layoutSelectors.isShown(isShownKey, docExpansion === "full" ) // Here is where we set the default
} }
onTryoutClick =() => { onTryoutClick =() => {

View File

@@ -10,6 +10,7 @@ export default class Operations extends React.Component {
layoutActions: PropTypes.object.isRequired, layoutActions: PropTypes.object.isRequired,
authActions: PropTypes.object.isRequired, authActions: PropTypes.object.isRequired,
authSelectors: PropTypes.object.isRequired, authSelectors: PropTypes.object.isRequired,
getConfigs: PropTypes.func.isRequired
}; };
static defaultProps = { static defaultProps = {
@@ -25,6 +26,7 @@ export default class Operations extends React.Component {
layoutActions, layoutActions,
authActions, authActions,
authSelectors, authSelectors,
getConfigs,
fn fn
} = this.props } = this.props
@@ -34,6 +36,7 @@ export default class Operations extends React.Component {
const Collapse = getComponent("Collapse") const Collapse = getComponent("Collapse")
let showSummary = layoutSelectors.showSummary() let showSummary = layoutSelectors.showSummary()
let { docExpansion } = getConfigs()
return ( return (
<div> <div>
@@ -43,7 +46,7 @@ export default class Operations extends React.Component {
let tagDescription = tagObj.getIn(["tagDetails", "description"], null) let tagDescription = tagObj.getIn(["tagDetails", "description"], null)
let isShownKey = ["operations-tag", tag] let isShownKey = ["operations-tag", tag]
let showTag = layoutSelectors.isShown(isShownKey, true) let showTag = layoutSelectors.isShown(isShownKey, docExpansion === "full" || docExpansion === "list")
return ( return (
<div className={showTag ? "opblock-tag-section is-open" : "opblock-tag-section"} key={"operation-" + tag}> <div className={showTag ? "opblock-tag-section is-open" : "opblock-tag-section"} key={"operation-" + tag}>
@@ -98,6 +101,7 @@ export default class Operations extends React.Component {
getComponent={ getComponent } getComponent={ getComponent }
fn={fn} fn={fn}
getConfigs={ getConfigs }
/> />
}).toArray() }).toArray()
} }

View File

@@ -24,6 +24,7 @@ module.exports = function SwaggerUI(opts) {
spec: {}, spec: {},
url: "", url: "",
layout: "BaseLayout", layout: "BaseLayout",
docExpansion: "list",
validatorUrl: "https://online.swagger.io/validator", validatorUrl: "https://online.swagger.io/validator",
configs: {}, configs: {},
custom: {}, custom: {},

View File

@@ -43,8 +43,6 @@ export const specResolved = createSelector(
// Default Spec ( as an object ) // Default Spec ( as an object )
export const spec = state => { export const spec = state => {
let res = specResolved(state) let res = specResolved(state)
if(res.count() < 1)
res = specJson(state)
return res return res
} }