现在,我正在开发一个ASP.Net Web,并使用它的文档。我知道Swashbuckle在内部使用Swagger-UI,我知道我们可以通过注入css或javascript文件来修改布局,甚至可以更改index.html的布局。
我为Swagger https://github.com/jensoleg/swagger-ui找到了一个很好的主题,并试图实现它,但无法使它工作。尤其是当我想注入bootstrap.js的时候。我是否可以完全改变Swashbuckle实现,这样我就可以使用回购中的解决方案了吗?
发布于 2015-12-10 09:53:30
你当然可以-分两步。
1)将文件Index.html作为嵌入资源包含在程序集中。例如,假设您的web项目名为"Contosco.Api“,Index.html将位于该项目的"/Content/Index.html”下。
2)用自己的主页覆盖swagger主html页面。
[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");
});
}
}发布于 2016-01-10 10:36:57
您只需下载.zip文件夹,解压缩并包含到您的项目。在SwaggerConfigre.cs中,您不再需要配置。只要将模板放入文件夹Swagger中,当您访问{domain}/swagger时,它就会命中index.html。(不需要将构建操作更改为嵌入式资源,内容是可以的)
发布于 2017-10-26 08:49:20
通过以下简单步骤,我能够使用最新的swagger-ui,https://swagger.io/docs/swagger-tools/#swagger-ui-documentation-29。
https://stackoverflow.com/questions/31647635
复制相似问题