Skip to content

Commit

Permalink
Merge pull request #1203 from braingram/feature/jsonschema_4.10
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson authored Oct 11, 2022
2 parents 920bf45 + af59c7a commit 8632535
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Use forc ndarray flag to correctly test for fortran array contiguity [#1206]
- Unpin ``jsonschema`` version and fix ``jsonschema`` deprecation warnings. [#1185]
- Replace ``pkg_resources`` with ``importlib.metadata``. [#1199]
- Fix default validation for jsonschema 4.10+ [#1203]

2.13.0 (2022-08-19)
-------------------
Expand Down
10 changes: 10 additions & 0 deletions asdf/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections.abc import Mapping
from functools import lru_cache
from numbers import Integral
from operator import methodcaller

import numpy as np
import yaml
Expand Down Expand Up @@ -749,6 +750,14 @@ def _validate_default(validator, default, instance, schema):

validators.update({"default": _validate_default})

def applicable_validators(schema):
items = list(schema.items())
items.append(("default", ""))
return items

else:
applicable_validators = methodcaller("items")

meta_schema_id = schema.get("$schema", YAML_SCHEMA_METASCHEMA_ID)
meta_schema = _load_schema_cached(meta_schema_id, extension.get_default_resolver(), False, False)

Expand All @@ -759,6 +768,7 @@ def _validate_default(validator, default, instance, schema):
validators=validators,
type_checker=mvalidators.Draft4Validator.TYPE_CHECKER,
id_of=mvalidators.Draft4Validator.ID_OF,
applicable_validators=applicable_validators,
)
validator = cls(meta_schema, resolver=resolver)
validator.validate(schema)
2 changes: 0 additions & 2 deletions asdf/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ def test_defaults():
assert t == {}


@pytest.mark.xfail(reason="This will be fixed by #1203")
def test_default_check_in_schema():
s = {"type": "object", "properties": {"a": {"type": "integer", "default": "foo"}}}

Expand All @@ -420,7 +419,6 @@ def test_default_check_in_schema():
schema.check_schema(s, validate_default=False)


@pytest.mark.xfail(reason="This will be fixed by #1203")
def test_check_complex_default():
default_software = tagged.TaggedDict({"name": "asdf", "version": "2.7.0"}, "tag:stsci.edu/asdf/core/software-1.0.0")

Expand Down

0 comments on commit 8632535

Please sign in to comment.