github:https://github.com/domaindrivendev/Ahoy

之前文章有介绍在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 生成文档的更多相关文章

  1. asp.net core 3.0 中使用 swagger

    asp.net core 3.0 中使用 swagger Intro 上次更新了 asp.net core 3.0 简单的记录了一下 swagger 的使用,那个项目的 api 比较简单,都是匿名接口 ...

  2. 在ASP.NET Core 3.0中使用Swagger

    1.使用NuGet安装以下依赖: Swashbuckle.AspNetCore 注:版本选最高版本的,我选 5.0 rc4 2.在ConfigureServices添加以下代码 services.Ad ...

  3. ASP.NET Core Web API中使用Swagger

    本节导航 Swagger介绍 在ASP.NET CORE 中的使用swagger   在软件开发中,管理和测试API是一件重要而富有挑战性的工作.在我之前的文章<研发团队,请管好你的API文档& ...

  4. ASP.NET Core 1.0 中的依赖项管理

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  5. 在ASP.NET Core 1.0中如何发送邮件

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:目前.NET Core 1.0中并没有提供SMTP相关的类库,那么要如何从ASP.NE ...

  6. 用ASP.NET Core 1.0中实现邮件发送功能

    准备将一些项目迁移到 asp.net core 先从封装类库入手,在遇到邮件发送类时发现在 asp.net core 1.0中并示提供SMTP相关类库,于是网上一搜发现了MailKit 好东西一定要试 ...

  7. 在ASP.NET Core 2.0中使用CookieAuthentication

    在ASP.NET Core中关于Security有两个容易混淆的概念一个是Authentication(认证),一个是Authorization(授权).而前者是确定用户是谁的过程,后者是围绕着他们允 ...

  8. 如何在ASP.NET Core 2.0中使用Razor页面

    如何在ASP.NET Core 2.0中使用Razor页面  DotNetCore2017-11-22 14:49 问题 如何在ASP.NET Core 2.0中使用Razor页面 解 创建一个空的项 ...

  9. ASP.NET Core 3.0中使用动态控制器路由

    原文:Dynamic controller routing in ASP.NET Core 3.0 作者:Filip W 译文:https://www.cnblogs.com/lwqlun/p/114 ...

随机推荐

  1. sql case when 操作

    ,(CASE WHEN (SELECT COUNT(1) FROM BookAuthorizeObject WHERE BookAuthorizeObject.BookNo=T.BookNo)=8 T ...

  2. Centos下MySQL使用总结

    转载于CentOS中文站:http://www.centoscn.com/CentOS/Intermediate/2013/0817/1334.html 一.MySQL安装 Centos下安装mysq ...

  3. VS2012调试时无法启动程序和拒绝访问问题汇总

    很多人在使用VS2012的时候会出现下面所示的问题,我也是,而且不止一次,也不是同样的问题,我这里就把一些常见的解决方法罗列一下.

  4. ecshop的特点,持续加新

    一.目录文件结构 入口文件index.php,define('IN_ECS', true); 只有为true时才可以进入. 首先加入init.php,在这个文件里: @ini_set('memory_ ...

  5. 随笔—邀请赛前训— Codeforces Round #330 (Div. 2) Vitaly and Night

    题意:给你很多对数,要么是0要么是1.不全0则ans++. 思路即题意. #include<cstdio> #include<cstring> #include<iost ...

  6. ngx.lua中遇到的小问题

    作者: 胡 志伟 分类: ngx_lua, 开发代码 发布时间: 2013-09-26 08:40 ė 6评论关闭 在使用ngx.redirect 到一个新的地址时,错误日志提示: lua entry ...

  7. 跨进程(同一app不同进程之间通信)——Android自动化测试学习历程

    视频地址:http://study.163.com/course/courseLearn.htm?courseId=712011#/learn/video?lessonId=877122&co ...

  8. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

  9. node.js 基础学习 express安装使用

    安装好nodeJs,我们需要使用命令行中安装express. 我这里默认将Node.js安装在C:\Program Files\nodCejs\盘中. 在保持联网的状态下,依次输入如下命令. npm ...

  10. SAP 禁止某个库位的货物移动

    SAP 禁止某个库位的货物移动 1.先去spro --> 物料管理 --> 库存管理和实际库存 --> 权限管理 --> 授权检查存储位置 将要禁止的库位后的权限勾选上, 2. ...