JSON 架构 - 外键 (FK) 验证

JSON Schema - Foreign Key (FK) Validation

我有以下 JSON 模式:

架构 A:

{
  "$schema": "http://json-schema.org/draft-04/hyper-schema#",
  "title": "A",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "entityBId": {
      "type": "string"
    }
  },
  "required": [
    "name",
    "entityBId"
  ],
  "links": [
    {
      "rel": "B",
      "href": "myapi/EntityB?id={entityBId}"
    }
  ]
}

架构 B :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "B",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    }
  },
  "required": [
    "name"
  ]
}

我想弄清楚是否有办法 运行 类似于基于 JSON 外部架构的完整性检查 links/references。 例如:当我收到一个 entityBId = 1 的对象 A 时,我想在链接 href 中声明的端点中获取此实体 B 运行ning GET并检查接收到的 ID 中是否存在有效对象。 它将 运行 类似于深度验证,并且在没有定义数据库架构的情况下很有用。

根据 Raj Kamal 的建议,我自己制作了 "link validation"。 有一个函数在模式上查找 link 属性并直接在数据库上验证外部引用,如果未找到有效引用则抛出异常。