Skip to content

Commit f589cb9

Browse files
scottoharashockey
authored andcommitted
feature: supportedSubmitMethods config parameter (#4186)
1 parent 3d7a00c commit f589cb9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

docs/usage/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Parameter Name | Description
6868
`requestInterceptor` | `Function=(a => a)`. MUST be a function. Function to intercept remote definition, Try-It-Out, and OAuth2 requests. Accepts one argument requestInterceptor(request) and must return the potentially modified request.
6969
`responseInterceptor` |`Function=(a => a)`. MUST be a function. Function to intercept remote definition, Try-It-Out, and OAuth2 responses. Accepts one argument responseInterceptor(response) and must return the potentially modified response.
7070
`showMutatedRequest` | `Boolean=true`. If set to `true`, uses the mutated request returned from a requestInterceptor to produce the curl command in the UI, otherwise the request before the requestInterceptor was applied is used.
71+
`supportedSubmitMethods` | `Array=["get", "put", "post", "delete", "options", "head", "patch", "trace"]`. List of HTTP methods that have the Try it out feature enabled. An empty array disables Try it out for all operations. This does not filter the operations from the display.
7172
`validatorUrl` | `String="https://online.swagger.io/validator" OR null`. By default, Swagger-UI attempts to validate specs against swagger.io's online validator. You can use this parameter to set a different validator URL, for example for locally deployed validators ([Validator Badge](https://github.com/swagger-api/validator-badge)). Setting it to `null` will disable validation.
7273

7374
##### Macros

src/core/containers/OperationContainer.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export default class OperationContainer extends PureComponent {
5656

5757
mapStateToProps(nextState, props) {
5858
const { op, layoutSelectors, getConfigs } = props
59-
const { docExpansion, deepLinking, displayOperationId, displayRequestDuration } = getConfigs()
59+
const { docExpansion, deepLinking, displayOperationId, displayRequestDuration, supportedSubmitMethods } = getConfigs()
6060
const showSummary = layoutSelectors.showSummary()
6161
const operationId = op.getIn(["operation", "operationId"]) || op.getIn(["operation", "__originalOperationId"]) || opId(op.get("operation"), props.path, props.method) || op.get("id")
6262
const isShownKey = ["operations", props.tag, operationId]
6363
const isDeepLinkingEnabled = deepLinking && deepLinking !== "false"
64-
const allowTryItOut = typeof props.allowTryItOut === "undefined" ?
65-
props.specSelectors.allowTryItOutFor(props.path, props.method) : props.allowTryItOut
64+
const allowTryItOut = supportedSubmitMethods.indexOf(props.method) >= 0 && (typeof props.allowTryItOut === "undefined" ?
65+
props.specSelectors.allowTryItOutFor(props.path, props.method) : props.allowTryItOut)
6666
const security = op.getIn(["operation", "security"]) || props.specSelectors.security()
6767

6868
return {

src/core/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ module.exports = function SwaggerUI(opts) {
4949
defaultModelExpandDepth: 1,
5050
defaultModelsExpandDepth: 1,
5151
showExtensions: false,
52+
supportedSubmitMethods: [
53+
"get",
54+
"put",
55+
"post",
56+
"delete",
57+
"options",
58+
"head",
59+
"patch",
60+
"trace"
61+
],
5262

5363
// Initial set of plugins ( TODO rename this, or refactor - we don't need presets _and_ plugins. Its just there for performance.
5464
// Instead, we can compile the first plugin ( it can be a collection of plugins ), then batch the rest.

0 commit comments

Comments
 (0)