View Light

Swagger is super-slow with large JSON loads

Had some big JSON returned from a Web API project I was developing, Swagger was taking FOREVER (More than 20 minutes!) to display the returned data.

So I got looking into what I could do to increase the speed. Found some good settings that massively improve the rendering speed. The main fix is to disable Syntax Highlighting, but the other settings are handy as well.

Depending on your app, open either Startup.cs or Program.cs, look for the part that has app.UseSwaggerUI() and expand it as follows:

app.UseSwaggerUI(c =>
{
   // Expand details shown from default setting
   c.DefaultModelExpandDepth(2);

   // Smaller display onscreen
   c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);

   // Display the example JSON by default
   c.DefaultModelRendering(Swashbuckle.AspNetCore.SwaggerUI.ModelRendering.Example);

   // Make it so you don't have to keep clicking "Try It Now" to use a WebApi method.
   c.EnableTryItOutByDefault();

   // Disable highlighting as it really bogs down with large JSON loads.
   c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false);
});

Rating: (You must be logged in to vote)
Reply