【发布时间】:2015-06-29 03:15:12
【问题描述】:
以下是我的 JSON 架构的摘录。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"images": {
"type": "array",
"items": { "$ref": "#/definitions/bits" },
}
},
"definitions": {
"identifier": {
"type": "string"
},
"bits": {
"type": "integer",
"enum": [
8,
16,
32
]
}
}
}
按照说明,我相信一个图像数组,其中每个元素由一个字符串标识符和一个整数组成,其值可以是 8、16 或 32,将被视为有效的 JSON 数据。
这对我的一些 JSON 数据来说很好。
但是,如果我想进一步限制模式,使整数值只能是 32,该怎么办?我将如何做到这一点,同时仍然允许一些 JSON 数据对原始模式有效?
是否有可能,例如,在一个对象中引用两个模式,例如类似:
items": { "$ref": "#/definitions/bits" AND "$ref": "#/definitions/otherSchema"}
【问题讨论】:
标签: json schema jsonschema