[英]How do you create a swagger schema that includes an array of varying types
[英]How to create swagger array
我正在尝试创建一个低于JSON的swagger文档,但我得到以下错误: 带有'type:array'的模式,需要兄弟'items:'字段
JSON:
{
"_id": "string",
"name": "string",
"descriptions": {},
"date": "string",
"customer": {
"id": "string",
"name": {
"firstName": "string",
"lastName": "string",
"middleName": "string"
}
},
"productDetials": {
"id": "string",
"name": {
"name": "string",
"model": "string",
"price": "string",
"comments": "string"
}
},
"Phone": [{
"id": "string",
"category": "string",
"version": "string",
"condition": "string",
"availability": "string"
}
]
}
有人可以帮助我获得这个JSON的swagger文档。
任何帮助将非常感激。
首先,您必须定义依赖于JSON(对象)的模型。
在你的情况下:
Order
(我猜) Customer
CustomerName
ProductDetails
ProductName
Phone
然后在YAML(Swagger模式文档)的definitions
部分中定义模型:
Order:
type: "object"
properties:
_id:
type: "string"
name:
type: "string"
descriptions:
type: "object"
date:
type: "string"
customer:
$ref: "#/definitions/Customer"
productDetails:
$ref: "#/definitions/ProductDetails"
phoneNumbers:
type: "array"
items:
$ref: "#/definitions/Phone"
Customer:
type: "object"
properties:
id:
type: "string"
name:
$ref: "#/definitions/CustomerName"
CustomerName:
type: "object"
properties:
firstName:
type: "string"
lastName:
type: "string"
middleName:
type: "string"
ProductDetails:
type: "object"
properties:
id:
type: "string"
name:
$ref: "#/definitions/ProductName"
ProductName:
type: "object"
properties:
name:
type: "string"
model:
type: "string"
price:
type: "string"
comments:
type: "string"
Phone:
type: "object"
properties:
id:
type: "string"
category:
type: "string"
version:
type: "string"
condition:
type: "string"
availability:
type: "string"
如果要将具有特定模型的数组定义为项目 - 将array
作为type
并定义items
(根据提供的错误代码,您忘记了它)。 items
是数组的内容 - 所以在你的情况下的Phone
模型:
...
phoneNumbers:
type: "array"
items:
$ref: "#/definitions/Phone"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.