0

我有以下 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 Schema 的完整性检查之类的东西。例如:当我收到entityBId = 1 的对象 A 时,我想在链接 href 中声明的端点中获取运行 GET 的实体 B,并检查接收到的 id 中是否存在有效对象。它将像深度验证一样运行,并且在没有定义数据库模式的场景中很有用。

4

1 回答 1

0

正如 Raj Kamal 所建议的,我做了自己的“链接验证”。有一个函数可以在模式上查找链接属性并直接在数据库上验证外部引用,如果找不到有效引用则抛出异常。

于 2016-01-13T02:04:09.540 回答