$ref resolution in a $dynamicRef target ($dynamicAnchor) happening from base URI instead of target
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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', ...}
- Ngôn ngữ chính
- Python
- Star
- 56
- Fork
- 55
- Merge trung bình
- 5 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python-jsonschema/referencing
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
python-jsonschema/referencing#444 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
python-jsonschema/referencing#434 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
python-jsonschema/referencing#442 ·
-
$dynamicRef doesn't find $dynamicAnchor overrides in root schemas without $idCó thể đã có người làm @aqeelat đã nhận 174 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
python-jsonschema/referencing#366 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
python-jsonschema/referencing#257 ·
Tất cả issue của python-jsonschema/referencing
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
web-push-libs/pywebpush#216 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AgriciDaniel/claude-seo#572 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
area:print-dispatch
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: docs domain: technical-writing good first issue type: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Deepak3699/Ai_Mentor#919 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày