You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何正确引用外部JSON Schema?DNS工具Schema编译报错求助

问题解决方法

你的JSON Schema存在两处问题导致AJV编译报错,以下是修正方案:

1. 修复JSON语法错误

你在items字段中多嵌套了一层不必要的大括号,正确写法应直接将$ref放在items的对象内,无需额外包裹:

修正后的dns-tool.schema.json代码:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "dns-tool.schema.json",
  "title": "Zone Config Schema",
  "type": "object",
  "properties": {
    "records": {
      "type": "array",
      "items": {
        "$ref": "dns-record.schema.json"
      }
    }
  }
}

2. 解决AJV的引用解析问题

即使修复语法,AJV仍可能无法自动识别同目录下的依赖Schema,你需要在编译命令中通过-r参数显式指定要加载的引用文件:

ajv compile --verbose true -s dns-tool.schema.json -r dns-record.schema.json

如果不想每次编译都手动指定依赖,也可以给dns-record.schema.json设置一个内部片段ID(比如"$id": "#dns-record"),然后在主Schema中用"$ref": "#dns-record"引用,但显式通过-r加载依赖是更直接的方案。

内容的提问来源于stack exchange,提问作者Tom

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 11:29:56