Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

$dynamicRef doesn't find $dynamicAnchor overrides in root schemas without $id

オープン
#1,497 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python

調査の方向性

reproducer 内の Draft202012Validator のセットアップと Registry/Resource の登録から始め、次に $id のないルートスキーマが $ref を通じてどのように解決され、$dynamicRef がどのように自身の anchor を見つけるかを追跡します。iter_errors の失敗を再現し、合成 $id を追加せずにルートの $defs override が尊重されれば issue は完了とします。

索引モデルが issue の本文から書いたものです。

説明

$dynamicRef doesn't find $dynamicAnchor overrides in root schemas without $id

When a root schema has no $id and uses $ref to pull in a template containing $dynamicRef, the $dynamicRef ignores any $dynamicAnchor overrides defined in the root schema's $defs. It falls back to the template's own $dynamicAnchor instead.

Minimal reproducer

from jsonschema import Draft202012Validator
from referencing import Registry, Resource
from referencing.jsonschema import DRAFT202012

template = {
    "$id": "https://example.com/PaginatedTemplate",
    "$defs": {"itemType": {"$dynamicAnchor": "itemType", "not": {}}},
    "type": "object",
    "required": ["items"],
    "properties": {"items": {"type": "array", "items": {"$dynamicRef": "#itemType"}}}
}

schema = {
    "$defs": {"itemType": {"$dynamicAnchor": "itemType", "type": "string"}},
    "$ref": "https://example.com/PaginatedTemplate"
}

registry = Registry().with_resource(
    "https://example.com/PaginatedTemplate",
    Resource.from_contents(template, default_specification=DRAFT202012)
)

# Should pass — "hello" matches the override (type: string)
# Actually fails — $dynamicRef resolves to the template's not: {} instead
v = Draft202012Validator(schema, registry=registry)
assert not list(v.iter_errors({"items": ["hello"]}))  # fails

Adding $id to the root schema makes it work:

schema["$id"] = "https://example.com/Bound"
# ... then register and validate — passes

Workaround

Add a synthetic $id to the root schema before creating the validator.

主要言語
Python
スター
5k
フォーク
694
平均マージ
1日 20時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-jsonschema/jsonschema のほかの issue

python-jsonschema/jsonschema の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。