首页 > 解决方案 > 如何在 ASP.NET Core API 的 Swagger 中将注释显示为描述段落

问题描述

我在 asp.net-core 中有一个 web api,我想知道如何将段落作为描述放在端点上?我试过

\n \n ,没有任何效果。我将描述放在“备注”xml 中。

谢谢

标签: asp.net-coreswagger

解决方案


首先,您必须配置 Swashbuckle 以使用文档 XML

然后,使用<summary><remarks>标记进行操作摘要和描述。

/// <summary>
/// Summary for ActionWithSummaryAndRemarksTags
/// </summary>
/// <remarks>
/// Remarks for ActionWithSummaryAndRemarksTags
/// </remarks>
public ActionResult ActionWithSummaryAndRemarksTags()

您可以使用 Markdown 构建更复杂的文档:

/// <summary>
/// This is a short summary
/// </summary>
/// <remarks>
/// ## Usage
/// ...
/// ```
/// <![CDATA[
/// {
///   "html": "<h1>escape HTML with CDATA blocks</h1><img src=\"https://unsplash.it/400/200\" />"
/// }
/// ]]>
/// ```
///
/// ### A title
/// A paragrapth with [a link](https://example.com).
/// 
/// ```html
/// <h1>hello world, this is a code block</h1>
/// <img src="data:image/jpg,base64;..." />
/// ```
/// This is an inline code `https://unsplash.it/200/100`.
///
/// This is a separate paragraph
/// </remarks>


推荐阅读