如何使用 Swagger UI 对方法描述使用 html?

How can I use html on method description with Swagger UI?

我正在使用 Swashbuckle.AspNetCore 来可视化我的 .NET Core API 资源并与之交互。我正在尝试使用 html 格式化 Swagger 上的 API 方法描述,以便用户知道最近添加了此方法。

但我还没有找到如何做到这一点。我在摘要的 XML 文档注释中添加了 html 字符串,但返回为字符串。同时,我能够让它在响应中发挥作用。

我怎样才能使它工作或使用一些 "flashy" 方法来展示新方法,以便用户注意到它们是新的或更新的?这是我在控制器中的方法代码。

    /// <summary>
    /// <span style="font-size: 20px;color: red;">☆New method!</span>
    /// </summary>
    /// <returns>Gets the user commerce data</returns>
    /// <response code="200"><div><span style="font-size: 20px;color: red;">Returns user commerce data</span></div></response>
    /// <response code="401">User not authenticated</response>       
    /// <response code="404">Error: Not Found</response>       

    [HttpGet]
    [SwaggerResponse(200, Type = typeof(CommerceUserProfile))]
    [ProducesResponseType(401, Type = typeof(UnauthorizedResult))]
    [ProducesResponseType(404, Type = typeof(NotFoundResult))]
    public async Task<ActionResult<CommerceUserProfile>> Get()

这是我的启动代码。

     services.AddSwaggerGen(swagger =>
                {
                    swagger.SwaggerDoc("v1", new Info { Title = "API", Version = "v1" });
                    var xmlPath = Path.Combine(AppContext.BaseDirectory, "CommerceWebAPI.xml");
                    swagger.IncludeXmlComments(xmlPath);
                }

这就是正在生成的内容。我想像我在响应中所做的那样使用 html 格式化获取描述。

Swagger 有意转义摘要内容。

我认为这真的不可能实现你想要的。

Markdown也不支持,总结一下就可以用了。但是swagger在其他一些场景下是支持的。