swagger-uiswashbuckle.aspnetcore

Setting syntaxHighlight property for Swagger UI with Swashbuckle.AspNetCore


I am using Swashbuckle.AspNetCore for a project. The version I started with was 5.5.1 and when rendering results with large bodies (20k json rows), the speed was very reasonable (the data fetch takes 50ms and the rendering took less than a second. When I upgrade to 5.6.x, the syntax is now highlighted (which looks nice) but slows the rendering of those results to over 20 seconds. And once rendered, any action on the page that causes a refresh takes 20 seconds until the results are cleared.

After the usual searching, I want to try this solution (deactivating syntaxHighlight). I'm not sure how to do this via Swashbuckle.AspNetCore. Any suggestions?

SwaggerUI({
        syntaxHighlight: {
          activated: false,
          theme: "agate"
        },
        //url: path,
        ....
      });

Solution

  • Hi I had the same problem and after some digging in the source code i found that you can pass additional parameters to the ConfigObject this way (example showing how to disable syntax highlighting):

    app.UseSwaggerUI(c =>
    {
        c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
        c.RoutePrefix = string.Empty;
        c.ConfigObject.AdditionalItems.Add("syntaxHighlight", false);
    });