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. TCP报文段首部详解

    TCP虽然是面向字节流的,但是tcp传送的数据单元却是报文段,一个报文段分为首部和数据两部分,几乎TCP所有功能都从首部来体现,下面我们来详细的剖析下它的首部. (1):源端口与目标端口:分别写入源端 ...

  2. CSS3凹凸字

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  3. C语课设心得分享(二)

    咱们今儿说说IDE的事儿. IDE是「集成开发环境」的意思,比如咱们常用的VC6.0,就是开发C语言所用的IDE的一种.对于IDE的认识,可能有些朋友有点儿模糊,咱们捋一捋,我也会给出一些IDE方面的 ...

  4. oracle 同时更新(update)多个字段多个值

    --创建表A,B: create table A (a1 varchar2(33),a2 varchar2(33),a3 varchar2(33)); create table B (b1 varch ...

  5. [原创]HEXO博客搭建日记

    博客系统折腾了好久,使用过Wordpress,Ghost,Typecho,其中Typecho是我使用起来最舒心的一种,Markdown编辑+轻量化设计,功能不多不少刚好,着实让我这种强迫症患者舒服了好 ...

  6. Server Apache Tomcat v7.0 at localhost failed to start.

    自己在学习servlet中,突然启动不了Tomcat7服务器,提示出现如下错误: 百度之后,没有找到解决办法,偶然发现是我的Web-content下--WEB-INF下--web.xml的配置文件内 ...

  7. Java 基础知识总结 (三、运算符)

    三.Operators 运算符 Assignment Operators(赋值运算符) =   +=   -=   %=   *=   /=    <<=     >>=    ...

  8. Android Studio 初使用

    Android Studio 更改Eclipse快捷键 Android Studio 更改编码 Android Studio 导包

  9. CSS3动画与2D、3D转换

    一.过度动画:transition 五个属性: transition-property css 样式属性名称 transition-duration 动画持续时间(需要单位s) transition- ...

  10. Java学习笔记16--异常

    异常 异常是导致程序中断运行的一种指令流,如果不对异常进行正确的处理,则可能导致程序的中断执行,造成不必要的损失, 所以在程序的设计中必须要考虑各种异常的发生,并正确的做好相应的处理,这样才能保证程序 ...