Replace Swashbuckle UI completely(完全替换 Swashbuckle UI)
问题描述
现在我正在开发一个 ASP.Net Web API 并使用 Swashbuckle 作为它的文档.我知道 Swashbuckle 内部使用 Swagger-UI,我知道我们可以通过注入我们的 css 或 javascript 文件来修改布局,甚至改变 index.html 的布局.
Right now I'm developing an ASP.Net Web API and using Swashbuckle for its documentation. I know that Swashbuckle use Swagger-UI internally, I know that we can modify the layout by injecting our css or javascript file, even change the layout of index.html.
我为 Swagger-UI 找到了一个很好的主题 https://github.com/jensoleg/swagger-ui 并尝试实现它但无法使其工作.特别是当我想注入 bootstrap.js 时.无论如何我可以完全改变 Swashbuckle Swagger UI 实现,以便我可以使用该 repo 中的解决方案?
I found a good themes for Swagger-UI https://github.com/jensoleg/swagger-ui and trying to implement it but can't make it works. Especially when I want to inject bootstrap.js. Is there anyway I can completely change Swashbuckle Swagger UI implementation so I can use the solution from that repo?
推荐答案
当然可以 - 分两步.
Sure you can - in two steps.
1) 将文件 Index.html 作为嵌入式资源包含在您的程序集中.例如,假设您的 Web api 项目名为Contosco.Api",Index.html 将位于该项目的/Content/Index.html"下.
1) Include file Index.html as Embedded resource in your assembly. For example let's say your web api project is named "Contosco.Api" and Index.html will be located under "/Content/Index.html" in this project.
2) 用你自己的覆盖 swagger UI 主 html 页面
2) Override swagger UI main html page with your own
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
public class SwaggerConfig
{
public static void Register()
{
var thisAssembly = typeof(SwaggerConfig).Assembly;
GlobalConfiguration.Configuration.EnableSwagger(c => {
// configure swagger
})
.EnableSwaggerUi(c => {
// beware - the Contosco.Api.Content.Index.html has to match your project paths :)
c.CustomAsset("index", thisAssembly, "Contosco.Api.Content.Index.html");
});
}
}
这篇关于完全替换 Swashbuckle UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:完全替换 Swashbuckle UI
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
