Swagger UI disable Try It Out button

Viewed 4966

I would like to disable Try it Out button in the API documentation. I have tried "tryItOut": false in the parameter and the configuration. Furthermore, I'm using swagger 2.0 which has 'Try it out' button is enabled by default and in 3.0 it is disabled by default. So, there should be option to configure it. How to disable Try it out button from the Swagger UI?

2 Answers

Set supportedSubmitMethods to an empty array [] in your Swagger UI configuration. This config option is supported in v. 3.10.0+.

const ui = SwaggerUIBundle({
  "dom_id": "#swagger-ui",
  url: "https://path/to/your/api.yaml",
  ...
  supportedSubmitMethods: []    // <--------
})

This config can also disable "Try it out" selectively for specific HTTP methods. For example, supportedSubmitMethods: ["get", "head"] keeps "Try it out" only for GET and HEAD, but disables it for POST, PUT, PATCH, DELETE and other methods.

From the GitHub repository comments, the bellow code works to me

const DisableTryItOutPlugin = function() {
  return {
    statePlugins: {
      spec: {
        wrapSelectors: {
          allowTryItOutFor: () => () => false
        }
      }
    }
  }
}

// elsewhere, when you call Swagger-UI...
SwaggerUI({
  plugins: [
    DisableTryItOutPlugin
  ]
})

Reference: https://github.com/swagger-api/swagger-ui/issues/3725#issuecomment-334899276

Related