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

时间:2017-04-19 15:13:01

标签: swagger swagger-ui swagger-2.0 swagger-editor

我想在我的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不支持此功能吗?

1 个答案:

答案 0 :(得分:0)

代码块格式化问题已在Swagger UI 3.22.0和Swagger Editor 3.6.26中修复。代码块在以下版本中正确显示:

A Markdown code block displayed by Swagger UI

请注意文本中“ data键”和“包含”之间的换行符-这是由| 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"
          }
      }
      ```