使用 Swashbuckle.AspNetCore 为 Swagger UI 设置 syntaxHighlight 属性

编程入门 行业动态 更新时间:2024-10-17 13:32:24
本文介绍了使用 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 属性

本文发布于:2023-11-15 03:55:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590921.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   AspNetCore   Swashbuckle   Swagger   syntaxHighlight

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!