对象不是响应消息模型的基元

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)

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