2015-09-01 60 views
1

所以我一直在谷歌搜索很多試圖解決這個問題,但我似乎無法找到任何東西。請參閱圖片以供參考,但我試圖填寫正文參數的說明字段。做這個的最好方式是什麼?爲身體參數生成描述字段

missing body parameter description

回答

1

好了,所以我想通了這一點,希望這可以幫助遇到此問題的其他人。您要做的第一件事是按照link爲ApiExplorer啓用XML文檔。啓用後要添加

/// <summary>Description</summary> 

你上面的控制器名稱(您可以在XML中添加PARAM名稱,以及通過增加另一行<param name="model">A Test Model</param>

然後前往您的模型和內部的每個參數您的模型再次添加摘要標籤,如下所示:

public class TestModel() 
{ 
/// <summary>This is your IdNumber you received earlier</summary> 
public string IdNumber {get;set;} 
} 
1

您可以添加一個Description屬性:

[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/

+0

不幸的是,這沒有奏效。我仍留有「主體說明說明」的空白區域和主幫助頁面 – Kyle

1

我在這裏找到了答案,令人困惑,因此這裏是我的完整解決方案。

首先打開XMLDocumentation的區域 - > HelpPage - > App_Start - > HelpPageConfig.cs並取消註釋以下兩行。

// 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幫助頁面,則文檔應該可見。