比较来自世界各地的卖家的域名和 IT 服务价格

如何确定方案中的最小数组大小 json

我想制定一个计划 json file.It's 用于产品数组。

方案 json 类似于以下内容:


{
"$schema": "[url=http://json-schema.org/draft-04/schema#"]http://json-schema.org/draft-04/schema#"[/url],
"title": "Product set",
"type": "array",
"items": {
"title": "Product",
"type": "object",
"properties": {
"id": {
"description": "The unique identifier for a product",
"type": "number"
},
"name": {
"type": "string"
},
"price": {
"type": "number",
"minimum": 0,
"exclusiveMinimum": true
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"dimensions": {
"type": "object",
"properties": {
"length": {"type": "number"},
"width": {"type": "number"},
"height": {"type": "number"}
},
"required": ["length", "width", "height"]
},
"warehouseLocation": {
"description": "Coordinates of the warehouse with the product",
"$ref": "[url=http://json-schema.org/geo"]http://json-schema.org/geo"[/url]
}
},
"required": ["id", "name", "price"]
}
}


数组必须包含至少一个元素。 如何定义最小数组?

我需要添加最小定义吗?
已邀请:

石油百科

赞同来自:

要在数组中设置最小元素编号,请使用
"minItems"

.

看:

http://tools.ietf.org/html/dra ... 5.3.3


http://jsonary.com/documentati ... ation

{
"$schema": "[url=http://json-schema.org/draft-04/schema#"]http://json-schema.org/draft-04/schema#"[/url],
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
...
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"maxItems": 4,
"uniqueItems": true
}
},
"required": ["id", "name", "price"]
}

涵秋

赞同来自:

我相信,至少有,至少看工作草案,
minimum

仅适用于数值,而不是数组。

5.1. 检查数值实例的关键字 /number 和 integer/

...

http://tools.ietf.org/html/dra ... 5.1.3
所以你必须善于 min/maxItems 对于数组。

小姐请别说爱

赞同来自:

似乎这个项目 v4 允许您要找的内容。 从
http://json-schema.org/example1.html
:


{
"$schema": "[url=http://json-schema.org/draft-04/schema#"]http://json-schema.org/draft-04/schema#"[/url],
"title": "Product",
"description": "A product from Acme's catalog",
"type": "object",
"properties": {
...
"tags": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
},
"required": ["id", "name", "price"]
}


请注意,属性 "tags" 定义为具有最小项目数的数组 /1/.

要回复问题请先登录注册