Skip to content

Commit

Permalink
workaround with manual copy of properties to use draft-07 without une…
Browse files Browse the repository at this point in the history
…valuatedProperties
  • Loading branch information
fmigneault committed Nov 6, 2024
1 parent 8e56578 commit b3b7d63
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 23 deletions.
129 changes: 108 additions & 21 deletions json-schema/schema.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down Expand Up @@ -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
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:)'"]
)


Expand Down

0 comments on commit b3b7d63

Please sign in to comment.