Iva*_*ono 5 c# asp.net asp.net-mvc swagger swashbuckle
我按如下方式装饰了一个动作
[SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(List<CustomerDto>))]
[SwaggerResponse(HttpStatusCode.NotFound, Type = typeof(NotFoundException))]
Run Code Online (Sandbox Code Playgroud)
OK模型显示正确.
但是,在Repsonse Messages下,我得到'对象不是原始' NotFound.自定义异常派生自Exception,实现ISerializable,也有[Serializable]和[DataContract()]
如何显示实际数据类型而不是消息?
另外,如果我使用这些属性装饰所有动作,那么在正常使用WebApi时是否会导致性能下降?
Hel*_*eda -1
怎么样:
[SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(IEnumerable<int>))]
[SwaggerResponse(HttpStatusCode.BadRequest, Type = typeof(BadRequestErrorMessageResult))]
[SwaggerResponse(HttpStatusCode.NotFound, Type = typeof(NotFoundResult))]
public IHttpActionResult GetById(int id)
{
if (id > 0)
return Ok(new int[] { 1, 2 });
else if (id == 0)
return NotFound();
else
return BadRequest("id must be greater than 0");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
503 次 |
| 最近记录: |