jsonschema - 基本 URL 如何使用 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"
}
}
}
以下 URI 编码的 JSON 指针 [RFC6901](相对于根模式)中的模式具有以下基本 URI,并且可以根据上面的第 5 节由任何列出的 URI 识别:
...
#/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
位于“页面”下$other.json
,因此http://example.com/other.json#bar
在您包含的列表中与#/definitions/B/definitions/X
.
如果您创建一个位于 的 HTML 页面http://example.com/root.json
,并尝试单击位于 的链接#bar
,它将找不到 # 位置,因为它在other.json
页面上。
如果其中任何一个没有意义或令人困惑,请告诉我。
推荐阅读
- html - Colspan 适用于某些组合,但不适用于其他组合
- reactjs - JSX 元素上的严格空值检查 Typescript 错误
- sql - 获取按 ID 分组的最新条目
- cmake - CMakeLists.txt:7 (PROJECT) 处的 CMake 错误:无法运行 MSBuild 命令:
- r - 无法下载 ggplot 2,因为未指定“lib”
- php - 如何获取请求第一个值并将整个字符串分成两部分?
- python-3.x - tf.data.Dataset batch 和 map 和 tf.contrib.data.map_and_batch 的区别
- reactjs - 当它进入 Object.map 时,“this”会发生什么
- python - 构建器问题。我尝试为android制作apk文件,但我不能
- ios - 如何将单元格添加到 UITableView 部分并保存核心数据信息