2017-01-28 41 views
5

我装饰的动作如下对象不是原始用于响应消息模型

[SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(List<CustomerDto>))] 
[SwaggerResponse(HttpStatusCode.NotFound, Type = typeof(NotFoundException))] 

该行模型显示正确。

但是,在Repsonse消息下,我得到'对象不是原始'NotFound。自定义异常从Exception派生,实现ISerializable,也有[Serializable][DataContract()]

我怎么能显示实际数据类型的信息呢?

另外,如果我使用这些属性来装饰所有动作,我是否会在正常使用WebApi时发生性能下降?

回答

-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"); 
    } 

http://swashbuckletest.azurewebsites.net/swagger/ui/index#!/IHttpActionResult/IHttpActionResult_GetById

相关问题