完全替换Swashbuckle UI

Mar*_*ino 12 asp.net asp.net-web-api swagger swashbuckle

现在我正在开发一个ASP.Net Web API并使用Swashbuckle作为其文档.我知道Swashbuckle在内部使用Swagger-UI,我知道我们可以通过注入我们的css或javascript文件来修改布局,甚至可以更改index.html的布局.

我为Swagger-UI https://github.com/jensoleg/swagger-ui找到了一个很好的主题,并尝试实现它,但无法使其工作.特别是当我想注入bootstrap.js时.无论如何,我可以完全改变Swashbuckle Swagger UI实现,以便我可以使用该回购中的解决方案吗?

Ond*_*dar 9

当然可以 - 分两步走.

1)在程序集中包含文件Index.html作为嵌入式资源.例如,假设您的web api项目名为"Contosco.Api",Index.html将位于此项目的"/Content/Index.html"下.

2)用自己的方法覆盖swagger UI主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");
    });
  }
}
Run Code Online (Sandbox Code Playgroud)