大胆的自定义响应

时间:2019-06-07 10:46:11

标签: c# swagger asp.net-apicontroller

我在写

/// <summary>
/// someMethod
/// </summary>
/// <param name="name">name</param>
/// <response code="200" cref="APIResult">Success</response>
/// <returns></returns>
[HttpGet("someMethod")]
[ProducesResponseType(typeof(APIResult), 200)]
public APIResult someMethod(string name)
{
    return new APIResult();
}

但是我无法获得 APIResult 结构

enter image description here

我该怎么办?

我使用.net core 2.1
库NSwag.AspNetCore Version = 12.3.1

2 个答案:

答案 0 :(得分:0)

因为是通过注释而不是注释:

 [ProducesResponseType(typeof(APIResult), 200)]
 public async Task<APIResult> get()
 {
 }

大摇大摆地阅读模型要公开的内容

更新:好的,很抱歉。我没有阅读所有内容。

请尝试添加以下内容:

[Produces("application/json")]

答案 1 :(得分:0)

您需要使用以下内容,返回类型错误

public async Task<ActionResult>

然后

return Ok<object>;