添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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

Based on swagger-api/swagger-ui#3725 (comment)

const DisableTryItOutPlugin = function() {
  return {
    statePlugins: {
      spec: {
        wrapSelectors: {
          allowTryItOutFor: () => () => false
var options = {
  swaggerOptions: {
      plugins: [
           DisableTryItOutPlugin
          
const express = require('express');
const app = express();
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
const DisableTryItOutPlugin = function() {
  return {
    statePlugins: {
      spec: {
        wrapSelectors: {
          allowTryItOutFor: () => () => false
const options = {
  swaggerOptions: {
      plugins: [
           DisableTryItOutPlugin
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));

Hope that helps

const express = require('express');
const app = express();
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
const DisableTryItOutPlugin = function() {
  return {
    statePlugins: {
      spec: {
        wrapSelectors: {
          allowTryItOutFor: () => () => false
const options = {
  swaggerOptions: {
      plugins: [
           DisableTryItOutPlugin
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));

Hope that helps

const options = {
  swaggerOptions: {
    supportedSubmitMethods: []
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(require('./docs/build.json'),options));
          

@scottie1984

Hey, i'm opening this issue up and raising it again.

Since the time this solution was presented here,
the Swagger UI folks created a built-in option to disable the "try it out" button altogether.
Here is a reference to their doc which includes this option, and here's the thread (THE SAME ONE that raised that plugin work-around fix) with a comment down at the very bottom that says "hey, this work-around plugin thingy is no longer needed, since it is now built-in", and here's another.

I would love to see the support from the swagger-ui-express side as well! ❤️
Could it please be implemented here as well?

--- UPDATE ---

I tried it, it works 100%!
I passed tryItOutEnabled: true to the swaggerOptions, and now the "try it out" button is automatically clicked. The plugin override is not needed anymore. The built-in solution works great.

Those options can be set already via the swaggerOptions and will be passed through to swagger-ui:

https://github.com/scottie1984/swagger-ui-express#custom-swagger-options