Skip to content

Commit 3fea224

Browse files
authored
feat(swagger-ui-react): add request snippets configuration (#7536)
Closes #7523
1 parent c7b215b commit 3fea224

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

flavors/swagger-ui-react/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ Controls whether the "Try it out" section should start enabled. The default is f
125125

126126
⚠️ 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.
127127

128+
#### `requestSnippetsEnabled`: PropTypes.bool,
129+
130+
Enables the request snippet section. When disabled, the legacy curl snippet will be used. The default is false.
131+
132+
⚠️ 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.
133+
134+
#### `requestSnippets`: PropTypes.object,
135+
136+
Configures the request snippet core plugin. See Swagger UI's [Display Configuration](https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/configuration.md#display) for more details.
137+
138+
⚠️ 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.
139+
128140
## Limitations
129141

130142
* Not all configuration bindings are available.

flavors/swagger-ui-react/index.jsx

+24-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export default class SwaggerUI extends React.Component {
2424
defaultModelExpandDepth: this.props.defaultModelExpandDepth,
2525
displayOperationId: this.props.displayOperationId,
2626
tryItOutEnabled: this.props.tryItOutEnabled,
27+
requestSnippetsEnabled: this.props.requestSnippetsEnabled,
28+
requestSnippets: this.props.requestSnippets,
2729
showMutatedRequest: typeof this.props.showMutatedRequest === "boolean" ? this.props.showMutatedRequest : true,
2830
deepLinking: typeof this.props.deepLinking === "boolean" ? this.props.deepLinking : false,
2931
showExtensions: this.props.showExtensions,
@@ -104,7 +106,9 @@ SwaggerUI.propTypes = {
104106
presets: PropTypes.arrayOf(PropTypes.func),
105107
deepLinking: PropTypes.bool,
106108
showExtensions: PropTypes.bool,
107-
tryItOutEnabled: PropTypes.bool
109+
requestSnippetsEnabled: PropTypes.bool,
110+
requestSnippets: PropTypes.object,
111+
tryItOutEnabled: PropTypes.bool,
108112
}
109113

110114
SwaggerUI.defaultProps = {
@@ -115,4 +119,23 @@ SwaggerUI.defaultProps = {
115119
presets: [],
116120
deepLinking: false,
117121
showExtensions: false,
122+
requestSnippetsEnabled: false,
123+
requestSnippets: {
124+
generators: {
125+
"curl_bash": {
126+
title: "cURL (bash)",
127+
syntax: "bash"
128+
},
129+
"curl_powershell": {
130+
title: "cURL (PowerShell)",
131+
syntax: "powershell"
132+
},
133+
"curl_cmd": {
134+
title: "cURL (CMD)",
135+
syntax: "bash"
136+
},
137+
},
138+
defaultExpanded: true,
139+
languages: null, // e.g. only show curl bash = ["curl_bash"]
140+
},
118141
}

0 commit comments

Comments
 (0)