Error resolving sub-schema property with type object or array

Đang mở
#97 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

  • #116 của @Kaiserunix — đã đóng, không merge

Đá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
20/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
281
Fork
35
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python-jsonschema/hypothesis-jsonschema

Tất cả issue của python-jsonschema/hypothesis-jsonschema

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.