嵌套数组很简单:
type: array
items:
type: array
items:
type: string
但OpenAPI / Swagger没有办法在查询字符串中序列化嵌套数组,就像在您的示例中一样 .
如果数组具有固定数量的项,则可能的解决方法是将每个嵌套数组定义为单独的查询参数:
paths:
/setup:
get:
parameters:
- in: query
name: array[0]
required: true
type: array
items:
type: string
collectionFormat: multi # array[0]=key1&array[0]=value1
- in: query
name: array[1]
required: true
type: array
items:
type: string
collectionFormat: multi # array[1]=key2&array[1]=value2
更好的方法是使用POST请求并在请求正文中传递数组:
paths:
/setup:
post:
consumes:
- application/json
parameters:
- in: body
name: body
required: true
schema:
type: array
items:
type: array
items:
type: string