From c068b59341e744871e809950ef18fe413890104b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85dne=20Jacobsen?= Date: Thu, 7 Sep 2023 07:33:47 +0000 Subject: [PATCH] Require data.spec only on certain data types --- .../0.8.0/examples/dictionary_parameters.yml | 71 +++++++++++++++++++ .../definitions/0.8.0/schema/fmu_results.json | 27 ++++++- tests/test_schema/test_schema_logic.py | 20 ++++++ 3 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 schema/definitions/0.8.0/examples/dictionary_parameters.yml diff --git a/schema/definitions/0.8.0/examples/dictionary_parameters.yml b/schema/definitions/0.8.0/examples/dictionary_parameters.yml new file mode 100644 index 000000000..90f477199 --- /dev/null +++ b/schema/definitions/0.8.0/examples/dictionary_parameters.yml @@ -0,0 +1,71 @@ +$schema: "https://main-fmu-schemas-prod.radix.equinor.com/schemas/0.8.0/fmu_results.json" +version: "0.8.0" +source: "fmu" +tracklog: + - datetime: "2023-09-07T07:39:33.291683" + user: + id: "adnj" + event: "created" +class: "dictionary" +fmu: + model: + name: "ff" + revision: "undefined" + context: + stage: "realization" + case: + name: "adnj_drogon_parameters_test" + uuid: "0db864d3-ac25-4e0f-9195-36fd524e0840" + user: + id: "adnj" + iteration: + id: 0 + uuid: "dad9a25a-3ad0-0f0a-08f2-c6fe8aae4c45" + name: "iter-0" + realization: + id: 0 + uuid: "28274007-fd40-29c4-c6ef-10e2414ccdcd" + name: "realization-0" +file: + relative_path: "realization-0/iter-0/share/results/dictionaries/parameters.json" + absolute_path: "/scratch/fmu/adnj/adnj_drogon_parameters_test/realization-0/iter-0/share/results/dictionaries/parameters.json" + checksum_md5: "ebbf160256cc2cf2011ed2fb6ac13f85" +data: + name: "parameters" + stratigraphic: false + content: "parameters" + tagname: "" + format: "json" + layout: "dictionary" + unit: "" + vertical_domain: "depth" + depth_reference: "msl" + undef_is_zero: false + is_prediction: true + is_observation: false +display: + name: "parameters" +access: + asset: + name: "Drogon" + ssdl: + access_level: "internal" + rep_include: false + classification: "internal" +masterdata: + smda: + country: + - identifier: "Norway" + uuid: "ad214d85-8a1d-19da-e053-c918a4889309" + discovery: + - short_identifier: "DROGON" + uuid: "ad214d85-8a1d-19da-e053-c918a4889309" + field: + - identifier: "DROGON" + uuid: "00000000-0000-0000-0000-000000000000" + coordinate_system: + identifier: "ST_WGS84_UTM37N_P32637" + uuid: "ad214d85-dac7-19da-e053-c918a4889309" + stratigraphic_column: + identifier: "DROGON_HAS_NO_STRATCOLUMN" + uuid: "00000000-0000-0000-0000-000000000000" \ No newline at end of file diff --git a/schema/definitions/0.8.0/schema/fmu_results.json b/schema/definitions/0.8.0/schema/fmu_results.json index e002a0534..cf7e3207c 100644 --- a/schema/definitions/0.8.0/schema/fmu_results.json +++ b/schema/definitions/0.8.0/schema/fmu_results.json @@ -170,7 +170,6 @@ "content", "name", "format", - "spec", "stratigraphic", "is_prediction", "is_observation" @@ -1370,7 +1369,31 @@ "ssdl" ] } - } + }, + "allOf": [ + { + "$comment": "Require data.spec for table and surface objects", + "if": { + "properties": { + "class": { + "enum": [ + "table", + "surface" + ] + } + } + }, + "then": { + "properties": { + "data": { + "required": [ + "spec" + ] + } + } + } + } + ] } ] } \ No newline at end of file diff --git a/tests/test_schema/test_schema_logic.py b/tests/test_schema/test_schema_logic.py index fcf250d9a..96bd33155 100644 --- a/tests/test_schema/test_schema_logic.py +++ b/tests/test_schema/test_schema_logic.py @@ -347,3 +347,23 @@ def test_schema_logic_classification(schema_080, metadata_examples): example["access"]["classification"] = "open" with pytest.raises(jsonschema.exceptions.ValidationError): jsonschema.validate(instance=example, schema=schema_080) + +def test_schema_logic_data_spec(schema_080, metadata_examples): + """Test schema logic for data.spec""" + + # fetch surface example + example_surface = deepcopy(metadata_examples["surface_depth.yml"]) + + # assert validation with no changes + jsonschema.validate(instance=example_surface, schema=schema_080) + + # assert data.spec required when class == surface + del example_surface["data"]["spec"] + with pytest.raises(jsonschema.exceptions.ValidationError): + jsonschema.validate(instance=example_surface, schema=schema_080) + + # fetch dictionary example + example_dict = deepcopy(metadata_examples["dictionary_parameters.yml"]) + + # assert data.spec not required when class === dictionary + jsonschema.validate(instance=example_dict, schema=schema_080) \ No newline at end of file