Error resolving sub-schema property with type object or array

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

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

  • #116 @Kaiserunix による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
testing

調査の方向性

Start by reproducing the supplied schema with hypothesis==6.47.0, hypothesis-jsonschema==0.22.0, and jsonschema==4.6.0, then trace how $defs/def_foo is resolved. Compare the resolver behavior for the object and array cases in the example. Done means the example no longer raises RefResolutionError; an open pull request is already linked.

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

説明

The following jsonschema provokes hypothesis-jsonschema to fail:

from hypothesis import given
from hypothesis_jsonschema import from_schema

schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$defs": {
        "def_foo": {
            "properties": {
                "foo": {"type": "string"}
            },
            "additionalProperties": False,
        },
        "def_bar": {
            "type": "object",
            "properties": {
                "bar": {
                    "type": ["object", "array"],
                    "$ref": "#/$defs/def_foo",
                    "items": {
                        "type": "object",
                        "$ref": "#/$defs/def_foo",
                    },
                },
            },
            
        },
    },
    "allOf": [
        {"$ref": "#/$defs/def_bar"},
    ],
}


@given(from_schema(schema))
def test_dummy(instance):
    assert True

Exception:

self = <hypothesis_jsonschema._resolve.LocalResolver object at 0x7f2a1058ce10>
document = {'additionalProperties': {'not': {}}, 'items': {'$ref': '#/$defs/def_foo', 'type': 'object'}, 'maxProperties': 1, 'properties': {'foo': {'type': 'string'}}, ...}
fragment = '$defs/def_foo'

    def resolve_fragment(self, document, fragment):
        """
        Resolve a ``fragment`` within the referenced ``document``.
    
        Arguments:
    
            document:
    
                The referent document
    
            fragment (str):
    
                a URI fragment to resolve within it
        """
    
        fragment = fragment.lstrip(u"/")
        parts = unquote(fragment).split(u"/") if fragment else []
    
        for part in parts:
            part = part.replace(u"~1", u"/").replace(u"~0", u"~")
    
            if isinstance(document, Sequence):
                # Array indexes should be turned into integers
                try:
                    part = int(part)
                except ValueError:
                    pass
            try:
                document = document[part]
            except (TypeError, LookupError):
                raise exceptions.RefResolutionError(
>                   "Unresolvable JSON pointer: %r" % fragment
                )
E               jsonschema.exceptions.RefResolutionError: Unresolvable JSON pointer: '$defs/def_foo'

./venv/bin/python3.6/site-packages/jsonschema/validators.py:814: RefResolutionError

Environment:

  • Python version: 3.10.4
  • hypothesis==6.47.0
  • hypothesis-jsonschema==0.22.0
  • jsonschema==4.6.0
主要言語
Python
スター
281
フォーク
35
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

python-jsonschema/hypothesis-jsonschema のほかの issue

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

似ている issue

Python の issue をもっと見る

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

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