简体   繁体   English

在Swagger中,如何将参数定义为多维数组?

[英]In Swagger, how do I define a parameter as a multidimensional array?

In Swagger, I'm able to create a parameter that is an array of any type like this: 在Swagger中,我能够创建一个参数,它是任何类型的数组,如下所示:

"MyType" : {
  "description" : "my example object type",
  "type" : "object",
  "properties" : {
    "id" : {
      "description" : "identifier",
      "type" : "number"
    },
    "data" : {
      "description" : "data container",
      "type" : "array",
      "items" : {
        "type" : "string"
      }
    }
  }
}

Which defines an object that might look like this: 其中定义了一个可能如下所示的对象:

{
  "id" : 1,
  "data" : ["a", "b", "c"]
}

But what I need to do is define an object that might look like this: 但我需要做的是定义一个可能如下所示的对象:

{
  "id" : 1,
  "data" : [
    [0, 1, 2],
    ["a", "b"],
    [true, "foo", 99, false]
  ]
}

The data property needs to be a multidimensional array, and ideally it could contain any number of "rows", each with any number of columns containing any type of data in each field. data属性需要是一个多维数组,理想情况下它可以包含任意数量的“行”,每个行包含任意数量的列,每列包含任何类型的数据。 I'd even settle for the schema allowing for data to just be an array of anything, but I can't figure out how to get that to work. 我甚至满足于模式允许数据只是一个任何东西的数组,但我无法弄清楚如何让它工作。

All you need to do is change the type of the items schema to be array . 您需要做的就是将items schema的type更改为array The following schema means "data" is an array, whose items are arrays. 以下模式表示“data”是一个数组,其项目是数组。 There are no constraints on the inner arrays. 内部数组没有约束。

"data" : {
  "description" : "data container",
  "type" : "array",
  "items" : {
    "type" : "array",
    "items": {}
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM