diff --git a/schema/definitions/0.8.0/schema/fmu_meta.json b/schema/definitions/0.8.0/schema/fmu_meta.json index 38e7616dc..6a64e1b44 100644 --- a/schema/definitions/0.8.0/schema/fmu_meta.json +++ b/schema/definitions/0.8.0/schema/fmu_meta.json @@ -2240,7 +2240,6 @@ "absolute_path": { "anyOf": [ { - "format": "path", "type": "string" }, { @@ -2257,7 +2256,6 @@ "absolute_path_symlink": { "anyOf": [ { - "format": "path", "type": "string" }, { @@ -2287,14 +2285,12 @@ "examples": [ "share/results/maps/volantis_gp_base--depth.gri" ], - "format": "path", "title": "Relative Path", "type": "string" }, "relative_path_symlink": { "anyOf": [ { - "format": "path", "type": "string" }, { @@ -4895,7 +4891,6 @@ "properties": { "argList": { "items": { - "format": "path", "type": "string" }, "title": "Arglist", @@ -4911,7 +4906,6 @@ "error_file": { "anyOf": [ { - "format": "path", "type": "string" }, { @@ -4921,14 +4915,12 @@ "title": "Error File" }, "executable": { - "format": "path", "title": "Executable", "type": "string" }, "license_path": { "anyOf": [ { - "format": "path", "type": "string" }, { @@ -5018,7 +5010,6 @@ "target_file": { "anyOf": [ { - "format": "path", "type": "string" }, { @@ -5051,7 +5042,6 @@ "RealizationJobs": { "properties": { "DATA_ROOT": { - "format": "path", "title": "Data Root", "type": "string" }, diff --git a/src/fmu/dataio/datastructure/meta/meta.py b/src/fmu/dataio/datastructure/meta/meta.py index 8bdec23e8..49bdc6176 100644 --- a/src/fmu/dataio/datastructure/meta/meta.py +++ b/src/fmu/dataio/datastructure/meta/meta.py @@ -2,7 +2,7 @@ from collections import ChainMap from pathlib import Path -from typing import Dict, List, Literal, Optional, Union +from typing import Dict, List, Literal, Optional, TypeVar, Union from uuid import UUID from pydantic import ( @@ -19,6 +19,8 @@ from . import content, enums +T = TypeVar("T", Dict, List, object) + class Asset(BaseModel): name: str = Field(examples=["Drogon"]) @@ -484,6 +486,26 @@ def _remove_discriminator_mapping(obj: Dict) -> Dict: return obj +def _remove_format_path(obj: T) -> T: + """ + Removes entries with key "format" and value "path" from dictionaries. This adjustment + is necessary because JSON Schema does not recognize the "format": "path", while OpenAPI does. + This function is used in contexts where OpenAPI specifications are not applicable. + """ + + if isinstance(obj, dict): + return { + k: _remove_format_path(v) + for k, v in obj.items() + if not (k == "format" and v == "path") + } + + if isinstance(obj, list): + return [_remove_format_path(element) for element in obj] + + return obj + + def dump() -> Dict: # ruff: noqa: E501 """ @@ -501,54 +523,57 @@ def dump() -> Dict: If changes are satisfactory and do not introduce issues, commit them to maintain schema consistency. """ - - return _remove_discriminator_mapping( - dict( - ChainMap( - { - "$contractual": [ - "class", - "source", - "version", - "tracklog", - "data.format", - "data.name", - "data.stratigraphic", - "data.alias", - "data.stratigraphic_alias", - "data.offset", - "data.content", - "data.tagname", - "data.vertical_domain", - "data.grid_model", - "data.bbox", - "data.time", - "data.is_prediction", - "data.is_observation", - "data.seismic.attribute", - "data.spec.columns", - "access", - "masterdata", - "fmu.model", - "fmu.workflow", - "fmu.case", - "fmu.iteration.name", - "fmu.iteration.uuid", - "fmu.realization.name", - "fmu.realization.id", - "fmu.realization.uuid", - "fmu.aggregation.operation", - "fmu.aggregation.realization_ids", - "fmu.context.stage", - "file.relative_path", - "file.checksum_md5", - "file.size_bytes", - ], - # schema must be present for "dependencies" key to work. - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "fmu_meta.json", - }, - Root.model_json_schema(), - ) + schema = dict( + ChainMap( + { + "$contractual": [ + "class", + "source", + "version", + "tracklog", + "data.format", + "data.name", + "data.stratigraphic", + "data.alias", + "data.stratigraphic_alias", + "data.offset", + "data.content", + "data.tagname", + "data.vertical_domain", + "data.grid_model", + "data.bbox", + "data.time", + "data.is_prediction", + "data.is_observation", + "data.seismic.attribute", + "data.spec.columns", + "access", + "masterdata", + "fmu.model", + "fmu.workflow", + "fmu.case", + "fmu.iteration.name", + "fmu.iteration.uuid", + "fmu.realization.name", + "fmu.realization.id", + "fmu.realization.uuid", + "fmu.aggregation.operation", + "fmu.aggregation.realization_ids", + "fmu.context.stage", + "file.relative_path", + "file.checksum_md5", + "file.size_bytes", + ], + # schema must be present for "dependencies" key to work. + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "fmu_meta.json", + }, + Root.model_json_schema(), ) ) + + return _remove_format_path( + _remove_discriminator_mapping( + schema, + ), + )