简体   繁体   English

如何在ASP.NET WebApi帮助页面中记录可选的QueryString参数?

[英]How do I document an optional QueryString parameter in ASP.NET WebApi Help Pages?

The ASP.Net Web Api Help Pages seem to automatically determine if a parameter is in the Request Uri or Body. ASP.Net Web Api帮助页面似乎自动确定参数是否在Request Uri或Body中。 How can I document option parameters that are QueryString parameters? 如何记录QueryString参数的选项参数?

For example I have may have a RESTful Url such as 例如,我可能有一个RESTful Url,例如

[GET] api/Books?relatedToBookId=xx

Where "relatedToBookId" is an optional queryString parameter. 其中“relatedToBookId”是可选的queryString参数。

Normally the parameters that are FromUri or FromBody are put into the comments as 通常,将FromUri或FromBody的参数放入注释中

<param name="variableName">blah blah</param>

You could do the following and your optional query string parameter info would show up in the HelpPage. 您可以执行以下操作,您的可选查询字符串参数信息将显示在HelpPage中。

In the below code relatedToBookId is an optional parameter coming from Query String. 在下面的代码relatedToBookId是来自Query String的可选参数。

    /// <summary>
    /// Gets list of books
    /// </summary>
    /// <param name="relatedToBookId">Your description here</param>
    /// <returns>returns list of books</returns>
    public IEnumerable<Book> GetBooks(int? relatedToBookId = null)

Also, if you would like to mention about this parameter being optional, you can do the following: 此外,如果您想提及此参数是可选的,您可以执行以下操作:

  • Go to the installed file (Areas/HelpPage/Views/Help/DisplayTemplates/Parameters.cshtml) 转到已安装的文件(Areas / HelpPage / Views / Help / DisplayTemplates / Parameters.cshtml)

  • Update the condition related to case ApiParameterSource.FromUri to the following: 将与case ApiParameterSource.FromUri相关的条件更新为以下内容:

    case ApiParameterSource.FromUri: <p>Define this parameter in the request <b>URI</b>.</p> if(parameter.ParameterDescriptor.IsOptional) { <p>This parameter is <b>optional</b>.</p> } break;

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

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