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

问题描述 投票:0回答:1

似乎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代码片段?

swagger-ui
1个回答
2
投票

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

这是我使用的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修复了上述版本。

© www.soinside.com 2019 - 2024. All rights reserved.