Question about validators across $refs
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
報告されている outer.json、nested.json、script から始め、その後 jsonschema 4.9.1 と 4.10.0 に対して比較を実行してください。$ref をまたいでカスタム Draft4 バリデーターがどのように選択されるかを追跡し、$schema を削除せずに以前のデフォルト値の補完動作を維持できるかどうかを記録してください。
索引モデルが issue の本文から書いたものです。
説明
Hi, I have a question regarding the change in 4.10.0 and the default filling custom validator suggested here.
Before this version, I could use this enhanced validator to fill in default values even across "$ref"s to different schema.
But 4.10.0 added support "for referencing schemas with $ref across different versions of the specification", which means that now the validator is determined dynamically based on the "$schema" and the custom one is not used for the referred schema.
Here is an example:
outer:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"count": {
"default": 0,
"type": "integer"
},
"nested": {
"$ref": "file://nested.json"
}
}
}
nested:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"nestedcount": {
"default": 0,
"type": "integer"
},
"name": {
"type": "string"
}
}
}
script:
import copy
import json
import jsonschema
def extend_with_default(validator_class):
validate_properties = validator_class.VALIDATORS["properties"]
def set_defaults(validator, properties, instance, schema):
for property, subschema in properties.items():
if "default" in subschema:
instance.setdefault(property, subschema["default"])
for error in validate_properties(
validator, properties, instance, schema,
):
yield error
return jsonschema.validators.extend(
validator_class, {"properties" : set_defaults},
)
Draft4ValidatorWithDefaults = extend_with_default(jsonschema.Draft4Validator)
def load_schema(uri):
with open(uri.removeprefix("file://")) as ifile:
return json.load(ifile)
schema = load_schema("outer.json")
resolver = jsonschema.RefResolver(
"outer.json", schema,
handlers={"file": load_schema})
validator_with_defaults = Draft4ValidatorWithDefaults(schema, resolver=resolver)
validator = jsonschema.Draft4Validator(schema, resolver=resolver)
content = {
"nested": {"name": "foo"}
}
print(jsonschema.__version__)
validator.validate(content)
print(content)
validator_with_defaults.validate(content)
print(content)
When I run this with jsonschema 4.9.1, I get:
4.9.1
{'nested': {'name': 'foo'}}
{'nested': {'name': 'foo', 'nestedcount': 0}, 'count': 0}
when I use 4.10.0, it looks like this:
4.10.0
{'nested': {'name': 'foo'}}
{'nested': {'name': 'foo'}, 'count': 0}
My question is, is there a way to revert to the previous behavior? I found out that when I delete the "$schema" key from the referred schema, it works as before, but that doesn't seem exactly nice (and I am not sure that won't cause other issues)...
- 主要言語
- Python
- スター
- 5k
- フォーク
- 700
- 平均マージ
- 1日 20時間
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-jsonschema/jsonschema のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
python-jsonschema/jsonschema#1588 · コメント 2 件 ·
-
Iterator error contexts lose parent links and absolute paths再び着手できるかも @DawnofGenX が 10 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
python-jsonschema/jsonschema#1584 · コメント 3 件 ·
-
regex format checker crashes with RecursionError on deeply nested patterns対応中かも @DawnofGenX が 10 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-jsonschema/jsonschema#1538 · コメント 1 件 ·
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponent再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンNeeds Test Upstream
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-jsonschema/jsonschema#1511 · コメント 1 件 ·
-
regex format checker crashes with ValueError on conflicting inline flags対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
python-jsonschema/jsonschema#1558 · コメント 2 件 ·
python-jsonschema/jsonschema の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
jbacalso24/mimry#291 ·
メンテナーはふだん 1 日以内に返信
-
good first issue
難易度 2/5 1時間未満 初心者へのやさしさ 82/100
eli-alvarado/us-watchlist-alerts#14 ·
メンテナーはふだん 1 日以内に返信
-
from-review-extraction python severity:nit
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
LearningCircuit/local-deep-research#7462 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
cathrynlavery/diagram-design#441 ·
メンテナーはふだん 2 日以内に返信
-
[Cleanup] Include the public header in work_split.cpp対応中かも @blozano-tt が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
tenstorrent/tt-metal#60850 ·
メンテナーはふだん 1 日以内に返信