4
我使用扬鞭OpenAPI的规格工具,我有一个字符串数组属性中的定义之一如下:如何在swagger propertise中添加多个示例值?
cities:
type: array
items:
type: string
example: "Pune"
我的API产生JSON结果因此对于下面的结果上述对象出现在响应:
{
"cities": [
"Pune"
]
}
试过逗号分隔的字符串象下面这样:
cities:
type: array
items:
type: string
example: "Pune", "Mumbai", "Bangaluru"
期待结果为:
{
"cities": [
"Pune",
"Mumbai",
"Bangaluru"
]
}
但编辑器显示错误。 “Bad indentation”
我想给示例标签提供多个值有没有什么办法?
更新
用户海伦下面给了正确的答案我有indentaion问题,因此有嵌套的数组(二维数组)
正确方法:
cities:
type: array
items:
type: string
example:
- Pune
- Mumbai
我的方式(这是错)
cities:
type: array
items:
type: string
example:
- Pune
- Mumbai
在上述两种情况下寻找example
标签的缩进,使其不同,它的YAML缩进很重要。
你给输出“城市”的解决方案:[ [ “普纳”, “孟买” ] ]这是两个嵌套数组,我不希望我想要单个数组将数组元素作为数组元素保存而不是新数组,感谢您的回复 – pcj
你在哪里看到嵌套数组?它在Swagger编辑器中工作正常: https://i.stack.imgur.com/uT85I.png – Helen
嘿谢谢海伦缩进问题看到更新的问题。 – pcj