From b3b7d630a7bd5070515e8829bbc5219a069aa577 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Wed, 6 Nov 2024 13:23:12 -0500 Subject: [PATCH] workaround with manual copy of properties to use draft-07 without unevaluatedProperties --- json-schema/schema.json | 129 +++++++++++++++++++++++++++++++++------- tests/test_schema.py | 4 +- 2 files changed, 110 insertions(+), 23 deletions(-) diff --git a/json-schema/schema.json b/json-schema/schema.json index 42371c9..1baf8f0 100644 --- a/json-schema/schema.json +++ b/json-schema/schema.json @@ -1,5 +1,5 @@ { - "$schema": "https://json-schema.org/draft/2019-09/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://stac-extensions.github.io/mlm/v1.3.0/schema.json", "title": "Machine Learning Model STAC Extension Schema", "description": "This object represents the metadata for a Machine Learning Model (MLM) used in STAC documents.", @@ -30,38 +30,125 @@ "properties": { "description": "Schema to validate the MLM fields permitted under Item properties.", "$comment": "Allow properties not defined by MLM prefix to work with other extensions and attributes, but disallow undefined MLM fields.", - "allOf": [ - { - "type": "object", - "required": [ - "mlm:name", - "mlm:architecture", - "mlm:tasks", - "mlm:input", - "mlm:output" - ] + "type": "object", + "required": [ + "mlm:name", + "mlm:architecture", + "mlm:tasks", + "mlm:input", + "mlm:output" + ], + "properties": { + "mlm:name": { + "$ref": "#/$defs/mlm:name" }, - { - "$ref": "#/$defs/mlmItemFields" + "mlm:architecture": { + "$ref": "#/$defs/mlm:architecture" }, - { - "patternProperties": { - "^(?!mlm:)": {} - } + "mlm:tasks": { + "$ref": "#/$defs/mlm:tasks" + }, + "mlm:framework": { + "$ref": "#/$defs/mlm:framework" + }, + "mlm:framework_version": { + "$ref": "#/$defs/mlm:framework_version" + }, + "mlm:memory_size": { + "$ref": "#/$defs/mlm:memory_size" + }, + "mlm:total_parameters": { + "$ref": "#/$defs/mlm:total_parameters" + }, + "mlm:pretrained": { + "$ref": "#/$defs/mlm:pretrained" + }, + "mlm:pretrained_source": { + "$ref": "#/$defs/mlm:pretrained_source" + }, + "mlm:batch_size_suggestion": { + "$ref": "#/$defs/mlm:batch_size_suggestion" + }, + "mlm:accelerator": { + "$ref": "#/$defs/mlm:accelerator" + }, + "mlm:accelerator_constrained": { + "$ref": "#/$defs/mlm:accelerator_constrained" + }, + "mlm:accelerator_summary": { + "$ref": "#/$defs/mlm:accelerator_summary" + }, + "mlm:accelerator_count": { + "$ref": "#/$defs/mlm:accelerator_count" + }, + "mlm:input": { + "$ref": "#/$defs/mlm:input" + }, + "mlm:output": { + "$ref": "#/$defs/mlm:output" + }, + "mlm:hyperparameters": { + "$ref": "#/$defs/mlm:hyperparameters" } - ], - "unevaluatedProperties": false + }, + "patternProperties": { + "^(?!mlm:)": {} + }, + "additionalProperties": false }, "assets": { "type": "object", "additionalProperties": { "description": "Schema to validate the MLM fields permitted only under Assets properties.", "$comment": "Allow properties not defined by MLM prefix to work with other extensions and attributes, but disallow undefined MLM fields.", - "$ref": "#/$defs/mlmAssetFields", + "properties": { + "mlm:architecture": { + "$ref": "#/$defs/mlm:architecture" + }, + "mlm:tasks": { + "$ref": "#/$defs/mlm:tasks" + }, + "mlm:framework": { + "$ref": "#/$defs/mlm:framework" + }, + "mlm:framework_version": { + "$ref": "#/$defs/mlm:framework_version" + }, + "mlm:memory_size": { + "$ref": "#/$defs/mlm:memory_size" + }, + "mlm:total_parameters": { + "$ref": "#/$defs/mlm:total_parameters" + }, + "mlm:pretrained": { + "$ref": "#/$defs/mlm:pretrained" + }, + "mlm:pretrained_source": { + "$ref": "#/$defs/mlm:pretrained_source" + }, + "mlm:batch_size_suggestion": { + "$ref": "#/$defs/mlm:batch_size_suggestion" + }, + "mlm:accelerator": { + "$ref": "#/$defs/mlm:accelerator" + }, + "mlm:accelerator_constrained": { + "$ref": "#/$defs/mlm:accelerator_constrained" + }, + "mlm:accelerator_summary": { + "$ref": "#/$defs/mlm:accelerator_summary" + }, + "mlm:accelerator_count": { + "$ref": "#/$defs/mlm:accelerator_count" + }, + "mlm:artifact_type": { + "$ref": "#/$defs/mlm:artifact_type" + } + }, "patternProperties": { "^(?!mlm:)": {} }, - "unevaluatedProperties": false + "additionalProperties": false } } } diff --git a/tests/test_schema.py b/tests/test_schema.py index bda53d1..e5a1ded 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -48,7 +48,7 @@ def test_mlm_no_undefined_prefixed_field_item_properties( pystac.validation.validate(mlm_item, validator=mlm_validator) assert all( info in str(exc.value.source) - for info in ["mlm:unknown", "Unevaluated properties are not allowed"] + for info in ["mlm:unknown", "does not match any of the regexes: '^(?!mlm:)'"] ) # defined property only allowed at the Asset level @@ -59,7 +59,7 @@ def test_mlm_no_undefined_prefixed_field_item_properties( pystac.validation.validate(mlm_item, validator=mlm_validator) assert all( field in str(exc.value.source) - for field in ["mlm:artifact_type", "Unevaluated properties are not allowed"] + for field in ["mlm:artifact_type", "does not match any of the regexes: '^(?!mlm:)'"] )