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. 认识tornado(四)

    接下来我们看一下helloword.py的唯一一个handler. 1 class MainHandler(tornado.web.RequestHandler): 2 def get(self): ...

  2. java反射——方法

    大家都知道反射技术在Java里面时非常重要的一个技术点,因为Java好多框架的编写都是基于反射的,别的不多说,spring框架里面的IOC就是基于反射实现.那么什么是反射呢?JAVA反射机制是在运行状 ...

  3. python3 基础数据类型

    一.基础数据类型分类 python的数据类型主要包括以下几种: 1.数字 2.字符串 3.列表 4.字典 5.元组 6.集合 1.数字 int 数字主要是用于计算用的,使用方法并不多 #bit_len ...

  4. Python高级教程-切片

    Python中的切片 取一个list或tuple的部分元素是非常常见的操作.比如,一个list如下: >>> L = ['A','B','C','D'] 对经常取指定索引范围的操作, ...

  5. composer 常用包管理工具

    名称 用途说明 说明地址 mashape/unirest-php 简单易用的HTTP请求库 官网地址 guzzlehttp/guzzle 功能强大的HTTP请求库 文档 hassankhan/conf ...

  6. 在Windows上以服务方式运行 Redis

    ServiceStack.Redis 使用教程里提到Redis最好还是部署到Linux下去,Windows只是用来 做开发环境,现在这个命题发生改变了,在Windows上也可以部署生产环境的Redis ...

  7. UTC和时间相互转换

    // ToLocalTime() UTC时间转换为本地时间 public static DateTime UtcToDateTime(long number) { , , , , , , ).AddS ...

  8. 『NiFi 学习之路』资源 —— 资料汇总

    一.概述 由于 NiFi 是一个比较新的开源项目,国内的相关资料少之又少. 加之,大家都知道,国内的那么些个教程,原创都只是停留在初级使用阶段,没有更多深入的介绍. 再者,其余的文章不是东抄抄就是西抄 ...

  9. linux命令详解之(at)--6/24

    在Linux下,有两个命令可以用来作为计划任务而执行,at:一次性定时任务计划执行crontab :每天定时任务计划执行 以下仅说一下一次性任务计划执行(at)要使用一次性任务计划,linux必须要有 ...

  10. mac相关记录

    一.设置允许安装任何来源软件 命令行执行: sudo spctl --master-disable -----------------------------