如何使用YAML为Swagger-API插入JSON代码块?

时间:2016-06-03 15:33:47

标签: json yaml swagger

在我使用YAML编辑的招摇文件中。我打算使用GFM语法插入代码块,这是swagger根据this document所期望的。

description: >-
  Some description of the object here.
  More Here. An example to for this is as follows:
  ```json
  {
    "Key": {
      "name": "myName",
      "id": 100
    }
  }
  ```

然而,这并没有显示为格式化为JSON,而是所有这些都最终出现在这样的一行:

Some description of the object here. More Here. An example to for this is as follows: ```json { "Key": { "name": "myName", "id": 100 } } ```

1 个答案:

答案 0 :(得分:6)

这一切都以一行结束,因为您使用folded style block scalar指定>-用于删除扼流指示符)。

您要使用的是literal style block scalar,其中包含换行符和间距。您可能还想使用默认的剪辑选择(在JSON代码的末尾留下一个换行符):

description: |
  Some description of the object here.
  More Here. An example to for this is as follows:
  ```json
  {
    "Key": {
      "name": "myName",
      "id": 100
    }
  }
  ```

(唯一的更改是在第一行>-|