我对UI的后端API响应如下JSON,其中某些对象中的$ref
指向同一JSON 中的内部obj$defs
{
"schema": {
"type": "object",
"properties": {
"mongodb.name": {
"title": "Namespace",
"description": "Unique name",
"type": "string",
"x-name": "mongodb.name",
"x-category": "CONNECTION"
},
"mongodb.hosts": {
"title": "Hosts",
"description": "The hostname",
"type": "string",
"x-name": "mongodb.hosts",
"x-category": "CONNECTION"
},
"data_shape": {
"type": "object",
"additionalProperties": false,
"properties": {
"key": {
"title": "some data",
"description": "xxx",
"x-name": "mongodb.hosts",
"x-category": "CONNECTION",
"$ref": "#/$defs/serializer"
},
"value": {
"title": "some data",
"description": "xxx",
"x-name": "mongodb.hosts",
"x-category": "CONNECTION",
"$ref": "#/$defs/serializer"
}
}
}
},
"$defs": {
"serializer": {
"type": "string",
"enum": [
"JSON",
"AVRO",
],
"default": "JSON"
}
}
}
}
我正试着用这个https://www.npmjs.com/package/@stoplight/json-ref-resolver npm pkg解析$ref
,但它工作不正常,并删除了title
、description
等同级字段。
对于更新的2019-09草案及更高版本,是否还有其他npm pkg可以正确处理它?
在该包的变更日志中,我没有看到任何关于支持JSONSchema draft2019-09或更高版本的内容,这是能够处理$ref
旁边的兄弟关键字所必需的。在draft7及之前的版本中,$ref
只能单独出现在子模式中,而不能与任何其他关键字(如title
(一起出现。