休息 – 使用IHttpActionResult时如何获取帮助文档在WebApi2中工作?

我想利用WebApi2的自动化文档功能以及IHttpActionResult.因此,我想更改以下代码
/// <summary>
/// Gets specified User 
/// </summary>
/// <param name="id">User Id</param>
/// <returns>The user</returns>
public usermodel Get(int id)
{
    usermodel result = new usermodel()
    {
        ErrorLevel = "Warning",ErrorMessage = "Not Implemented yet!"
    };
    User u = new User() { Id = 1,ADUserName = "nfindlater",DefaultRoutingGroupId = 1 };
    result.Data = u;

    var helper = new UrlHelper(Request);
    result.Url = helper.Link("User",new { userId = 1 });

    return result;
}

/// <summary>
    /// Gets specified User 
    /// </summary>
    /// <param name="id">User Id</param>
    /// <returns>The user</returns>
    public IHttpActionResult Get(int id)
    {
        usermodel result = new usermodel()
        {
            ErrorLevel = "Warning",ErrorMessage = "Not Implemented yet!"
        };
        User u = new User() { Id = 1,DefaultRoutingGroupId = 1 };
        result.Data = u;

        var helper = new UrlHelper(Request);
        result.Url = helper.Link("User",new { userId = 1 });

        return Ok<usermodel>(result);
    }

但是当我这样做时,我放松了/ Help / Api / GET-2013-12-05-user-id下自动生成api文档的一部分.

以下是丢失的文档的一部分:

响应体格式

application / json,text / json

样品:

{
“url”:“sample string 1”,
“data”:{
“id”:1,
“adUserName”:“sample string 2”,
“name”:“sample string 3”,
“defaultRoutingGroupId”:4
},
“errorLevel”:“sample string 2”,
“errorMessage”:“sample string 3”
}

解决方法

您可以使用“ResponseType”属性来装饰动作,并且HelpPage会选择此操作来生成示例…

示例:[ResponseType(typeof(usermodel)]

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....