如何在Swagger UI 3.x中描述代码块的格式?

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

我想在我的API描述中放置一个Markdown代码块,但Swagger UI似乎在阅读,好像它是一个单行代码片段。我目前有:

description: |
    This API was created to allow interaction with the Image Status Database (ISD)

    ## Requests

    ## Responses
    In the case of a successful response, you will always receive a `data` key
    that contains your data.
    ```
    {
        "meta": {
            "code": 200
        },
        "data": {
            ...
        },
        "pagination": {
            "next_url": "...",
            "next_max_id": "13872296"
        }
    }
    ```

这显示为:

Swagger UI Screenshot

但是,Swagger编辑器显示正确的代码块:

Swagger Editor Screenshot

Swagger UI不支持这个吗?

swagger swagger-ui swagger-2.0 swagger-editor
1个回答
0
投票

代码块格式化问题在Swagger UI 3.22.0和Swagger Editor 3.6.26中得到修复。代码块在这些版本中正确显示:

注意文本中“a data key”和“that contains”之间的换行符 - 它是由| literal block style引起的,它保留了YAML多行字符串中的换行符。为了避免断行,您可以1)在YAML中删除它,或2)使用>折叠样式并缩进代码块(以防止折叠),如下所示:

  description: >
    This API was created to allow interaction with the Image Status Database (ISD)

    ## Requests

    ## Responses

    In the case of a successful response, you will always receive a `data` key
    that contains your data.

      ```
      {
          "meta": {
              "code": 200
          },
          "data": {
              ...
          },
          "pagination": {
              "next_url": "...",
              "next_max_id": "13872296"
          }
      }
      ```
© www.soinside.com 2019 - 2024. All rights reserved.