是一样贝尔巴托夫说,你可以添加注释与SwaggerResponse响应,要求是有点不同的,就像你添加XML注释到你的动作,你应该添加到的参数,下面是一个例子:
using Swagger.Net.Annotations;
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Http;
using System.Web.Http.Results;
namespace Swagger_Test.Controllers
{
public class IHttpActionResultController : ApiController
{
[SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(IEnumerable<int>))]
[SwaggerResponse(HttpStatusCode.NotFound, Type = typeof(NotFoundResult))]
public IHttpActionResult Post(MyData data)
{
throw new NotImplementedException();
}
}
/// <summary>My super duper data</summary>
public class MyData
{
/// <summary>The unique identifier</summary>
public int id { get; set; }
/// <summary>Everyone needs a name</summary>
public string name { get; set; }
}
}
而且在招摇,这将是这样的:
这里是一个生动的例子: http://swashbuckletest.azurewebsites.net/swagger/ui/index?filter=IHttpActionResult#/IHttpActionResult/IHttpActionResult_Post – HelderSepu
这里是代码背后: https://github.com/ heldersepu/SwashbuckleTest/BLOB/eb89ab65a3e735f022104c153f2f7af21bc8bf48/Swagger_Test /控制器/ IHttpActionResultController.cs – HelderSepu
现在这个有趣的是我在所示的例子添加///的唯一标识符 ...就像但是说明没有招摇的文档显示,我的模型是在一个单独的项目(这是否重要?) –
001