From 296f73aa007f35684cadac064af480449bf39c3a Mon Sep 17 00:00:00 2001 From: Peter Mooney <44618217+pmooney-jama@users.noreply.github.com> Date: Sat, 4 Jan 2020 17:15:33 -0800 Subject: [PATCH] feat(swagger-ui-react): `defaultModelExpandDepth` and `plugins` props (#5594) * Add plugins as React prop * Add defaultModelExpandDepth as React prop * Add documentation re: defaultModelExpandDepth and plugins props * Fetched latest and rebased on that * add on-mount-only warning messages to new options Co-authored-by: Todd Lemoine <43755148+tlemoine-jama@users.noreply.github.com> Co-authored-by: kyle shockey --- flavors/swagger-ui-react/README.md | 12 ++++++++++++ flavors/swagger-ui-react/index.js | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/flavors/swagger-ui-react/README.md b/flavors/swagger-ui-react/README.md index 4c658da4816..b6fa11f666c 100644 --- a/flavors/swagger-ui-react/README.md +++ b/flavors/swagger-ui-react/README.md @@ -71,6 +71,18 @@ Controls the default expansion setting for the operations and tags. It can be 'l ⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change. +#### `defaultModelExpandDepth`: PropTypes.number + +The default expansion depth for models (set to -1 completely hide the models). + +⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change. + +#### `plugins`: PropTypes.arrayOf(PropTypes.object), + +An array of objects that augment and modify Swagger UI's functionality. See Swagger UI's [Plugin API](https://github.com/swagger-api/swagger-ui/blob/master/docs/customization/plugin-api.md) for more details. + +⚠️ This prop is currently only applied once, on mount. Changes to this prop's value will not be propagated to the underlying Swagger UI instance. A future version of this module will remove this limitation, and the change will not be considered a breaking change. + ## Limitations * Not all configuration bindings are available. diff --git a/flavors/swagger-ui-react/index.js b/flavors/swagger-ui-react/index.js index 206ee74973d..6ba415504de 100644 --- a/flavors/swagger-ui-react/index.js +++ b/flavors/swagger-ui-react/index.js @@ -11,12 +11,14 @@ export default class SwaggerUI extends React.Component { componentDidMount() { const ui = swaggerUIConstructor({ + plugins: this.props.plugins, spec: this.props.spec, url: this.props.url, requestInterceptor: this.requestInterceptor, responseInterceptor: this.responseInterceptor, onComplete: this.onComplete, docExpansion: this.props.docExpansion, + defaultModelExpandDepth: this.props.defaultModelExpandDepth, }) this.system = ui @@ -82,4 +84,6 @@ SwaggerUI.propTypes = { responseInterceptor: PropTypes.func, onComplete: PropTypes.func, docExpansion: PropTypes.oneOf(['list', 'full', 'none']), + defaultModelExpandDepth: PropTypes.number, + plugins: PropTypes.arrayOf(PropTypes.object), }