1

所以我一直在谷歌上搜索很多东西来尝试解决这个问题,但我似乎找不到任何东西。请参阅图片以供参考,但我正在尝试填写主体参数的描述字段。做这个的最好方式是什么?

缺少body参数说明

4

4 回答 4

1

我发现这里的答案令人困惑,所以这是我的完整解决方案。

首先通过转到 Areas -> HelpPage -> App_Start -> HelpPageConfig.cs 并取消注释以下两行来打开 XMLDocumentation。

// Uncomment the following to use the documentation from XML documentation file.
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));

然后,对于您要提供文档以创建以下格式的 xml 注释的方法。这对我来说通常是自动完成的,但我打开了 resharper,所以这可能不是默认设置。

    /// <summary>
    /// An example method description
    /// </summary>
    /// <param name="id">An example parameter description</param>
    /// <returns>An example return value description</returns>
    // GET: api/Products/5
    public string Get(int id)
    {
        return "value";
    }

如果您运行应用程序并转到您的 api 帮助页面,文档应该是可见的。

于 2017-06-06T23:14:06.073 回答
1

好吧,所以我想通了,希望这可以帮助遇到此问题的其他人。您要做的第一件事是点击此链接为 ApiExplorer 启用 XML 文档。启用后要添加

/// <summary>Description</summary>

在您的控制器名称上方(您也可以通过添加另一行在 xml 中添加参数名称<param name="model">A Test Model</param>

然后前往您的模型,并为模型中的每个参数再次添加摘要标签,如下所示:

public class TestModel()
{
/// <summary>This is your IdNumber you received earlier</summary>
public string IdNumber {get;set;}
}
于 2015-09-02T15:32:50.087 回答
1

您可以添加描述属性:

[Description("Get the data from our service. It will requires a key.")]
public ActionResult GetData(string key)
{
  //Do something here...
  return Json(new{Success=true, Data = data});
}

或者对于参数

public ActionResult GetData([Description("A valid key should be formated as xxx-xxx-xx")]string key)
{
  //Do something here...
  return Json(new{Success=true, Data = data});
}

来自: http: //millionbonus.bitbucket.org/mvc.apiexplorer/

于 2015-09-01T19:12:30.737 回答
0
  1. 右键单击项目,单击属性-> 构建-> 单击 XML 构建,如图所示。

在此处输入图像描述

  1. 转到项目中的区域文件夹 -> App_Start -> HelpPageConfig.cs

  2. 如果有注释,请取消注释以下行。

    config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/ projectname.xml ")));

  3. 将 MapPath 文件名更改为构建 XML 文档文件列中给出的名称。*projectname 将更改为您的项目名称。

于 2020-11-03T11:04:39.170 回答