【发布时间】:2017-11-18 13:41:18
【问题描述】:
我正在尝试使用 www.hl7.org/fhir/json.html 中定义的 JSON 架构,例如 www.hl7.org/fhir/Patient.schema.json。
架构开始于:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://hl7.org/fhir/json-schema/Patient",
"$ref": "#/definitions/Patient",
"description": "see http://hl7.org/fhir/json.html#schema for information
about the FHIR Json Schemas",
"definitions": {
"Patient": {
"allOf": [
{
"$ref": "DomainResource#/definitions/DomainResource"
},
当我将其粘贴到 [www.jsonschemavalidator.net][3] 时,我收到错误消息
解析架构引用“#/definitions/Patient”时出错。路径'',第 1 行,位置 1。
如果我将第 4 行 ("$ref": "#/definitions/Patient") 移到“Patient”定义中,架构解析错误将得到修复,并且我可以正确验证一些示例 JSON 数据。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://hl7.org/fhir/json-schema/Patient",
"description": "see http://hl7.org/fhir/json.html#schema for information
about the FHIR Json Schemas",
"definitions": {
"Patient": {
"$ref": "#/definitions/Patient",
"allOf": [
{
"$ref": "DomainResource#/definitions/DomainResource"
},
但是,我注意到http://hl7.org/fhir/json.html 定义的每个 JSON 模式都是以这种方式构造的。是 HL7 JSON 模式中的错误,还是 www.jsonschemavalidator.net 解析这些 JSON 模式的方式?
我对 $ref 的理解是 "$ref": "#/definitions/Patient" 会查看 baseURL 的最近父 id,在这种情况下是:
“hl7.org/fhir/json-schema/Patient”。
这个 URL 应该提供 www.hl7.org/fhir/Patient.schema.json,它从根元素开始,应该有一个模式元素 #/definitions/Patient 对应于定义 $ref 的当前元素。因此,$ref 的正确位置似乎确实应该在 #/definitions/Patient 内,而不是在 ref 当前所在的上根 #/ 位置。
【问题讨论】:
-
在此处查看相关对话:gitter.im/ajv-validator/ajv?at=58f484c208c00c092a8a5787 - 虽然不确定这是同一个问题
-
我不像你那样阅读 json 模式规范。我认为模式是正确的。您对模式的“更正”意味着任何 json 都是有效的
-
我正在跟进groups.google.com/forum/#!forum/json-schema。随意加入那里
标签: json jsonschema hl7 json-schema-validator