使用 Swashbuckle.AspNetCore 为 Swagger UI 设置 syntaxHighlight 属性 [英] Setting syntaxHighlight property for Swagger UI with Swashbuckle.AspNetCore

查看:53
本文介绍了使用 Swashbuckle.AspNetCore 为 Swagger UI 设置 syntaxHighlight 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个项目使用 Swashbuckle.AspNetCore.我开始使用的版本是5.5.1,在渲染大体(20k json 行)的结果时,速度非常合理(数据获取需要 50 毫秒,渲染时间不到一秒.当我升级到 5.6.x,语法现在突出显示(看起来不错),但将这些结果的呈现速度减慢到 20 秒以上.一旦呈现,页面上导致刷新的任何操作都需要20 秒,直到结果被清除.

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.

在通常的搜索之后,我想尝试这个解决方案(停用syntaxHighlight).我不确定如何通过 Swashbuckle.AspNetCore 做到这一点.有什么建议吗?

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,
        ....
      });

推荐答案

我遇到了同样的问题,在对源代码进行了一些挖掘后,我发现您可以通过这种方式将附加参数传递给 ConfigObject(示例显示如何禁用语法高亮):

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);
});

这篇关于使用 Swashbuckle.AspNetCore 为 Swagger UI 设置 syntaxHighlight 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆