【发布时间】:2020-02-28 11:57:08
【问题描述】:
我正在尝试指定一个必须包含特定属性的字符串数组。
我想指定验证所需的项目。
在此示例中:uuid、模板、createdOn、updatedOn。它必须是一个字符串数组。
我的架构如下所示:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "56544e3c-e197-4602-8457-2c01dc6b12c5",
"title": "The Root Schema",
"type": "object",
"additionalProperties": false,
"required": ["attributes"],
"properties": {
"attributes": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"enum": ["uuid", "template", "createdOn", "updatedOn", "fields", "elements"]
},
}
}
}
并且应该对此进行验证:
{
"attributes": ["uuid", "template", "createdOn", "updatedOn"],
},
{
"attributes": ["uuid", "template", "createdOn", "updatedOn", "fields", "elements"],
}
但这不是因为缺少项目“updatedOn”:
{
"attributes": ["uuid", "template", "createdOn", "fields", "elements"],
}
我已经尝试了很多都没有成功。谁能给个提示?
【问题讨论】:
-
尝试将
minItems: 6和maxItems: 6与uniqueItems一起使用,在此处查看更多文档docs.mongodb.com/stitch/mongodb/document-schemas/#arrays
标签: json jsonschema json-schema-validator