是一樣貝爾巴托夫說,你可以添加註釋與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