Skip to content

Commit

Permalink
fix disallowing undefined mlm-prefixed fields (fixes #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Nov 1, 2024
1 parent d36a374 commit 125152b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Otherwise, the amount of `scaling` objects should match the number of bands or channels involved in the input.

### Fixed
- n/a
- Fix check of unknown/undefined `mlm:`-prefixed fields is disallowed
(fixes [#41](https://github.com/stac-extensions/mlm/issues/41)).

## [v1.3.0](https://github.com/stac-extensions/mlm/tree/v1.3.0)

Expand Down
2 changes: 1 addition & 1 deletion json-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
},
"$comment": "Allow properties not defined by MLM prefix to allow combination with other extensions.",
"patternProperties": {
"^(?!dlm:)": {}
"^(?!mlm:)": {}
},
"additionalProperties": false
},
Expand Down
23 changes: 23 additions & 0 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ def test_mlm_schema(
assert SCHEMA_URI in validated


@pytest.mark.parametrize(
"mlm_example",
["item_raster_bands.json"],
indirect=True,
)
def test_mlm_no_undefined_prefixed_field(
mlm_validator: STACValidator,
mlm_example: Dict[str, JSON],
) -> None:
mlm_data = copy.deepcopy(mlm_example)
mlm_item = pystac.Item.from_dict(mlm_data)
pystac.validation.validate(mlm_item, validator=mlm_validator) # ensure original is valid

mlm_data["properties"]["mlm:unknown"] = "random"
with pytest.raises(pystac.errors.STACValidationError) as exc:
mlm_item = pystac.Item.from_dict(mlm_data)
pystac.validation.validate(mlm_item, validator=mlm_validator)
assert all(
field in str(exc.value.source)
for field in ["mlm:unknown", "^(?!mlm:)"]
)


@pytest.mark.parametrize(
"mlm_example",
["item_raster_bands.json"],
Expand Down

0 comments on commit 125152b

Please sign in to comment.