Python JSONSchema验证失败,带有$ref(草案v7)
我根据v7规范草案创建了一个JSON模式。架构如下所示:Python JSONSchema验证失败,带有$ref(草案v7),python,jsonschema,json-schema-validator,python-jsonschema,Python,Jsonschema,Json Schema Validator,Python Jsonschema,我根据v7规范草案创建了一个JSON模式。架构如下所示: { "type": "object", "properties": { "songs": { "type": "array", "items": { "type": "object", "properties": { "composition":
{
"type": "object",
"properties": {
"songs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"composition": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"publishing": {
"type": "array",
"items": {
"type": "object",
"required": ["publisherId","territory"],
"definitions": {
"categoryList": {
"type": "object",
"properties": {
"BR": {
"type": "number"
}
}
}
},
"properties": {
"publisherId": {
"type": "integer"
},
"territory": {
"$ref": "#/definitions/categoryList"
}
}
}
}
}
},
"recordings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"songVersion": {
"type": "string"
},
"album": {
"type": "object",
"properties": {
"title": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
但Get error无法解析架构引用“#/definitions/categoryList”。路径“properties.songs.items.properties.composition.properties.publishing.items.properties.territory”,第40行,位置24。如果我省略了定义部分,它将完美地工作解释为什么参考解决方案不能像您期望的那样工作的最简单方法是讨论draft-07核心规范本身的修改示例
{
"definitions": {
"A": { },
"B": {
"definitions": {
"X": { },
"Y": { }
}
}
}
}
文档根是具有定义
属性的对象
要访问#/definitions/A
,可以使用#/definitions/A
的引用
要访问#/definitions/B/definitions/X
,可以使用#/definitions/B/definitions/X
的参考
模式中的引用需要知道从文档根到子模式的完整路径
我猜您假设URI是相对于最近的子模式或它所使用的子模式的,但事实并非如此
参考:
该示例包括一组更详尽的示例。将URI引用想象成HTML中的锚标记。当URI的某个域部分不包含时,为了进行URI解析,“想象”一个域部分就在它的位置上
如果您有任何后续问题,请告诉我。根据您提供的参考,希望在根级别看到
定义。您的引用URI相对于文档根,而不是当前对象。“URI相对于文档根,而不是当前对象”-您能解释一下吗?