完全替换Swashbuckle UI [英] Replace Swashbuckle UI completely
问题描述
现在,我正在开发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的实现,以便可以使用该存储库中的解决方案?
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主页
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!