diff --git a/src/metldata/builtin_transformations/add_content_properties/__init__.py b/src/metldata/builtin_transformations/add_content_properties/__init__.py new file mode 100644 index 0000000..9cd318f --- /dev/null +++ b/src/metldata/builtin_transformations/add_content_properties/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln +# for the German Human Genome-Phenome Archive (GHGA) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""A transformation to add content properties.""" + +from metldata.builtin_transformations.add_content_properties.main import ( + ADD_CONTENT_PROPERTIES_TRANSFORMATION, # noqa: F401 +) diff --git a/src/metldata/builtin_transformations/add_content_properties/instruction.py b/src/metldata/builtin_transformations/add_content_properties/instruction.py index 5b56771..e74a5d4 100644 --- a/src/metldata/builtin_transformations/add_content_properties/instruction.py +++ b/src/metldata/builtin_transformations/add_content_properties/instruction.py @@ -20,31 +20,14 @@ from pydantic import Field from pydantic_settings import BaseSettings +from metldata.builtin_transformations.common import NewContentSchemaPath + DEFAULT_CONTENT_SCHEMA: Final[dict[str, Any]] = { "type": "object", "additionalProperties": False, } -class NewContentSchemaPath(BaseSettings): - """A model describing the path of an object property within the content schema that - is yet to be added. The model comprises a path to an already existing object within - the content schema and the name of a property to be added to that object's schema - """ - - object_path: str = Field( - ..., - description=( - "The path to the content object to which a property shall be added. The" - + " path must be specified in dot notation, equivalently to JavaScript" - + " property accessors." - ), - examples=["some_property.another_nested_property"], - ) - - property_name: str = Field(..., description="The name of the property to be added.") - - class AddContentPropertyInstruction(BaseSettings): """A model describing an instruction to add a new content property to a class in a schemapack, including an associated default value in corresponding data. diff --git a/src/metldata/builtin_transformations/common/__init__.py b/src/metldata/builtin_transformations/common/__init__.py new file mode 100644 index 0000000..448eb34 --- /dev/null +++ b/src/metldata/builtin_transformations/common/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln +# for the German Human Genome-Phenome Archive (GHGA) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Common models and functions for the built-in transformations.""" + +from metldata.builtin_transformations.common.contentschema import ( + NewContentSchemaPath, # noqa: F401 +) diff --git a/src/metldata/builtin_transformations/common/contentschema.py b/src/metldata/builtin_transformations/common/contentschema.py new file mode 100644 index 0000000..55de406 --- /dev/null +++ b/src/metldata/builtin_transformations/common/contentschema.py @@ -0,0 +1,37 @@ +# Copyright 2021 - 2024 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln +# for the German Human Genome-Phenome Archive (GHGA) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Models and functions related to content schema manipulation.""" + +from pydantic import Field +from pydantic_settings import BaseSettings + + +class NewContentSchemaPath(BaseSettings): + """A model describing the path of an object property within the content schema that + is yet to be added. The model comprises a path to an already existing object within + the content schema and the name of a property to be added to that object's schema + """ + + object_path: str = Field( + ..., + description=( + "The path to the content object to which a property shall be added. The" + + " path must be specified in dot notation, equivalently to JavaScript" + + " property accessors." + ), + examples=["some_property.another_nested_property"], + ) + + property_name: str = Field(..., description="The name of the property to be added.") diff --git a/tests/fixtures/transformations.py b/tests/fixtures/transformations.py index 35e6e37..c5a0eb8 100644 --- a/tests/fixtures/transformations.py +++ b/tests/fixtures/transformations.py @@ -23,10 +23,10 @@ from schemapack.spec.datapack import DataPack from schemapack.spec.schemapack import SchemaPack -from metldata.builtin_transformations.add_content_properties.main import ( +from metldata.builtin_transformations.add_content_properties import ( ADD_CONTENT_PROPERTIES_TRANSFORMATION, ) -from metldata.builtin_transformations.delete_properties.main import ( +from metldata.builtin_transformations.delete_properties import ( PROPERTY_DELETION_TRANSFORMATION, ) from metldata.builtin_transformations.infer_relations import (