Skip to content

Commit

Permalink
FIX: Remove format-path from schema (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbjorge authored Mar 14, 2024
1 parent 27f62d3 commit 846157d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 60 deletions.
10 changes: 0 additions & 10 deletions schema/definitions/0.8.0/schema/fmu_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,6 @@
"absolute_path": {
"anyOf": [
{
"format": "path",
"type": "string"
},
{
Expand All @@ -2257,7 +2256,6 @@
"absolute_path_symlink": {
"anyOf": [
{
"format": "path",
"type": "string"
},
{
Expand Down Expand Up @@ -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"
},
{
Expand Down Expand Up @@ -4895,7 +4891,6 @@
"properties": {
"argList": {
"items": {
"format": "path",
"type": "string"
},
"title": "Arglist",
Expand All @@ -4911,7 +4906,6 @@
"error_file": {
"anyOf": [
{
"format": "path",
"type": "string"
},
{
Expand All @@ -4921,14 +4915,12 @@
"title": "Error File"
},
"executable": {
"format": "path",
"title": "Executable",
"type": "string"
},
"license_path": {
"anyOf": [
{
"format": "path",
"type": "string"
},
{
Expand Down Expand Up @@ -5018,7 +5010,6 @@
"target_file": {
"anyOf": [
{
"format": "path",
"type": "string"
},
{
Expand Down Expand Up @@ -5051,7 +5042,6 @@
"RealizationJobs": {
"properties": {
"DATA_ROOT": {
"format": "path",
"title": "Data Root",
"type": "string"
},
Expand Down
125 changes: 75 additions & 50 deletions src/fmu/dataio/datastructure/meta/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -19,6 +19,8 @@

from . import content, enums

T = TypeVar("T", Dict, List, object)


class Asset(BaseModel):
name: str = Field(examples=["Drogon"])
Expand Down Expand Up @@ -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
"""
Expand All @@ -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,
),
)

0 comments on commit 846157d

Please sign in to comment.