在springfox-swagger-ui中渲染html [英] Render html in springfox-swagger-ui

查看:583
本文介绍了在springfox-swagger-ui中渲染html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近更新了一个运行springfox-swagger2和springfox-swagger-ui 2.5.0的应用程序以使用2.6.0版本。应用程序的API文档使用< li> < b> < br> ;< code>< li>< / code>和< code>标准, < / code>标记被swagger-ui忽略。



为了让springfox再次呈现HTML标签,我必须做些什么?



标签用于以下位置:

  ApiInfoBuilder( ).description(HERE)

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


解决方案

在用 @ApiOperation 注解进行实验之后, 2.7.0版本SpringFox支持


我需要做什么SpringFox再次呈现HTML标签?


您必须将您的API描述翻译为Markdown。


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

解决方案

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.

这篇关于在springfox-swagger-ui中渲染html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆