Support additional (Python) types in more than the `type` validator
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Bắt đầu bằng cách đọc issue #364 và pull request liên quan, sau đó tái hiện các ví dụ NamedTuple trong issue này với các validator required và additionalProperties. Xác định cách các thuộc tính NamedTuple cần được nhận diện và truy cập một cách nhất quán, và coi công việc là hoàn tất khi cả hai ví dụ đều xác thực các thuộc tính dự kiến mà không xem các giá trị của chúng là tên thuộc tính.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In issue #364 and the related PR the type checker was expanded to allow redefining how jsonschema identifies/validates a type, with the intention of allowing a named tuple to be used as a jsonschema "object" type. In practice, this does not appear to be enough, as other portions of jsonschema use the python "in" expression to test for or iterate over properties in an object. In a NamedTuple, this will actually test the values of the properties. Two specific examples (required and additionalProperties) highlight this:
from typing import NamedTuple
from jsonschema import Draft7Validator
from jsonschema.validators import extend
from jsonschema.exceptions import ValidationError
# dict or tuple w/ _fields is object (allowed NamedTuple as object)
def is_object_or_namedtuple(checker, instance):
return isinstance(instance, dict) or (
isinstance(instance, tuple) and hasattr(instance, '_fields'))
# redefine object to allow namedtuple
type_checker = Draft7Validator.TYPE_CHECKER.redefine(
'object', is_object_or_namedtuple)
# extend validator with new type checker
Validator = extend(Draft7Validator, type_checker=type_checker)
# validator with foo as required property
validator_foo_required = Validator(schema={
"type": "object",
"properties": {
"foo": {
"type": "string"
}
},
"required": ["foo"]
})
# validator with foo as optional property, no additional
validator_foo_optional_no_additional = Validator(schema={
"type": "object",
"properties": {
"foo": {
"type": "string"
}
},
"additionalProperties": False
})
class Example(NamedTuple):
foo: str
example = Example(foo="bar")
try:
validator_foo_required.validate(example)
except ValidationError as e:
print(f"Error: {e.message}")
try:
validator_foo_optional_no_additional.validate(example)
except ValidationError as e:
print(f"Error: {e.message}")
# the problem is that 'foo' is not "in" example..
print('Is foo in example? ', ('foo' in example))
# ... but 'bar' is
print('Is bar in example? ', ('bar' in example))
This is more of an FYI, as #364 was targeted at supporting NamedTuple, but it looks like there would be some bigger changes required to facilitate redefining how properties are identified/accessed in the NamedTuple.
- Ngôn ngữ chính
- Python
- Star
- 5k
- Fork
- 700
- Merge trung bình
- 1 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 6
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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/jsonschema
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
python-jsonschema/jsonschema#1588 · 2 bình luận ·
-
Iterator error contexts lose parent links and absolute pathsCó thể làm lại được @DawnofGenX đã nhận 11 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
python-jsonschema/jsonschema#1584 · 3 bình luận ·
-
regex format checker crashes with RecursionError on deeply nested patternsCó thể đã có người làm @DawnofGenX đã nhận 11 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python-jsonschema/jsonschema#1538 · 1 bình luận ·
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponentCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởNeeds Test Upstream
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python-jsonschema/jsonschema#1511 · 1 bình luận ·
-
regex format checker crashes with ValueError on conflicting inline flagsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
python-jsonschema/jsonschema#1558 · 2 bình luận ·
Tất cả issue của python-jsonschema/jsonschema
Issue tương tự
-
docs: the dev-setup table and AGENTS.md name the reviewed_by guard that CI's Changelog job runsĐang mởarea: tools documentation good first issue ready for a contributor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
eyalgolan/statecraft-israel#873 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add cover art to song rowsĐang mởenhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 5 ngày
-
bug
Độ 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
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày