【发布时间】:2018-05-11 20:55:58
【问题描述】:
我正在使用 YAML 来标记一些公式并使用 JSON 模式来提供参考模式。 YAML 的一个示例可能是:
formula: # equates to '5 + (3 - 2)'
add:
- 5
- subtract: [3, 2]
虽然我已经弄清楚如何使公式的直接子对象(本例中为 "add")具有正确的键名和类型(使用 "required"s 的 "oneOf"array)。我不确定如何确保数组的对象 ("subtract") 同样使用特定的键名。
到目前为止,我可以使用以下方法确保类型。但是使用这种方法,只要使用的对象匹配减法type,就可以任意键名,不限于subtract:
"definitions: {
"add": {
"type": "array",
"minItems": 2,
"items": {
"anyOf": [
{ "$ref": "#/definitions/value"}, # value type is an integer which allows for the shown scalar array elements
{ "$ref": "#/definitions/subtract" }
// other operation types
]
}
},
"subtract": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"anyOf": [
{ "$ref": "#/definitions/value"},
{ "$ref": "#/definitions/add" }
// other operation types
]
}
}
// other operation types
}
如何引入限制,使数组中对象的键匹配特定名称,同时仍然允许标量元素?
【问题讨论】:
标签: yaml jsonschema