mika
mika

Reputation: 2585

Render html in springfox-swagger-ui

I recently updated an application running springfox-swagger2 and springfox-swagger-ui 2.5.0 to use version 2.6.0. The application's API documentation uses <li>, <b> and <br> tags, which were rendered correctly with 2.5.0, but with version 2.6.0 the <li> and <br> tags are ignored by the swagger-ui.

What do I have to do to make springfox render the HTML tags again?

The tags are used at the following positions:

ApiInfoBuilder().description("HERE")

@ApiOperation(notes="HERE")
@ApiResponse(message="HERE")

Upvotes: 7

Views: 4204

Answers (1)

naXa stands with Ukraine
naXa stands with Ukraine

Reputation: 37946

After experimenting with @ApiOperation annotation I discovered that in version 2.7.0 SpringFox supports Markdown syntax for text formatting (just like Stack Overflow, GitHub, Atlassian and others). See any Markdown syntax guide for reference.

My experiments show that this Swagger annotation and the following YAML definition should be equivalent.

@ApiOperation(value = "Markdown in Swagger API descriptions",
    notes = "#Head 1 \n## Head 2 \n###Sorting rules\nThe data is sorted by priority (from the highest to the lowest).<br/> Unordered list \n * item 1.\n * <b>bold item 2</b>\n")

=

summary: Markdown in Swagger API descriptions
description: <h1>Head 1</h1><h2>Head 2</h2><h3>Sorting rules</h3>
             The data is sorted by priority (from the highest to the lowest).<br/> Unordered list
             <ul><li>item 1.</li><li><b>bold item 2</b></li></ul>

And the annotation produces this output in Swagger-UI

Swagger UI 2.7.0 (markdown)

What do I have to do to make SpringFox render the HTML tags again?

You have to translate your API description to Markdown.

Upvotes: 16

Related Questions