我试图表达物体以及它们之间的关系。
每个对象都有一个 ID,每个关系引用 2 个对象 ID。
我想确保每个关系都引用现有的对象 ID。你能用 Json Schema 做到这一点吗?
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"Objects": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
}
},
"Relations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"objId1": {"type": "integer"}, // I'd like these
"objId2": {"type": "integer"} // Two fields to reference an existing Objects.id
}
}
},
},
}
不,您不能使用 JSON Schema 执行此操作。对不起。
听起来这是一个数据库。
您应该考虑使用数据库级别约束进行此类验证。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)