diff --git a/asdf/_tests/tags/core/tests/test_ndarray.py b/asdf/_tests/tags/core/tests/test_ndarray.py index 5688a3681..02c79f469 100644 --- a/asdf/_tests/tags/core/tests/test_ndarray.py +++ b/asdf/_tests/tags/core/tests/test_ndarray.py @@ -812,6 +812,7 @@ def test_structured_datatype_validation(tmp_path): data: [[1, 'a'], [2, 'b'], [3, 'c']] datatype: - name: a + description: a description datatype: int8 - name: b datatype: ['ascii', 8] @@ -829,6 +830,7 @@ def test_structured_datatype_validation(tmp_path): - name: a datatype: int64 - name: b + title: a title datatype: ['ascii', 8] """ buff = helpers.yaml_to_asdf(content) diff --git a/asdf/tags/core/ndarray.py b/asdf/tags/core/ndarray.py index 37574073f..df78e771f 100644 --- a/asdf/tags/core/ndarray.py +++ b/asdf/tags/core/ndarray.py @@ -7,6 +7,8 @@ from asdf import util from asdf._jsonschema import ValidationError +_STRUCTURED_DATATYPE_KEYS = {"name", "datatype", "byteorder", "shape"} + _datatype_names = { "int8": "i1", "int16": "i2", @@ -533,6 +535,13 @@ def validate_datatype(validator, datatype, instance, schema): msg = "Not an array" raise ValidationError(msg) + # We are only concerned with some fields from the datatype + # object in the schema so if the schema datatype is structured + # copy the datatype and drop the irrelevant fields + # name datatype byteorder shape + if isinstance(datatype, list) and len(datatype) and isinstance(datatype[0], dict): + datatype = [{k: v for k, v in subitem.items() if k in _STRUCTURED_DATATYPE_KEYS} for subitem in datatype] + if datatype == in_datatype: return diff --git a/changes/1901.bugfix.rst b/changes/1901.bugfix.rst new file mode 100644 index 000000000..b3066d871 --- /dev/null +++ b/changes/1901.bugfix.rst @@ -0,0 +1 @@ +Allow extra keywords in structured datatype validation.