From 6273fd1dd88ed63da23a195790dd7da77ec45fd5 Mon Sep 17 00:00:00 2001 From: Alex Rejto Date: Wed, 12 Jan 2022 14:31:55 -0800 Subject: [PATCH] feat: add support of defaultModelRendering prop to swagger-ui-react Co-authored-by: Tim Lai --- flavors/swagger-ui-react/README.md | 7 +++++++ flavors/swagger-ui-react/index.jsx | 3 +++ 2 files changed, 10 insertions(+) diff --git a/flavors/swagger-ui-react/README.md b/flavors/swagger-ui-react/README.md index d66c15d4..0299dc35 100644 --- a/flavors/swagger-ui-react/README.md +++ b/flavors/swagger-ui-react/README.md @@ -83,6 +83,13 @@ 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. +#### `defaultModelRendering`: PropTypes.oneOf(["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.) The default value is 'example'. + +⚠️ 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. + + #### `displayOperationId`: PropTypes.bool Controls the display of operationId in operations list. The default is false. diff --git a/flavors/swagger-ui-react/index.jsx b/flavors/swagger-ui-react/index.jsx index 50a09aeb..9b92925b 100644 --- a/flavors/swagger-ui-react/index.jsx +++ b/flavors/swagger-ui-react/index.jsx @@ -15,6 +15,7 @@ export default class SwaggerUI extends React.Component { url: this.props.url, layout: this.props.layout, defaultModelsExpandDepth: this.props.defaultModelsExpandDepth, + defaultModelRendering: this.props.defaultModelRendering, presets: [presets.apis,...this.props.presets], requestInterceptor: this.requestInterceptor, responseInterceptor: this.responseInterceptor, @@ -106,6 +107,7 @@ SwaggerUI.propTypes = { showMutatedRequest: PropTypes.bool, defaultModelExpandDepth: PropTypes.number, defaultModelsExpandDepth: PropTypes.number, + defaultModelRendering: PropTypes.oneOf["example", "model"], presets: PropTypes.arrayOf(PropTypes.func), deepLinking: PropTypes.bool, showExtensions: PropTypes.bool, @@ -124,6 +126,7 @@ SwaggerUI.defaultProps = { queryConfigEnabled: false, docExpansion: "list", defaultModelsExpandDepth: 1, + defaultModelRendering: "example", presets: [], deepLinking: false, showExtensions: false,