Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to be in try-it-out mode by default in Swagger 2?

I am using Swagger 2 with Springfox.

When you click on an endpoint, is there any way to have the Try-it-out mode activated by default, without having to click this button:

enter image description here

like image 504
Thomas Avatar asked Sep 06 '25 06:09

Thomas


2 Answers

try this: use on startup.cs (.net5) or program.cs (.net6)

app.UseSwaggerUI(options =>
{       
    options.EnableTryItOutByDefault();
});
like image 139
mohsen mashhadi Avatar answered Sep 07 '25 23:09

mohsen mashhadi


You should set TRY_IT_OUT_ENABLED=true to enable "Try it out mode" by default.

So try to search this option for your UI swagger lib.

In my case I use @nestjs/swagger package so I used the following code to enable the mode:

SwaggerModule.setup(apiPrefix, app, document, {
    swaggerOptions: {
        tryItOutEnabled: true,
    },
});

Also it works for swagger-ui package you can find its config here

For some swagger libs it does not work so try to update package version

like image 24
zemil Avatar answered Sep 07 '25 23:09

zemil