我想弄清楚如何在我的json-schema數組對象上設置required
。所需的屬性在一個對象上正常工作,而不是一個數組。json-schema數組所需的設置
這裏是我的JSON模式的項目部分:
"items": {
"type": "array",
"properties": {
"item_id": {"type" : "number"},
"quantity": {"type": "number"},
"price": {"type" : "decimal"},
"title": {"type": "string"},
"description": {"type": "string"}
},
"required": ["item_id","quantity","price","title","description"],
"additionalProperties" : false
}
這裏是JSON數組我送過來。 json驗證應該失敗,因爲我沒有在這些項目中傳遞說明。
"items": [
{
"item_id": 1,
"quantity": 3,
"price": 30,
"title": "item1 new name"
},
{
"item_id": 1,
"quantity": 16,
"price": 30,
"title": "Test Two"
}
]
json-schema.org似乎在使用v4。 – ipengineer