$ref resolution in a $dynamicRef target ($dynamicAnchor) happening from base URI instead of target
還沒有人認領這個 Issue。
評估
研究方向
Run repro.py against the two schemas in base.schema.json and extension.schema.json to confirm the PointerToNowhere failure, then trace how referencing resolves the $ref: "#/$defs/B" written inside the extension's $dynamicAnchor target. The fix is to resolve that $ref against the resource the target is written in (the extension's $id) rather than the base schema, so "done" means the repro prints True then False without changing other resolution behaviour. This needs familiarity with JSON Schema 2020-12 dynamic scope and the resolver internals, so read the surrounding resolution code and existing dynamicRef tests before editing.
由索引模型根據 Issue 內容生成。
描述
referencing 0.37.0 resolves $refs inside a $dynamicRef target against the referring schema's base URI instead of the target's resource, contrary to JSON Schema 2020-12 §8.2.
8.2.3.1 "The value of the "$ref" keyword MUST be a string which is a URI-Reference. Resolved against the current URI base, it produces the URI of the schema to apply"
- The base URI for a $ref comes from the schema resource the $ref is written in, not from the path validation took to get there.
- The slot definition with "$ref": "#/$defs/B" is written inside the extension, so its base URI is the extension's $id.
- $dynamicRef decides which schema gets applied: the extension's definition. It doesn't change where that definition is written.
- So #/$defs/B should resolve inside the extension. referencing resolves it inside the base schema.
To reproduce:
Folder Layout
repro/
base.schema.json
extension.schema.json
repro.py
base.schema.json:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/base.schema.json",
"type": "object",
"allOf": [{ "$dynamicRef": "#ext" }],
"properties": {
"a": { "type": "integer" }
},
"unevaluatedProperties": false,
"$defs": {
"ext": { "$dynamicAnchor": "ext" }
}
}
extension.schema.json:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/schemas/extension.schema.json",
"$ref": "base.schema.json",
"$defs": {
"ext": {
"$dynamicAnchor": "ext",
"properties": {
"b": { "$ref": "#/$defs/B" }
}
},
"B": { "type": "string" }
}
}
repro.py:
import json
from pathlib import Path
from jsonschema import Draft202012Validator
from referencing import Registry, Resource
here = Path(__file__).parent
schemas = [json.loads((here / name).read_text()) for name in ("base.schema.json", "extension.schema.json")]
registry = Registry().with_resources((s["$id"], Resource.from_contents(s)) for s in schemas)
validator = Draft202012Validator(
{"$ref": "https://example.com/schemas/extension.schema.json"}, registry=registry
)
print(validator.is_valid({"a": 1, "b": "text"})) # expected: True
print(validator.is_valid({"a": 1, "b": 3})) # expected: False
Expected: True, then False
Actual (jsonschema 4.26.0 and referencing 0.37.0):
jsonschema.exceptions._WrappedReferencingError: PointerToNowhere: '/$defs/B' does not exist within
{'$schema': 'https://json-schema.org/draft/2020-12/schema', '$id': 'https://example.com/schemas/base.schema.json', ...}
- 主要語言
- Python
- 星號
- 56
- 分支
- 55
- 平均合併
- 5 天 22 小時
- 30 天內合併 PR
- 4
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python-jsonschema/referencing 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 75/100
python-jsonschema/referencing#444 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
python-jsonschema/referencing#434 ·
-
難度 4/5 3-5 天 新手友好度 52/100
python-jsonschema/referencing#442 ·
-
$dynamicRef doesn't find $dynamicAnchor overrides in root schemas without $id可能已有人在做 @aqeelat 於 174 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 45/100
python-jsonschema/referencing#366 ·
-
難度 4/5 3-5 天 新手友好度 35/100
python-jsonschema/referencing#257 ·
查看 python-jsonschema/referencing 的全部 Issue
相似的 Issue
-
難度 1/5 1-3 小時 新手友好度 78/100
web-push-libs/pywebpush#216 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 72/100
AgriciDaniel/claude-seo#572 ·
維護者通常 5 天內回覆
-
area:print-dispatch
難度 2/5 1-3 小時 新手友好度 92/100
維護者通常 1 天內回覆
-
area: docs domain: technical-writing good first issue type: documentation
難度 2/5 1-3 小時 新手友好度 80/100
Deepak3699/Ai_Mentor#919 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆