有没有办法在JSON模式中将数组定义为非空?
答案 0 :(得分:2)
正如您在网站http://json-schema.org/example2.html上看到的那样:
{
"id": "http://some.site.somewhere/entry-schema#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "schema for an fstab entry",
"type": "object",
"properties": {
"options": {
"type": "array",
"minItems": 1, // -> array must not be empty
"items": { "type": "string" },
"uniqueItems": true
},
"readonly": { "type": "boolean" }
}
}
您可以使用"minItems": 1