Render html in springfox-swagger-ui

筅森魡賤 提交于 2019-12-10 13:55:55

问题


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")

回答1:


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

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

You have to translate your API description to Markdown.



来源:https://stackoverflow.com/questions/40261455/render-html-in-springfox-swagger-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!