Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show HTTP request duration in Swagger UI

Swagger UI has the displayRequestDuration parameter to show how long a request takes. It's disabled by default.

How can this be enabled in the SwaggerConfig.cs configuration when using Swashbuckle (the not-core version)?

I see this is possible in the Java version.

like image 594
Bernard Vander Beken Avatar asked Dec 14 '22 13:12

Bernard Vander Beken


2 Answers

According to the documentation, this is a Swagger UI configuration. For my .Net Core app, I was able to get the Request duration with the following code.

app.UseSwaggerUI(c =>
    {
        c.DisplayRequestDuration();
        // .... other configurations
    });

Example for the Request Duration

like image 153
user12323405 Avatar answered Dec 28 '22 05:12

user12323405


In recent versions you can do

app.UseSwaggerUi3(
    settings => settings.AdditionalSettings.Add("displayRequestDuration ", true));
)

since app.UseSwaggerUI is marked as obsolete.

Tested with .NET Core 3.x.

like image 44
Bernard Vander Beken Avatar answered Dec 28 '22 07:12

Bernard Vander Beken