【发布时间】:2017-04-30 21:54:06
【问题描述】:
我在使用 swagger 时遇到了一些问题:我在 .yaml 文件中有一个以这种方式描述的对象(地址)数组:
Address:
properties:
street:
type: string
city:
type: string
state:
type: string
country:
type: string
这是另一个带有 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'
这是我在 swagger UI 中输入的文字:
[
{
"street": "Bond street",
"city": "Torino",
"state": "Italy",
"country": "Italy"
}
]
但在 node.js 中,如果我打印收到的内容:
{"地址":["["," {"," \"street\": \"邦德街\","," \"city\": \"Torino\","," \"state\": \"Italy\","," \"country\": \"意大利\""," }","]"]}
我得到一个解析错误...有一些额外的 [ 和 "。似乎招摇将它解析为字符串 (?)
【问题讨论】:
-
你使用
the .yaml file(带点)和the other yaml file(不带点)有什么意义吗? -
请发布您的完整 .yaml 文件。它们在同一个文件夹中吗?您使用什么代码在 Node.js 端打印数据?
-
不,yaml 文件不在同一个文件夹中,但我认为这不是问题,因为 swagger ui 中的描述有效。要打印数据,我使用 JSON.stringify