c# - 使用 Swagger 的特定状态代码的响应模型

标签 c# rest asp.net-web-api swagger

我正在使用 Swagger记录我的 REST API(使用 asp.net web api 2)。有没有办法 Swagger 为给定 api 调用的每个可能响应提供响应模型?我正在使用 xml 注释注释状态代码响应,如下所示:

    /// <summary>
    /// Save a person
    /// </summary>
    /// <response code="200">Ok</response>
    /// <response code="400">Bad Request</response>
    /// <response code="500">Internal Server error</response>
    public HttpResponseMessage SavePerson() {...}

enter image description here

最佳答案

您可以像这样在您的 XML 注释上尝试使用 cref="TYPE HERE"。

/// <response code="400" cref="CustomErrorModel">Bad Request</response>

乙 但我建议使用 Swagger 为您提供的注释。

[SwaggerResponse(HttpStatusCode.OK, Type = typeof(OnlineMerchantQueryResponseInformation))]

将此归因于您的 Controller 。

关于c# - 使用 Swagger 的特定状态代码的响应模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29489304/

相关文章:

javascript - JQuery 导出到 Excel 无法正常工作

c# - 我的类似乎没有与 API 的 JSON 响应正确映射,没有绑定(bind)

c# - CRM 2011 插件 (C#) - 遍历表单子(monad)网格中的记录

c# - 将 WCF 服务转换为 RESTful 应用程序?

php - 如何编写 REST API?

c# - ApiController 没有收到我的日期时间?

c# - 从 VSTest.Console.exe 向单元测试传递参数或选项

c# - 在 WCF Webapi 站点上验证 Android 客户端?

asp.net-web-api - application/x-www-form-urlencoded 的自定义属性名称绑定(bind)

cookies - 使用表单例份验证的照片上传 Phonegap 请求失败