简体   繁体   中英

How to display parameter in Web API help page for request and response body

I want to show request and response body as parameter not as raw data. For that I have followed Generate Description Fields for Body Parameters answer but not get success, still showing

在此处输入图像描述

/// <summary>
    /// Gets some very important data from the server.
    /// </summary>
    /// <param name="reqData">A Test Model</param>
    [HttpPost]
    public AccountService.GetAccountList_ResponseData GetAccountList([FromBody] AccountService.GetAccountList_ReqestData reqData)
    {
    }
    
    //--my modal
    public class GetAccountList_ReqestData 
    {
        /// <summary>
        /// StartDate 
        /// </summary>
        /// <param name="StartDate">Describe parameter.</param>
        public string StartDate { get; set; }
    }
   
   //---Also enabled 
   config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/WebApi.xml")));

You have to add XmlDocs to your class GetAccountList_RequestData

/// <summary>
/// My requestData model
/// </summary>
/// <param name="reqData">The description you want </param>
public class GetAccountList_ReqestData 
{
   /// <summary>
   /// StartDate 
   /// </summary>
   /// <param name="StartDate">Describe parameter.</param>
   public string StartDate { get; set; }
}

You followed the steps correctly, however the person asking in the other thread was displaying a property. You on the other hand are asking for an object, which is your class. Therefor the xmldocs of the class will be used to generate the descriptions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM