问题描述
现在我正在开发一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!