小编Skv*_*upp的帖子

在同一文档中引用 $id 时如何修复“无法解析引用”错误?

我想使用 JavaScript 中的 Ajv 根据 JSON 模式验证 JSON。我收到错误:

抛出新的 it.MissingRefError(it.baseId, $schema, $message); ^ 错误:无法从 id requestGetGraphs 解析引用 #/definitions/requestGraph

删除对其他架构的引用时: { "$ref" : "#/definitions/requestGraph" } 错误消失。

JavaScript 代码:

ajv.addSchema(require('./json-schema/graph-response'), 'graph-response.json');
ajv.validate('requestGetGraphs', `{"type" : "requestGetGraphs", "space" : "config", "v" : 1.1, "id" : "dsaf" }`);
Run Code Online (Sandbox Code Playgroud)

图请求.json:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id" : "graph-requests.json",
  "definitions": {
    "requestGraph" : {
      "$id" : "#/definitions/requestGraph",
      "allOf" : [
        { "$ref" : "call.json/#/definitions/request" },
        {
          "properties": {
            "space": {
              "$id" : "#requestGraph/properties/space",
              "type": "string",
              "const": "config"
            }
          } …
Run Code Online (Sandbox Code Playgroud)

javascript jsonschema ajv

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

ajv ×1

javascript ×1

jsonschema ×1