Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
json模式(draft7)实现应该如何解析未知关键字中定义的“$ref”?_Json_Schema_Jsonschema - Fatal编程技术网

json模式(draft7)实现应该如何解析未知关键字中定义的“$ref”?

json模式(draft7)实现应该如何解析未知关键字中定义的“$ref”?,json,schema,jsonschema,Json,Schema,Jsonschema,JSON模式测试套件定义了这样的模式,我假设它们是有效的: { "tilda~field": {"type": "integer"}, "slash/field": {"type": "integer"}, "percent%field": {"type": "integer"}, "properties": { "tilda": {"$ref": "#/tilda~0field"}, "slash": {"$ref": "#/sl

JSON模式测试套件定义了这样的模式,我假设它们是有效的:

{
    "tilda~field": {"type": "integer"},
    "slash/field": {"type": "integer"},
    "percent%field": {"type": "integer"},
    "properties": {
        "tilda": {"$ref": "#/tilda~0field"},
        "slash": {"$ref": "#/slash~1field"},
        "percent": {"$ref": "#/percent%25field"}
    }
}
以下面这个例子为例:

{
    "$id": "http://example.com/root.json",
    "definitions": {
        "A": { "type": "integer" }
    },
    "properties": {
        "$id": {
            "type": "string"
        },
        "attributes": {
            "$ref": "#/tilda~0field/slash~1field/$id"
        }
    },
    "tilda~field": {
        "$id": "t/inner.json",
        "slash/field": {
            "$id": {
                "$id": "test/b",
                "$ref": "document.json"
            }
        }
    }
}
#/tilda~0field/slash~1field/$id/$ref
中,
$ref
解析为以下哪项


#/tilda~0field
中的
$id
中的哪一个必须被视为所讨论的
$ref
的baseURI,以及原因。

您确定您的第二个架构有效吗

例如,根据,
$id
属性应该是字符串

如果存在,此关键字的值必须是字符串

因此,我认为以下几点是错误的:

"slash/field": {
  "$id": {
      "$id": "test/b",
      "$ref": "document.json"
  }
}
那么我认为您的第一个
$ref
也不正确:

"attributes": {
  "$ref": "#/tilda~0field/slash~1field/$id"
}
它大概应该是这样的:

"attributes": {
  "$ref": "#/tilda~0field/slash~1field"
}
同样的规范文档也提到了
$id
$ref
: 碳纤维

“$id”关键字定义了架构的URI,以及架构中其他URI引用的基础URI

或者简单地说:

$ref被解析为uri引用,使用模式$id作为基本uri[…]


考虑到您的模式的当前状态,我只能大致回答您的问题,但是ref可能会解析为类似于
t/inner.json\document.json

的内容,但是您确定您的第二个模式有效吗

例如,根据,
$id
属性应该是字符串

如果存在,此关键字的值必须是字符串

因此,我认为以下几点是错误的:

"slash/field": {
  "$id": {
      "$id": "test/b",
      "$ref": "document.json"
  }
}
那么我认为您的第一个
$ref
也不正确:

"attributes": {
  "$ref": "#/tilda~0field/slash~1field/$id"
}
它大概应该是这样的:

"attributes": {
  "$ref": "#/tilda~0field/slash~1field"
}
同样的规范文档也提到了
$id
$ref
: 碳纤维

“$id”关键字定义了架构的URI,以及架构中其他URI引用的基础URI

或者简单地说:

$ref被解析为uri引用,使用模式$id作为基本uri[…]


考虑到您的模式的当前状态,我只能大致回答您的问题,但ref可能会解析为类似于
t/inner.json#document.json

我刚刚在json模式网站上看到您的问题。我也会在这里发布我在那里发布的内容。但是,也可以查看编辑


#/tilda~0field/slash~1field/$id/$ref
中,
$ref
解析为以下哪项

我想答案是:“子模式的“$id”是根据其父模式的基本URI解析的。”这意味着它将是

#/tilda~0字段
中的
$id
中的哪一个必须被视为相关
$ref
的baseURI,以及原因

此操作的基本URI是根目录下的
$id
,由
tilda~字段中的
$id
重新路由

  • http://example.com/root.json
  • 将文件夹更改为
    t
    并使用文件
    inner.json
  • 将文件夹更改为
    test
    (在
    t
    内)并使用file
    document.json

  • 编辑


    查看@customcommander的回复,并意识到
    tilde~字段中的值没有作为模式处理,我想说
    #ref
    根本不会被处理。它只是一个简单的JSON字符串,没有固有的含义。

    我刚刚在JSON模式网站上看到了您的问题。我也会在这里发布我在那里发布的内容。但是,也可以查看编辑


    #/tilda~0field/slash~1field/$id/$ref
    中,
    $ref
    解析为以下哪项

    我想答案是:“子模式的“$id”是根据其父模式的基本URI解析的。”这意味着它将是

    #/tilda~0字段
    中的
    $id
    中的哪一个必须被视为相关
    $ref
    的baseURI,以及原因

    此操作的基本URI是根目录下的
    $id
    ,由
    tilda~字段中的
    $id
    重新路由

  • http://example.com/root.json
  • 将文件夹更改为
    t
    并使用文件
    inner.json
  • 将文件夹更改为
    test
    (在
    t
    内)并使用file
    document.json

  • 编辑

    查看@customcommander的回复,并意识到
    tilde~字段中的值没有作为模式处理,我想说
    #ref
    根本不会被处理。它只是一个简单的JSON字符串,没有固有的含义。

    $ref
    不会在未知关键字中解析,因为
    $ref
    $id
    仅应用于架构内部。让我们看一个例子来了解我的意思

    {
      "$id": "http://example.com/foo",
      "type": "object",
      "properties": {
        "aaa": {
          "const": { "$ref": "#/definitions/bbb" }
        },
        "bbb": { "$ref": "#/definitions/bbb" }
      },
      "ccc": { "$ref": "#/definitions/bbb" },
      "definitions": {
        "bbb": { "type": "string" }
      }
    }
    
    • 文档作为一个整体是一个模式,因此JSON模式可以理解
      /$id
    • properties
      关键字定义为值为模式的对象。因此,
      /properties/bbb
      处的值是一个模式,
      /properties/bbb/$ref
      由JSON模式理解
    • const
      关键字的值不受约束。
      /properties/aaa/const
      处的值可能看起来像一个模式,但它只是一个普通的JSON对象。因此,JSON模式不理解
      /properties/aaa/const/$ref
    • /ccc
      处的值不是JSON模式关键字,因此它的值不受约束,也不是模式。因此,JSON模式不理解
      $id
      $ref
      关键字

    这就是它现在的工作原理。当你回到旧的草案(草案05 iirc),它有点不同。在此之前,
    $ref
    被取消