我正在尝试为我的用例构造一个JSON模式,其中我在单独的文件中具有字符串的枚举,并希望从我的模式中引用它。我该如何实现。
样本架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"card": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"value": {
"type": "string",
"enum": {"$ref" : "reference to a file having list of enums"}
//I want to refer to a specific enum array (say value1's array)
}
}
}
},
"required": [
"card"
]
}
枚举文件类似于:
{
"value1": [..],
"value2": [..]
....
}
$ref
应该仅用于引用架构。因此,您可以做这样的事情。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"card": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"value": { "$ref" : "/schemas/valueEnum.json" }
}
}
},
"required": ["card"]
}
/schemas/valueEnum.json
{ "enum": ["foo", "bar"] }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句