Search code examples
c#.net-coreswaggerswagger-ui

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


I'm using Swashbuckle.AspNetCore to visualize and interact with my .NET Core API resources. I'm trying to format an API method description on Swagger with html so the user knows this method has been added recently.

But I haven't found yet how to do this. I added the html string on the XML Documentation Comments on summary but is returned as string. Meanwhile I'm able to make it work on the responses.

How can I make it work or use some "flashy" way to feature new methods so the user notices they are new or updated? This is the code of my method in the controller.

    /// <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()

This is my Startup code.

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

Results

This is what is being generated. I want to format the get description using html like I did in the response.


Solution

  • Swagger escapes summary content for purpose.

    I dont think that this is really possible to achieve what you want.

    Markdown is also not supported to be able to use it in summary. But swagger supports it in some other scenarios.