Show HTTP request duration in Swagger UI

試著忘記壹切 提交于 2020-07-30 03:02:05

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/54351293/show-http-request-duration-in-swagger-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!