【发布时间】:2018-03-02 19:34:15
【问题描述】:
我是第一次创建一组 API。这是其中一种方法:
// GET: api/Doors/0
/// <summary>
/// Get a list of all doors for a given organization.
/// </summary>
/// <param name="organizationSys">The Organization ID for which all doors should be retreived.</param>
/// <returns></returns>
[Route("{organizationSys:int}")]
public IHttpActionResult Get(int organizationSys)
{
try
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("@OrganizationSys", organizationSys);
List<Door> doors = Repository<Doors>.GetList("WHERE OrganizationSys = @OrganizationSys", parameters).ToList();
if (doors == null || doors.Count() == 0)
return Content(HttpStatusCode.NotFound, RejectionMessage.NoItemsFound);
return Ok(doors);
}
catch (Exception ex)
{
return Content(HttpStatusCode.BadRequest, ex.Message);
}
}
我已经为此端点设置了一个单元测试,它运行良好。不过,我确实有一个问题。
在 Swagger 中,我想展示一个将返回的数据对象的示例。该方法的唯一返回类型是IHttpActionResult,所以我并不惊讶它没有在 Swagger 中显示数据模型。那么,我需要对这个方法进行哪些更改,以使返回对象(在本例中为 List<Door>)更加可见?
Swashbuckle 支持这个吗?
谢谢!
【问题讨论】:
-
这个 Q 看起来很像:stackoverflow.com/questions/49028001/…
标签: c# .net api swagger swashbuckle