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

时间:2019-07-25 06:28:35

标签: .net-core swagger swagger-ui

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

但是我还没有找到该怎么做的方法。我在摘要的XML文档注释中添加了html字符串,但以字符串形式返回。同时,我可以使其对响应起作用。

如何使它起作用或使用一些“浮华”的方法来展示新方法,以便用户注意到它们是新方法还是已更新?这是我在控制器中方法的代码。

    /// <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);
                }

Results

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

1 个答案:

答案 0 :(得分:0)

Swagger出于目的转义了摘要内容。

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

还不支持Markdown以便能够摘要使用。但是swagger在其他一些情况下也支持它。