From d1b9409adca4fda6a6434ae7cdef11e6bbc7d090 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Fri, 1 Nov 2024 00:21:19 -0400 Subject: [PATCH 1/5] fix disallowing undefined mlm-prefixed fields (fixes #41) --- CHANGELOG.md | 3 ++- json-schema/schema.json | 2 +- tests/test_schema.py | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 116e1d3..9a47ba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - n/a ### Fixed -- n/a +- Fix check of disallowed unknown/undefined `mlm:`-prefixed fields + (fixes [#41](https://github.com/stac-extensions/mlm/issues/41)). ## [v1.3.0](https://github.com/stac-extensions/mlm/tree/v1.3.0) diff --git a/json-schema/schema.json b/json-schema/schema.json index ff21357..2072404 100644 --- a/json-schema/schema.json +++ b/json-schema/schema.json @@ -314,7 +314,7 @@ }, "$comment": "Allow properties not defined by MLM prefix to allow combination with other extensions.", "patternProperties": { - "^(?!dlm:)": {} + "^(?!mlm:)": {} }, "additionalProperties": false }, diff --git a/tests/test_schema.py b/tests/test_schema.py index 4755978..3958b55 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -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"], From b750dec7aa57045f06caca89b989e8d5e65410ae Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Fri, 1 Nov 2024 17:21:07 -0400 Subject: [PATCH 2/5] ignore test typing --- tests/test_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_schema.py b/tests/test_schema.py index 3958b55..fec5660 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -40,7 +40,7 @@ def test_mlm_no_undefined_prefixed_field( 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" + mlm_data["properties"]["mlm:unknown"] = "random" # type: ignore with pytest.raises(pystac.errors.STACValidationError) as exc: mlm_item = pystac.Item.from_dict(mlm_data) pystac.validation.validate(mlm_item, validator=mlm_validator) From 7f70ce47d9fb4d17b29fb7b2ad630c6a67d05acc Mon Sep 17 00:00:00 2001 From: Francis Charette-Migneault Date: Mon, 4 Nov 2024 01:25:53 -0500 Subject: [PATCH 3/5] add missing close parenthesis --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ad10344..a8b52ff 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ properties of the model. | Field Name | Type | Description | |------------|--------|----------------------------------------------------------------------------------------------------------------------------------------| -| name | string | **REQUIRED** Name of the band referring to an extended band definition (see [Bands](#bands-and-statistics). | +| name | string | **REQUIRED** Name of the band referring to an extended band definition (see [Bands](#bands-and-statistics) detiails). | | format | string | The type of expression that is specified in the `expression` property. | | expression | \* | An expression compliant with the `format` specified. The expression can be applied to any data type and depends on the `format` given. | From 43c0aaf87fdceefbf57338d4fe573f9c320d2f9e Mon Sep 17 00:00:00 2001 From: Francis Charette-Migneault Date: Mon, 4 Nov 2024 01:26:21 -0500 Subject: [PATCH 4/5] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8b52ff..1f4c05b 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ properties of the model. | Field Name | Type | Description | |------------|--------|----------------------------------------------------------------------------------------------------------------------------------------| -| name | string | **REQUIRED** Name of the band referring to an extended band definition (see [Bands](#bands-and-statistics) detiails). | +| name | string | **REQUIRED** Name of the band referring to an extended band definition (see [Bands](#bands-and-statistics) details). | | format | string | The type of expression that is specified in the `expression` property. | | expression | \* | An expression compliant with the `format` specified. The expression can be applied to any data type and depends on the `format` given. | From 768ac13b80c187a408cbc237350d005de5c58c66 Mon Sep 17 00:00:00 2001 From: Francis Charette-Migneault Date: Mon, 4 Nov 2024 01:44:43 -0500 Subject: [PATCH 5/5] fix typo --- best-practices.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best-practices.md b/best-practices.md index dcdf389..d7e1675 100644 --- a/best-practices.md +++ b/best-practices.md @@ -116,7 +116,7 @@ A potential representation of a STAC Asset could be as follows: Furthermore, the STAC Item representing the derived product could also include a [Link Object](https://github.com/radiantearth/stac-spec/tree/master/item-spec/item-spec.md#link-object) referring back to the MLM definition using `rel: derived_from`, as described in -[MLM Relation Types](README.md#relation-types). Such a link would like something like the following: +[MLM Relation Types](README.md#relation-types). Such a link would look something like the following: ```json {