完全替换 Swashbuckle UI

Replace Swashbuckle UI completely(完全替换 Swashbuckle UI)
本文介绍了完全替换 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)