Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger UI disable Try It Out button

Tags:

swagger-ui

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?

like image 263
Ramesh Murugesan Avatar asked Sep 13 '25 17:09

Ramesh Murugesan


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.

like image 55
Helen Avatar answered Sep 15 '25 17:09

Helen


In Swagger UI Options, try this for .NET 6 or 7:

    app.UseSwaggerUI(options =>
    {
        options.SwaggerEndpoint("/swagger/v1/swagger.json", "My API");
        options.EnableTryItOutByDefault();
    });
like image 31
Jey J Avatar answered Sep 15 '25 18:09

Jey J