0

I am trying to configure swagger for my application. Being new to this field I went to different tutorials and tried to convert the below json to YAML but it's giving errors like bad indentation, response missing etc. The main problem I am facing is in recognizing syntax to represent array of list in YAML format, then to add block in YAML which shows expected values for a particular block.

JSON Format to be converted to YAML:

  {
       "abc":[
          {
             "xyz":[ //array of list
                {
                   "id":"",
                   "name":"",
                   "relation":[ //array of list
                      {
                         "first":{
                            "xxx":"",
                            "xxx":"",
                            "xxx":[ //array of string
                               ""
                            ]
                         },
                         "second":{
                            "xxx":"",
                            "xxx":"",
                            "xxx":[
                               ""
                            ],
                            "type":""
                         }
                      },
                      {
                         "first":{
                            "xxx":"",
                            "xxx":"",
                            "xxx":[ //array of string
                               ""
                            ]
                         },
                         "second":{
                            "xxx":"",
                            "xxx":"",
                            "xxx":[
                               ""
                            ],
                            "type":""
                   }
                }
             ],
             "rows":[

             ]
          }
       ]
    }

YAML is as below:

    swagger: "2.0"
    info:
      version: 1.0.0
      title: xxxx
      description: xxxx
    schemes:
      - https
    host: xxxx
    basePath: xxxx
    paths:
      /xxx:
        post:
         summary: xxxx
         consumes:
            - application/json
         produces:
            - application/json
         parameters:
    abc:
        - xyz:
            id: string
            name: string
            relation: string
        - first:
            id: string
            name: string
            relation: string
          second:
             id: string
            name: string
            relation: string
        - first:
            id: string
            name: string
            relation: string
          second:
            id: string
            name: string
            relation: string

    responses:
            '200':
              description: Created
2

1 Answer 1

0

When working with YAML you talk about sequences (besides map an scalar). A sequences is what gets mapped to a list in Python and an array in some other languages.

So if you are talking about "represent array of list in YAML" you are actually referring to a sequence of sequences. There are three ways to represent this in YAML.

block-style within block-style:

- - a
  - b
- - c
  - d

, flow-style within block-style:

- [a, b]
- [c, d]

, or flow-style within flow-style:

[[a, b,], [c, d,],]

Any online YAML parser will show you that the above amounts to the same.

Please note:

  • You cannot have block-style within flow-style
  • You can have trailing commas (something that JSON doesn't allow, and which makes JSON unnecessarily hard to edit for humans).

In your example YAML output, which is correct YAML, there are no sequence of sequences (or array of lists in your terminology).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.