简体   繁体   English

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

[英]How to insert a JSON code block for a Swagger-API using YAML?

In my swagger document that I am editing using YAML. 在我使用YAML编辑的招摇文件中。 I was intending to insert a Block of code using GFM syntax which is what swagger expects according to this document . 我打算使用GFM语法插入代码块,这是swagger根据本文档所期望的。

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

This however does not show up formatted as a JSON, instead it all ends up being on one line like this: 然而,这并没有显示为格式化为JSON,而是所有最终都在这样的一行上:

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

That it all ends up as one line is because you are using a folded style block scalar by specifying > ( - is for stripping chomping indicator). 这一切最终都是因为你通过指定>-用于剥离chomping指示符)来使用折叠样式块标量

What you want to use is a literal style block scalar , with that the line breaks and spacing is preserved. 你想要使用的是一个文字样式块标量 ,其中保留了换行符和间距。 You probably also want to use the default clip chomping (leaving one newline at the end of the JSON code): 您可能还想使用默认的剪辑选择(在JSON代码的末尾留下一个换行符):

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

(the only change is on the first line >- to | ) (唯一的变化是在第一行>-|

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM