2017-01-28 77 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

相關問題