我有一个返回类型,它是一个包含两个元素的数组。第一个元素是一个整数,第二个元素是一个带有sql_ident和name键的字典数组。sql_ident值是一个整数,name值是一个字符串。
我不知道如何在response对象中对此进行建模。所以它会是这样的:
[
12,
[
{
"sql_ident" : 17,
"name" : "Billy Bob"
},
{
"sql_ident" : 935,
"name" : "Tina Turner"
}
]
] 发布于 2017-03-16 03:19:09
在OpenAPI/Swagger 2.0中,数组项必须是相同类型的,因此无法精确地对响应进行建模。您最多只能为items使用typeless schema,这意味着项可以是任何类型-数字、对象、字符串等-但您不能指定项的确切类型。
definitions:
MyResponse:
type: array
items: {}在OpenAPI 3.0中,可以使用oneOf和anyOf来描述多类型数组
components:
schemas:
MyResponse:
type: array
items:
oneOf:
- type: integer
- type: array
items:
$ref: "#/components/schemas/MyDictionary"
MyDictionary:
type: object
properties:
sql_ident:
type: string
name:
type: stringhttps://stackoverflow.com/questions/41904148
复制相似问题