Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

json

yaml

swagger

In my swagger document that I am editing using YAML. I was intending to insert a Block of code using GFM syntax which is what swagger expects according to 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
    }
  }
  ```

This however does not show up formatted as a JSON, instead it all ends up being on one line like this:

Some description of the object here. More Here. An example to for this is as follows: ```json { "Key": { "name": "myName", "id": 100 } } ```
like image 361
Pika Avatar asked Jun 03 '16 15:06

Pika


1 Answers

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).

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):

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 |)

like image 111
Anthon Avatar answered Oct 02 '22 23:10

Anthon