Swagger-ui: How to disable 'Try it out' in 3.x

Created on 3 Oct 2017  路  10Comments  路  Source: swagger-api/swagger-ui

| Q | A
| ------------------------------- | -------
| Bug or feature request? | Question
| Which Swagger-UI version? | 3.3.1
| How did you install Swagger-UI? | downloaded from releases and used dist

As there is no any other communication channel with you dev guys, i am opening this issue, which is basically a question:
I haven't found anywhere how to disable 'Try it out' button in swagger-ui version 3.x.
Is it possible ?
Thank you

Most helpful comment

As there is no any other communication channel with you dev guys,

CC: https://github.com/swagger-api/swagger-ui/issues/3544.

I haven't found anywhere how to disable 'Try it out' button in swagger-ui version 3.x. Is it possible ?

Yes! It requires a custom plugin, though. Here's the code:

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

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

If you don't have control of the call to Swagger-UI (if you're using a downstream library, for example), this isn't possible at the moment... but if there's significant demand, we'd consider adding a tryItOutEnabled configuration option.

All 10 comments

I too need a way to disable Try It Out. I'm using OAP v3 with Swagger UI 3.3+, but my API uses Oauth2, so the Try It Out options always give 401 responses. Sigh.

As there is no any other communication channel with you dev guys,

CC: https://github.com/swagger-api/swagger-ui/issues/3544.

I haven't found anywhere how to disable 'Try it out' button in swagger-ui version 3.x. Is it possible ?

Yes! It requires a custom plugin, though. Here's the code:

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

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

If you don't have control of the call to Swagger-UI (if you're using a downstream library, for example), this isn't possible at the moment... but if there's significant demand, we'd consider adding a tryItOutEnabled configuration option.

Closing due to inactivity.

This is simply to keep our issue tracker clean - feel free to comment if there are any further thoughts or concerns, and we'll be happy to reopen this issue.

Hi, I was wondering if it's possible to disable the Try It Out button on a per-path or possibly tag basis?

As there is no any other communication channel with you dev guys,

CC: #3544.

I haven't found anywhere how to disable 'Try it out' button in swagger-ui version 3.x. Is it possible ?

Yes! It requires a custom plugin, though. Here's the code:

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

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

If you don't have control of the call to Swagger-UI (if you're using a downstream library, for example), this isn't possible at the moment... but if there's significant demand, we'd consider adding a tryItOutEnabled configuration option.

Just by the looks of search results on "disabling try it out" I'd say there's enough demand. Including me :)

I'd also love disabling "try it out" by some annotation parameter :)

@shockey thanks for that plugin sketch It (still) works as expected. Still no plans to make that feature configurable via a simple flag?

I also thought it necessary to hide the parameter input fields; haven't found a way to do that with a plugin and resorted to CSS.

.parameters-col_description input, .parameters-col_description select {
    /* if you can't try out the call it also doesn't make sense to display input fields for the request */
    display: none;
}

Hi all - how to achieve this when running Swagger UI in docker ?
I.e. how can I add a plugin to Docker ?

@eshepelyuk Swagger UI now has the supportedSubmitMethods option to disable "try it out", so there's no need for a plugin. In the Docker image, this option is set via the SUPPORTED_SUBMIT_METHODS environment variable, for example:

SUPPORTED_SUBMIT_METHODS="[]"

@hkosova sorry, could you give a minimal docker version supporting this feature ?

Was this page helpful?
0 / 5 - 0 ratings