2
我试图定义一个引用的模式以用作具有文本字段的Cassandra CQL地图类型。具体来说,我想将URI映射到字符串。使用json-schema v4定义地图类型
现在我有:
"scope": {
"type": "object",
"properties": {
"uri": {
"type": "string",
"format": "uri"
},
"permission": {
"type": "string",
"enum": ["read_only", "read_write", "write_only"]
}
},
"required": ["uri", "permission"],
"additionalProperties": false
}
这有利于像
{"uri":"http://example.com",
"permission": "read_only"}
数据,但我要像
{"http://example.com": "read_only"}
http://spacetelescope.github.io/understanding-json-schema/reference/object.html数据的模式有一个解决方案:
{
"type": "object",
"patternProperties": {
"^S_": { "type": "string" },
"^I_": { "type": "integer" }
}
}
这个问题是,我不得不定义一个正则表达式的内置格式。看看URI的正则表达式的例子让我想避免这种情况。
由于我拥有的URI数量有限,因此将枚举映射到enum也是一个解决方案。这是可行的吗?