【发布时间】:2016-09-22 07:48:07
【问题描述】:
我有这个用于 json 响应的架构
{
"title": "Products",
"description": "schema for products",
"type": "array",
"properties": {
"id": {
"description": "id of a product",
"type": "integer"
},
"name": {
"description": "name of the product",
"type": "string"
},
"created_at": {
"description": "record created_at",
"type": "string",
"format": "date-time"
},
"updated_at": {
"description": "record updated_at",
"type": "string",
"format": "date-time"
}
},
"required": ["id", "name"]
}
我想将此架构与此 json 匹配
[{
"id": 1,
"name": "Cricket Ball"
}, {
"id": 2,
"name": "Soccer Ball"
}, {
"id": 3,
"name": "football ball"
}, {
"id": 4,
"name": "Basketball ball"
}, {
"id": 5,
"name": "Table Tennis ball"
}, {
"id": 6,
"name": "Tennis ball"
}]
此架构与响应匹配,但它也与必填字段为 this 的架构匹配
"required": ["ids", "names"]
我认为架构已针对数组进行验证,而数组中的对象未经过验证。
【问题讨论】:
-
不清楚您实际在做什么。包括控制器和视图(如果您使用 jbuilder)或序列化程序(如果您使用 AMS)。
-
这与 Rails 无关。在最近的编辑中删除了 rails 标签
标签: arrays json jsonschema