ASP.NET Core 1.0 中使用 Swagger 生成文档
之前文章有介绍在ASP.NET WebAPI 中使用Swagger生成文档,ASP.NET Core 1.0中同样也支持。
依赖包
"dependencies": {
"Swashbuckle.SwaggerGen": "6.0.0-rc1-final",
"Swashbuckle.SwaggerUi": "6.0.0-rc1-final"
}
项目属性选中“生成时生成输出”选项用来生成XML注释
Startup类
public class Startup
{
//private readonly string pathXml = @"\\Mac\Home\Desktop\asp.net core\learn_asp.net core 1.0\artifacts\bin\SwaggerForASP.NETCore\Debug\dnx451\SwaggerForASP.NETCore1.0.xml";
private readonly string pathXml = @"C:\Users\irving\Desktop\asp.net core\LearningASP.NETCore\artifacts\bin\LearningASP.NETCore\Debug\dnx451\LearningASP.NETCore.xml"; public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
} public IConfigurationRoot Configuration { get; set; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc(); services.AddSwaggerGen(); services.ConfigureSwaggerDocument(options =>
{
options.SingleApiVersion(new Info
{
License = new License { Name = "irving", Url = @"http://cnblogs.com/irving" },
Contact = new Contact { Name = "irving", Email = "zhouyongtao@outlook.com", Url = @"http://cnblogs.com/irving" },
Version = "v1",
Title = "ASP.NET Core 1.0 WebAPI",
Description = "A Simple For ASP.NET Core 1.0 WebAPI",
TermsOfService = "None"
});
options.OperationFilter(new ApplyXmlActionComments(pathXml));
}); services.ConfigureSwaggerSchema(options =>
{
options.IgnoreObsoleteProperties = true;
options.DescribeAllEnumsAsStrings = true;
options.ModelFilter(new ApplyXmlTypeComments(pathXml));
});
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug(); if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
} app.UseIISPlatformHandler(); app.UseStaticFiles(); app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
}); app.UseSwaggerGen(); app.UseSwaggerUi();
} // Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
OrdersController类
[Route("api/orders")]
public class OrdersController : Controller
{
[HttpGet]
[Route("info")]
public async Task<ActionResult> Info()
{
return await Task.Run(() =>
{
return Json(new { name = "irving", age = });
}).ContinueWith(t => t.Result);
}
// GET: api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
访问:http://localhost/swagger/ui/index.html

REFER:
http://damienbod.com/2015/12/13/asp-net-5-mvc-6-api-documentation-using-swagger/
https://api.gitcafe.com/apidoc/
Swagger框架学习分享http://blog.csdn.net/u010827436/article/details/44417637
Micro Service工具集之Swagger:可测试的样式化API文档http://ningandjiao.iteye.com/blog/1948874
https://github.com/aspnet/Docs/blob/master/aspnetcore/tutorials/web-api-help-pages-using-swagger.md
https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-2.1
ASP.NET Core 1.0 中使用 Swagger 生成文档的更多相关文章
- asp.net core 3.0 中使用 swagger
asp.net core 3.0 中使用 swagger Intro 上次更新了 asp.net core 3.0 简单的记录了一下 swagger 的使用,那个项目的 api 比较简单,都是匿名接口 ...
- 在ASP.NET Core 3.0中使用Swagger
1.使用NuGet安装以下依赖: Swashbuckle.AspNetCore 注:版本选最高版本的,我选 5.0 rc4 2.在ConfigureServices添加以下代码 services.Ad ...
- ASP.NET Core Web API中使用Swagger
本节导航 Swagger介绍 在ASP.NET CORE 中的使用swagger 在软件开发中,管理和测试API是一件重要而富有挑战性的工作.在我之前的文章<研发团队,请管好你的API文档& ...
- ASP.NET Core 1.0 中的依赖项管理
var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...
- 在ASP.NET Core 1.0中如何发送邮件
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:目前.NET Core 1.0中并没有提供SMTP相关的类库,那么要如何从ASP.NE ...
- 用ASP.NET Core 1.0中实现邮件发送功能
准备将一些项目迁移到 asp.net core 先从封装类库入手,在遇到邮件发送类时发现在 asp.net core 1.0中并示提供SMTP相关类库,于是网上一搜发现了MailKit 好东西一定要试 ...
- 在ASP.NET Core 2.0中使用CookieAuthentication
在ASP.NET Core中关于Security有两个容易混淆的概念一个是Authentication(认证),一个是Authorization(授权).而前者是确定用户是谁的过程,后者是围绕着他们允 ...
- 如何在ASP.NET Core 2.0中使用Razor页面
如何在ASP.NET Core 2.0中使用Razor页面 DotNetCore2017-11-22 14:49 问题 如何在ASP.NET Core 2.0中使用Razor页面 解 创建一个空的项 ...
- ASP.NET Core 3.0中使用动态控制器路由
原文:Dynamic controller routing in ASP.NET Core 3.0 作者:Filip W 译文:https://www.cnblogs.com/lwqlun/p/114 ...
随机推荐
- nginx的Location的总结以及rewrite规则的总结
Location的语法: location 有”定位”的意思, 根据Uri来进行不同的定位. 在虚拟主机的配置中,是必不可少的,location可以把网站的不同部分,定位到不同的处理方式上. 比如, ...
- Reactjs 入门基础(三)
State 和 Props以下实例演示了如何在应用中组合使用 state 和 props .我们可以在父组件中设置 state, 并通过在子组件上使用 props 将其传递到子组件上.在 render ...
- css3伸缩布局属性总结
http://www.css88.com/book/css/properties/flex/flex-basis.htm http://c7sky.com/dive-into-flexbox.html ...
- 一段防盗连的PHP代码
$ADMIN[defaulturl] = http://www.163.com/404.htm; //盗链返回的地址 $okaysites = array("http://www.163 ...
- 企业内部从零开始安装docker hadoop 提纲
下载apache 项目 http://mirror.bit.edu.cn/apache/ 下载 centos 7 安装 盘 iso 大约7G 安装 centos7 copy 光盘盘中的 packag ...
- 亚马逊开放机器学习系统源代码:挑战谷歌TensorFlow
北京时间5月17日上午消息,亚马逊在开源技术领域迈出了更大的步伐,宣布开放该公司的机器学习软件DSSTNE的源代码.这个最新项目将与谷歌的TensorFlow竞争,后者已于去年开源.亚马逊表示,在缺乏 ...
- knockout.js $index 做列表索引小技巧
我们都知道,在foreach binding中,使用$index可以得到基于0的索引序号,但在列表显示中,我们更希望这个索引是从1开始的,怎么处理呢? 这里,有个小技巧:使用$index() + 1, ...
- 第一个Spring demo
参考Spring3.x企业实战 1.新建web工程chapter5,导入jar包.注意:cglib和commons-dbcp这两个包 2.设计数据库 t_login_log表结构(存放日志信息),主键 ...
- ng中的过滤器
angular中对输出的值提供过滤器,用法如下: {{name | currency:"¥"}}</p> 这是在在html中的用法,用 | 来添加过滤器,过滤器后面通过 ...
- WKWebView与Js (OC版)
OC如何给JS注入对象及JS如何给IOS发送数据 JS调用alert.confirm.prompt时,不采用JS原生提示,而是使用iOS原生来实现 如何监听web内容加载进度.是否加载完成 如何处理去 ...