基本 URL 如何使用 JSON 模式更改纯名称片段解析?
How does the base URL change plain name fragment resolution with JSON Schema?
摘自http://json-schema.org/draft-07/json-schema-core.html#rfc.section.8.2.4
{
"$id": "http://example.com/root.json",
"definitions": {
"A": { "$id": "#foo" },
"B": {
"$id": "other.json",
"definitions": {
"X": { "$id": "#bar" },
"Y": { "$id": "t/inner.json" }
}
},
"C": {
"$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
}
}
}
The schemas at the following URI-encoded JSON Pointers [RFC6901]
(relative to the root schema) have the following base URIs, and are
identifiable by any listed URI in accordance with Section 5 above:
...
#/definitions/B/definitions/X
http://example.com/other.json#bar
http://example.com/other.json#/definitions/X
http://example.com/root.json#/definitions/B/definitions/X
...
为什么 http://example.com/root.json#bar 不是 #/definitions/B/definitions/X 的有效基础 URI?
http://example.com/root.json#bar
无法使用给定的架构解析。
可以把它想象成 HTML 中的锚点。
$id
就像定义一个新页面,因此 #/definitions/B
的位置属于 "the page" $other.json
,因此您包含的列表中的 http://example.com/other.json#bar
与 #/definitions/B/definitions/X
.
如果您创建位于 http://example.com/root.json
的 HTML 页面,并尝试单击位于 #bar
的 link,它将找不到 # 位置,因为它在 other.json
页面上。
如果其中任何内容没有意义或令人困惑,请告诉我。
摘自http://json-schema.org/draft-07/json-schema-core.html#rfc.section.8.2.4
{
"$id": "http://example.com/root.json",
"definitions": {
"A": { "$id": "#foo" },
"B": {
"$id": "other.json",
"definitions": {
"X": { "$id": "#bar" },
"Y": { "$id": "t/inner.json" }
}
},
"C": {
"$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f"
}
}
}
The schemas at the following URI-encoded JSON Pointers [RFC6901] (relative to the root schema) have the following base URIs, and are identifiable by any listed URI in accordance with Section 5 above:
...
#/definitions/B/definitions/X
http://example.com/other.json#bar
http://example.com/other.json#/definitions/X
http://example.com/root.json#/definitions/B/definitions/X
...
为什么 http://example.com/root.json#bar 不是 #/definitions/B/definitions/X 的有效基础 URI?
http://example.com/root.json#bar
无法使用给定的架构解析。
可以把它想象成 HTML 中的锚点。
$id
就像定义一个新页面,因此 #/definitions/B
的位置属于 "the page" $other.json
,因此您包含的列表中的 http://example.com/other.json#bar
与 #/definitions/B/definitions/X
.
如果您创建位于 http://example.com/root.json
的 HTML 页面,并尝试单击位于 #bar
的 link,它将找不到 # 位置,因为它在 other.json
页面上。
如果其中任何内容没有意义或令人困惑,请告诉我。