简体   繁体   English

如何在 Web API 请求和响应主体的帮助页面中显示参数

[英]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为此,我遵循了 Generate Description Fields for Body Parameters 的答案,但没有成功,仍然显示

在此处输入图像描述

/// <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您必须将 XmlDocs 添加到您的 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.另一方面,您要求的是 object,这是您的 class。因此,class 的 xmldoc 将用于生成描述。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Web API帮助页面文档中显示仅响应的参数? - How to display parameter in Web API help page documentation for Response only? 如何在访问原始请求正文的同时为 Web API 帮助页面生成正文参数/示例请求 - How to generate Body Parameters/ Sample Request for Web API Help Page while having access to raw request body ASP.NET Web Forms:对外发起API请求并在页面显示响应 - ASP.NET Web Forms: Make an external API Request and display response on page 需要在 web Api2 项目中获取请求和响应正文和头部。我该怎么做? - Need to get request and response body and head in web Api2 project .How can i do it? 如何使用Content-Type:multipart / form-data通过Web API请求主体参数访问? - How request body parameter access by Web API using Content-Type: multipart/form-data? 如何强制JSON请求正文在ASP.NET Web API 2中包含某些特定参数 - How to force JSON request body to contain some specific parameter in ASP.NET Web API 2 自定义Web API帮助页面以删除请求格式 - Customize web api help page to remove the request formats 生成的WEB API帮助区文档不显示响应正文格式/示例 - Generated WEB API Help Area documentation does not show response body formats/samples Angular + Core API:如何拦截请求响应错误正文 - Angular + Core API: How to intercept request response error body Web Api 中的 Post 请求中的请求正文为空 - Request Body is null in Post request in Web Api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM