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. Caused by: java.lang.IllegalArgumentException: @EnableAsync annotation metadata was not injected

    需要注意的是ComponentScan 不能扫描 org.springframework 否则会报错,要扫描指定的package才行

  2. python框架Scrapy报错TypeError: 'float' object is not iterable解决

    原因是:Twisted版本高了. 解决办法: 只要把Twisted库降级到16.6.0即可: pip3 install Twisted== 注:Twisted16..0安装后,会自动卸载高版本的Twi ...

  3. Commit message 的写法规范。本文介绍Angular 规范(

    Commit message 的写法规范.本文介绍Angular 规范( http://www.ruanyifeng.com/blog/2016/01/commit_message_change_lo ...

  4. Kafka — 高吞吐量的分布式发布订阅消息系统【转】

    1.Kafka独特设计在什么地方?2.Kafka如何搭建及创建topic.发送消息.消费消息?3.如何书写Kafka程序?4.数据传输的事务定义有哪三种?5.Kafka判断一个节点是否活着有哪两个条件 ...

  5. ArcGIS runtime for wpf 部署

    简介 ArcGIS runtime for wpf 是一个轻量级的产品,部署方便,甚至可以做到直接部署在U盘中,做到即插即用. 部署一般需要遵循如下几个步骤: 1. 设定部署许可 虽然ArcGIS r ...

  6. Django之html-模板继承

    在编程的过程中,我们经常会重复性的写了很多的代码,比如一个页面的框架部分,这样我又多少个页面就得写上多少次,这样既不好维护,也不够高效,所以我们引出了html的模板继承部分. 1.写好一个html文件 ...

  7. Scrapy框架-scrapy框架快速入门

    1.安装和文档 安装:通过pip install scrapy即可安装. Scrapy官方文档:http://doc.scrapy.org/en/latest Scrapy中文文档:http://sc ...

  8. swift 值得学习的项目

    http://www.php100.com/html/it/biancheng/2015/0112/8329.html

  9. Android自定义属性:attr.xml 与 TypedArray

    1.attr.xml <?xml version="1.0" encoding="utf-8"?> <resources> <de ...

  10. android adb devices offline的解决办法

    在做Android开发时经常出现android adb devices offline,解决办法如下: 1 重启adb服务 adb kill-server adb start-server linux ...