定制swagger的UI
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 routesapp.UseSwaggerUi(configure): Registers only the Swagger UI on the given routeapp.UseSwaggerUi3(configure): Registers the Swagger generator and Swagger UI v3.x on the given routesapp.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
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.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的更多相关文章
- Asp.net Core WebApi 使用Swagger做帮助文档,并且自定义Swagger的UI
WebApi写好之后,在线帮助文档以及能够在线调试的工具是专业化的表现,而Swagger毫无疑问是做Docs的最佳工具,自动生成每个Controller的接口说明,自动将参数解析成json,并且能够在 ...
- Swagger 自定义UI界面
Swagger 自定义UI界面 Swagger简单介绍 如何使用Swagger 添加自定义UI界面 使用swagger-ui-layer Swagger ui 的原生UI界面如下: 个人感觉原生UI显 ...
- 我定制的jquery ui主题
打开网址 http://jqueryui.com/themeroller/,找到Gallery找到Redmond点击edit 将圆角设置成3px,让圆角更低调:将下面的每个Background的背景图 ...
- 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件
作者:Sreekanth Mothukuru 2016年2月18日 本文旨在介绍如何使用常用的 Swagger 和 Swashbuckle 框架创建描述 Restful API 的交互界面,并为 AP ...
- 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件(转)
作者:Sreekanth Mothukuru2016年2月18日 本文旨在介绍如何使用常用的 Swagger 和 Swashbuckle 框架创建描述 Restful API 的交互界面,并为 API ...
- [C#]在 DotNetCore 下的 Swagger UI 自定义操作
1.Swagger UI 是什么? Swagger UI 是一个在线的 API 文档生成与测试工具,你可以将其集成在你的 API 项目当中. 支持 API 自动同步生成文档 高度自定义,可以自己扩展功 ...
- 在 .NET Core 下的 Swagger UI 自定义操作
1.Swagger UI 是什么? Swagger UI 是一个在线的 API 文档生成与测试工具,你可以将其集成在你的 API 项目当中. 支持 API 自动同步生成文档 高度自定义,可以自己扩展功 ...
- ASP.NET Web API 使用Swagger生成在线帮助测试文档
Swagger-UI简单而一目了然.它能够纯碎的基于html+javascript实现,只要稍微整合一下便能成为方便的API在线测试工具.项目的设计架构中一直提倡使用TDD(测试驱动)原则来开发,sw ...
- 使用 Swagger 文档化和定义 RESTful API
大部分 Web 应用程序都支持 RESTful API,但不同于 SOAP API——REST API 依赖于 HTTP 方法,缺少与 Web 服务描述语言(Web Services Descript ...
随机推荐
- Android无线测试之—UiAutomator UiCollection API介绍
UiCollection类介绍 一.UiCollection类说明 1)UiCollection类是UiObject类的子类,即UiObject类的所有方法都被UiCollection继承下来了,都可 ...
- UITabBarItem如何更改高度
本文转载至 http://www.cocoachina.com/bbs/read.php?tid=255361 我目前有个UITabBar,改了它的高度.但是我切换页签后,这个UITabBar样式又变 ...
- @RequestParam 注解
@RequestParam 注解org.springframework.web.bind.annotation.RequestParam注解类型用于将指定的请求参数赋给方法中的形参.使用@Reques ...
- iOS 苹果官方 Crash文件分析方法 (iOS系统Crash文件分析方法)
时间2013-08-20 12:49:20 GoWhich原文 http://www.gowhich.com/blog/view/id/343 苹果官方 Crash文件分析方法 (iOS系统Cras ...
- Openstack虚拟机创建流程
续上一篇Openstack安装配置 一,keystone交互认证阶段 1,发送用户名和密码给keystone认证获取token 2,带着token访问nova-api 3,nova-api使用toke ...
- Delphi xe---FIREDAC
delphi xe 10.2 完成FireDAC支持NoSQL MongoDB数据库,包括新FireDAC MongoDB,包括新FireDAC MongoDB的驱动.
- 区块链 block chain 去信任
去中心化:不以参与交易的任何一方为中心 去信任:假定参与交易的任何一方都是不可信任的 区块链受到关注的原因 去中心化.去信任化.智能合约等,正好满足未来互联网持续发展所要求的信息的盖度自动化和高度程序 ...
- Linux(3)- 用户管理、文件与目录权限、常用命令、Linux软件包管理
一.用户管理 现代操作系统一般属于多用户的操作系统,也就是说,同一台机器可以为多个用户建立账户,一般这些用户都是为普通用户,这些普通用户能同时登录这台计算机,计算机对这些用户分配一定的资源. 普通用户 ...
- 0502-Hystrix保护应用-简介,使用,健康指标等
一.概述 参看地址:https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_circuit_ ...
- Read Large Files in Python
I have a large file ( ~4G) to process in Python. I wonder whether it is OK to "read" such ...