https://github.com/RSuter/NSwag/wiki#ways-to-use-the-toolchain

Customizations

Swagger generation:

You can customize the Swagger generator with the following extension points of NSwag:

https://github.com/RSuter/NSwag/wiki/OWIN-Middleware

  • Package: NSwag.AspNet.Owin (.NET 4.5+)

The NuGet package provides extension methods to register the NSwag ASP.NET OWIN middlewares:

The middlewares are based on WebApiToSwaggerGenerator - the old reflection based ASP.NET Core and ASP.NET generator

Swagger only:

  • app.UseSwagger(assembly, configure): Registers the Swagger generator on a given route

Swagger and Swagger UI: (用了这个,就不能用上面的,是冲突的)

  • app.UseSwaggerUi(assembly, configure): Registers the Swagger generator and Swagger UI v2.x on the given routes
  • app.UseSwaggerUi(configure): Registers only the Swagger UI on the given route
  • app.UseSwaggerUi3(configure): Registers the Swagger generator and Swagger UI v3.x on the given routes
  • app.UseSwaggerReDoc(configure): Registers the Swagger generator and ReDoc on the given routes

The default routes to access the Swagger specification or Swagger UI:

  • Swagger JSON: http://yourserver/swagger/v1/swagger.json
  • Swagger UI: http://yourserver/swagger

1. Install required NuGet packages

First, you need to install the required NSwag NuGet packages.

2. Register the middleware

OWIN Startup Class Detection

public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration(); app.UseSwaggerUi(typeof(Startup).Assembly, settings =>
{
// configure settings here
// settings.GeneratorSettings.*: Generator settings and extension points
// settings.*: Routing and UI settings
});
app.UseWebApi(config); config.MapHttpAttributeRoutes();
config.EnsureInitialized();
}
}

Configure the routing of the Swagger requests

There are two ways to do this:

自定义

Post process the served Swagger specification

It is possible to transform the generated Swagger specification before it is served to the client:

app.UseSwagger(typeof(Startup).Assembly, settings =>
{
settings.PostProcess = document =>
{
document.Info.Description = "My description";
};
});

If you want to implement more reusable code, you can also implement Document Processors and Operation Processors.

UseSwagger和UseSwaggerUi3只能用一个

app.UseSwaggerUi3(typeof(Startup).Assembly, settings =>
{
// configure settings here
// settings.GeneratorSettings.*: Generator settings and extension points
// settings.*: Routing and UI settings
settings.GeneratorSettings.DefaultUrlTemplate = "api/{controller}/{action}/{id}";
settings.PostProcess = document =>
{
document.Info.Title = "My Services";
document.Info.Version = "1.5";
document.Info.Contact = new SwaggerContact {Name = "My team", Email = "test@qq.com" };
};
});

参考

https://github.com/RSuter/NSwag/blob/master/src/NSwag.Sample.NETCore22/Startup.cs   这里有ConfigureServices的方法签名示例

https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-nswag?view=aspnetcore-2.2&tabs=visual-studio%2Cvisual-studio-xml#customize-api-documentation    这里有如何进行文档自定义的代码

https://docs.particular.net/samples/dependency-injection/aspnetcore/   需要引用Autofac.Extensions.DependencyInjection

https://github.com/RSuter/NSwag/wiki/Middlewares   两种不同的middleware

https://github.com/RSuter/NSwag/wiki/AspNetCore-Middleware    这个里面是用ConfigureServices来处理文档

https://github.com/RSuter/NSwag/wiki/OWIN-Middleware    这个里面是用pp.UseSwaggerUi3(configure)来处理文档

定制swagger的UI的更多相关文章

  1. Asp.net Core WebApi 使用Swagger做帮助文档,并且自定义Swagger的UI

    WebApi写好之后,在线帮助文档以及能够在线调试的工具是专业化的表现,而Swagger毫无疑问是做Docs的最佳工具,自动生成每个Controller的接口说明,自动将参数解析成json,并且能够在 ...

  2. Swagger 自定义UI界面

    Swagger 自定义UI界面 Swagger简单介绍 如何使用Swagger 添加自定义UI界面 使用swagger-ui-layer Swagger ui 的原生UI界面如下: 个人感觉原生UI显 ...

  3. 我定制的jquery ui主题

    打开网址 http://jqueryui.com/themeroller/,找到Gallery找到Redmond点击edit 将圆角设置成3px,让圆角更低调:将下面的每个Background的背景图 ...

  4. 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件

    作者:Sreekanth Mothukuru 2016年2月18日 本文旨在介绍如何使用常用的 Swagger 和 Swashbuckle 框架创建描述 Restful API 的交互界面,并为 AP ...

  5. 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件(转)

    作者:Sreekanth Mothukuru2016年2月18日 本文旨在介绍如何使用常用的 Swagger 和 Swashbuckle 框架创建描述 Restful API 的交互界面,并为 API ...

  6. [C#]在 DotNetCore 下的 Swagger UI 自定义操作

    1.Swagger UI 是什么? Swagger UI 是一个在线的 API 文档生成与测试工具,你可以将其集成在你的 API 项目当中. 支持 API 自动同步生成文档 高度自定义,可以自己扩展功 ...

  7. 在 .NET Core 下的 Swagger UI 自定义操作

    1.Swagger UI 是什么? Swagger UI 是一个在线的 API 文档生成与测试工具,你可以将其集成在你的 API 项目当中. 支持 API 自动同步生成文档 高度自定义,可以自己扩展功 ...

  8. ASP.NET Web API 使用Swagger生成在线帮助测试文档

    Swagger-UI简单而一目了然.它能够纯碎的基于html+javascript实现,只要稍微整合一下便能成为方便的API在线测试工具.项目的设计架构中一直提倡使用TDD(测试驱动)原则来开发,sw ...

  9. 使用 Swagger 文档化和定义 RESTful API

    大部分 Web 应用程序都支持 RESTful API,但不同于 SOAP API——REST API 依赖于 HTTP 方法,缺少与 Web 服务描述语言(Web Services Descript ...

随机推荐

  1. svn服务器配置 for mac

      本文转载至 http://blog.sina.com.cn/s/blog_5e42f31a010156z4.html 1.找到合适的目录,新建一个版本库的目录:mkdir svn 创建版本库:sv ...

  2. cxGrid 循环选择条目

    Delphi DevExpress CxGrid 循环选择条目 整理出来的,直接复制粘贴即可使用 以下是从网络上复制粘帖到的,实践证明,利用以下代码进行获取选择行是错误的. 当我们利用 CxGrid进 ...

  3. maven 的构建异常 Could not find artifact ... and 'parent.relativePath'

    完整的异常提示: Non-resolvable parent POM: Could not find artifact com.ecp:ecp-main:pom:0.0.1-SNAPSHOT and ...

  4. HDU 5677 ztr loves substring(回文串加多重背包)

    ztr loves substring Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. MySQL 乐观锁与悲观锁

    悲观锁 悲观锁(Pessimistic Lock),顾名思义,就是很悲观,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这个数据就会block直到它拿到锁. 悲观锁: ...

  6. 《深入理解Linux网络技术内幕》阅读笔记 --- 路由表

    路由表基本概念 1.路由是由多个不同的数据结构的组合来描述的,每个数据结构代表路由信息的不同部分.例如,一个fib_node对应一个单独的子网,一个fib_alias对应一条路由.这样做的原因是只需通 ...

  7. HTML(form标签)、CSS

    一.表单标签<form> 功能:表单用于向服务器传输数据,从而实现用户与Web服务器的交互. 表单能够包含input系列标签,比如文本字段.复选框.单选框.提交按钮等等. 表单还可以包含t ...

  8. DBCC SHRINKFILE收缩日志/收缩数据库/收缩文件

    DBCC SHRINKFILE 收缩相关数据库的指定数据文件或日志文件大小. 语法 DBCC SHRINKFILE    ( { file_name | file_id }        { [ ,t ...

  9. 003-Java非堆CodeCache详解

    一.概述 Java的内存由堆和非堆两个部分组成.对于堆来说,它的组成是比较确定的,它包含了年轻代和年老代两个部分,而年轻代又是由Eden区和两个Survivor区组成.可是,非堆由哪些部分组成呢? 在 ...

  10. Webbench进行网站压力测试

    今天突然发现一个新大陆,Webbench,是linux下,用这很方便,开源,不限制并发访问次数和时间....大爱啊! 下载Webbench 使用wget  或者windows下载好导入linux也行, ...