确保对象字段的值存在于Json Schema的另一个字段中 [英] Make sure object field has value existing in another field in Json Schema

查看:366
本文介绍了确保对象字段的值存在于Json Schema的另一个字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试表达对象及其之间的关系. 每个对象都有一个ID,每个关系都引用2个对象ID. 我想确保每个关系都引用现有的对象ID.您可以使用Json Schema做到这一点吗?

I am trying to express objects and relationships between them. Every object has an ID and every relationship references 2 object ids. I'd like to make sure every relationship references existing object ids. Could you do this with 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模式执行此操作.抱歉.

No you cannot do this with JSON Schema. Sorry.

听起来这是一个数据库. 您应该考虑使用数据库级别的约束进行这种验证.

It sounds like this is a database. You should consider using database level constraints for this sort of validation.

这篇关于确保对象字段的值存在于Json Schema的另一个字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆