Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable 'Try it out' in 3.x #3725

Closed
tokra opened this issue Oct 3, 2017 · 15 comments
Closed

How to disable 'Try it out' in 3.x #3725

tokra opened this issue Oct 3, 2017 · 15 comments

Comments

@tokra
Copy link

tokra commented Oct 3, 2017

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

@curtisdf
Copy link

curtisdf commented Oct 7, 2017

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.

@shockey
Copy link
Contributor

shockey commented Oct 7, 2017

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.

@shockey
Copy link
Contributor

shockey commented Oct 12, 2017

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.

@drpoggi
Copy link

drpoggi commented Apr 30, 2018

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

@RvdHNL
Copy link

RvdHNL commented Oct 24, 2018

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 :)

@Cejkis-zz
Copy link

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

@marcelstoer
Copy link

@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;
}

@eshepelyuk
Copy link

eshepelyuk commented Jun 18, 2020

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

@hkosova
Copy link
Contributor

hkosova commented Jul 6, 2020

@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="[]"

@eshepelyuk
Copy link

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

@kevle1
Copy link

kevle1 commented May 14, 2021

Another workaround that may work for some use cases is setting a false server in the specification, meaning any use of "Try It Out" will hit a non existent endpoint instead. This overrides the default URL of "/"

servers:
  - url: https://api.example.com

AndrewKostousov added a commit to vektonn/vektonn that referenced this issue Jul 15, 2021
* swagger-ui v3.51.1 (see instructions here: https://github.com/peter-evans/swagger-github-pages)
* disable "Try it out" feature (swagger-api/swagger-ui#3725 (comment))
@Shoulao
Copy link

Shoulao commented Aug 24, 2021

There is a simple config setup for this approach:

const swaggerOptions = {
  swaggerOptions: {
    tryItOutEnabled: false,
    supportedSubmitMethods: [''],
  },
};
swaggerUi.setup(swaggerDoc, swaggerOptions)

In this case we wont have try-it-out button in the ui

@guhan121
Copy link

guhan121 commented Jan 14, 2022

@RvdHNL @shockey how to fix it in SwaggerUIBundle@4.1.3?


  <body>
    <div id="swagger-ui"></div>

    <script src="./swagger-ui-bundle.js" charset="UTF-8"> </script>
    <script src="./swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
    <script>
    window.onload = function() {
      // Begin Swagger UI call region
      const DisableTryItOutPlugin = function() {
        return {
          statePlugins: {
            spec: {
              wrapSelectors: {
                allowTryItOutFor: () => () => false
              }
            }
          }
        }
      }
      const ui = SwaggerUIBundle({
        url: "swagger.json",
        dom_id: '#swagger-ui',
        deepLinking: true,
        presets: [
          SwaggerUIBundle.presets.apis,
          SwaggerUIStandalonePreset
        ],
        plugins: [
          SwaggerUIBundle.plugins.DownloadUrl,
          DisableTryItOutPlugin
        ],
        supportedSubmitMethods:[],
        layout: "StandaloneLayout"
      });
      // End Swagger UI call region

      window.ui = ui;
    };
  </script>
  </body>

still not work 😢

@swethamekaa
Copy link

is it possible to add the customized text in swagger ui after clicking on the copy button.
image

@swethamekaa
Copy link

swethamekaa commented Sep 24, 2023

can anyone please help on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

14 participants