大量对象

Lor*_*one 0 arrays object swagger

我有些sw草:我在.yaml文件中有一个用这种方式描述的对象(地址)数组:

Address:
  properties:
    street:
      type: string
    city:
      type: string
    state:
      type: string
    country:
      type: string
Run Code Online (Sandbox Code Playgroud)

这是另一个具有API定义的yaml文件(地址是一个参数):

 - name: addresses
   in: formData
   description: List of adresses of the user. The first one is the default one.
   type: array
   items:
     $ref: '#/definitions/Address'
Run Code Online (Sandbox Code Playgroud)

这是我在大摇大摆的用户界面中输入的文本:

[
  {
    "street": "Bond street",
    "city": "Torino",
    "state": "Italy",
    "country": "Italy"
  }
]
Run Code Online (Sandbox Code Playgroud)

但是在node.js中,如果我打印出我收到的内容:

{“地址”:[“ [”,“ {”,“ \”街道\“:\”邦德街\“,”,“ \”城市\“:\”都灵\“,”,“ \”州\ “:\”意大利\“,”,“ \”国家\“:\”意大利\“”,“}”,“]”]}

而且我遇到了解析错误...还有一些额外的[和“。似乎大张旗鼓地将其解析为字符串(?)

Hel*_*len 5

要发送JSON数据,您需要使用in: body参数(不是in: formData)并指定操作消耗application/jsonformData参数用于消耗application/x-www-form-urlencoded或的操作multipart/form-data

paths:
  /something:
     post:
       consumes:
         - application/json
       parameters:
         - in: body
           name: addresses
           required: true
           schema:
             type: array
             items:
               $ref: "#/definitions/Address"  # if "Address" is in the same file
               # or
               # $ref: "anotherfile.yaml#/definitions/Address"  # if "Address" is in another file
Run Code Online (Sandbox Code Playgroud)