【发布时间】:2021-12-01 21:54:57
【问题描述】:
正在验证的文件如下所示:
MyArray:
- someItemWithRandomName:
one: f9jfw9j302
two: 09dj0293jff
three: 09dj0293jff
- someOtherItemWithRandomName:
one: f9jfw9j302
two: 09dj0293jff
three: 09dj0293jff
- anotherItem:
one: f9jfw9j302
two: 09dj0293jff
three: 09dj0293jff
我正在这样验证它:
"MyArray": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [
"one",
"two",
"three"
],
"properties": {
"one": {
"type": "string"
},
"two": {
"type": "string"
},
"three": {
"type": "string"
}
}
}
我不想允许未在架构中定义的数组项中的字段,但 "additionalProperties": false 不起作用,因为数组项的键可以是任何字符串。你如何适应这个?
编辑
这是我验证的一个活生生的例子。在验证之前,我假设的 YAML 将像本示例中一样转换为 JSON:https://www.jsonschemavalidator.net/s/PBmLkkBl
【问题讨论】:
-
根据您的描述,您所拥有的应该可以工作。您能否发布一个当前不应该通过的数据示例?
标签: jsonschema