在信息部分中包含Swagger-UI代码块

时间:2017-05-16 20:26:46

标签: swagger-ui

看起来Swagger UI正在扯掉并弄乱看起来像HTML标签的东西,即使在内部降价三重反引号分隔的代码块中也是如此!

我写过

swagger: '2.0'
info:
  title: My Title
  description: |
    Hello here is some Python code
    ```
      def hello():
          return "hello"
    ```
    and here is some HTML
    ```
      <body>
      <p>Hello</p>
      <script>x = 1</script>
      </body>

    ```
    That is all

不幸的是,Swagger-UI将其呈现为 enter image description here

我并没有抱怨它没有在降价中使用highlight.js;它毕竟是一个开源项目,可以修复。但是,我注意到它剥离了HTML标签,这很好,除了当我试图像这样逃避尖括号时:

swagger: '2.0'
info:
  title: My Title
  description: |
    Hello here is some Python code
    ```
      def hello():
          return "hello"
    ```
    and here is some HTML
    ```
      &lt;body>
      &lt;p>Hello</p>
      &lt;script>x = 1</script>
      &lt;/body>

    ```
    That is all

然后该工具以

返回

enter image description here

有谁知道如何击败Swagger-UI并显示HTML代码段?

1 个答案:

答案 0 :(得分:1)

Swagger UI v.3正确显示代码块中的HTML标记:

Markdown code block in API description displayed in Swagger UI

这是我使用的YAML:

  description: |
    Hello here is some Python code
    ```
    def hello():
      return "hello"
    ```
    and here is some HTML
    ```
    <body>
      <p>Hello</p>
      <script>x = 1</script>
    </body>
    ```
    That is all


注意:如果您的代码块存在如下所示的样式问题,请升级到Swagger UI 3.22.0+或Swagger Editor 3.6.26+。旧版本的CSS issue已在上述版本中修复。

Code blocks in API description in Swagger UI