4

我正在尝试使用从另一个 json 模式导入定义,$ref但出现以下错误:

can't resolve reference ../base/definitions.schema.json#/definitions/datetime from id #

{
  "$schema": "http://json-schema.org/draft-06/schema#",

  “定义”:{
    “约会时间”: {
      “类型”:“字符串”
    },
    “姓名”: {
      “类型”:“字符串”
    },
  }
}

{
  "$schema": "http://json-schema.org/draft-06/schema#",
  “特性”: {
    “活动”:{“类型”:“布尔”},
    "created_at": { "$ref": "../base/definitions.schema.json#/definitions/datetime" },
    “名称”:{“$ref”:“../base/base/definitions.schema.json#/definitions/name”},
    “updated_at”:{“$ref”:“../base/definitions.schema.json#/definitions/datetime”}
  },
  “必需”:[“名称”],
  “类型”:“对象”
}

目录结构:

api
-  根据
  -- 定义.schema.json
-  国家
  --国家.schema.json

我通过使用绝对路径、fileurl 和其他几种路径组合尝试了几种组合。不知道发生了什么。

模式验证器:ajv@5.1.1

4

1 回答 1

7

您需要使用“addSchema”方法添加模式。$ref 是相对于“id”属性(draft-06 中的“$id”)解析的,ajv 不(也不能)使用文件路径。

编辑:将 $ref 部分添加到docs

于 2017-09-24T19:19:25.297 回答