From a5aae499fa28e2b3bbd657f3e299815890ce4ad8 Mon Sep 17 00:00:00 2001 From: mferrera Date: Thu, 19 Dec 2024 09:37:16 +0100 Subject: [PATCH] FIX: Remove AnyProduct discriminator mapping --- .../definitions/0.8.0/schema/fmu_results.json | 3 --- src/fmu/dataio/_model/root.py | 1 + tests/test_schema/test_schema_uptodate.py | 25 +++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/schema/definitions/0.8.0/schema/fmu_results.json b/schema/definitions/0.8.0/schema/fmu_results.json index a824cd5ed..a37b4a4ee 100644 --- a/schema/definitions/0.8.0/schema/fmu_results.json +++ b/schema/definitions/0.8.0/schema/fmu_results.json @@ -214,9 +214,6 @@ "AnyProduct": { "description": "The ``product`` field contains information about which product this data object\nrepresent. Data that is tagged as a product is a standard result from FMU that\nconforms to a specified standard.\n\nThis class, ``AnyProduct``, acts as a container for different data products, with\nthe exact product being identified by the ``product.name`` field.", "discriminator": { - "mapping": { - "inplace_volumes": "#/$defs/InplaceVolumesProduct" - }, "propertyName": "name" }, "oneOf": [ diff --git a/src/fmu/dataio/_model/root.py b/src/fmu/dataio/_model/root.py index 8d7d1f8fe..627f5d152 100644 --- a/src/fmu/dataio/_model/root.py +++ b/src/fmu/dataio/_model/root.py @@ -274,6 +274,7 @@ def generate( # sumo-core's validator does not recognize these. del json_schema["discriminator"]["mapping"] del json_schema["$defs"]["AnyData"]["discriminator"]["mapping"] + del json_schema["$defs"]["AnyProduct"]["discriminator"]["mapping"] return self._remove_format_path(json_schema) diff --git a/tests/test_schema/test_schema_uptodate.py b/tests/test_schema/test_schema_uptodate.py index 802fa4df7..20c09bf0c 100644 --- a/tests/test_schema/test_schema_uptodate.py +++ b/tests/test_schema/test_schema_uptodate.py @@ -15,3 +15,28 @@ def test_schema_uptodate(): """ with open("schema/definitions/0.8.0/schema/fmu_results.json") as f: assert json.load(f) == dump() + + +def contains_discriminator_mapping(schema): + """Recursively checks ["discriminator"]["mapping"] in the schema.""" + if isinstance(schema, dict): + if ( + "discriminator" in schema and isinstance(schema["discriminator"], dict) + ) and "mapping" in schema["discriminator"]: + return True + for value in schema.values(): + if contains_discriminator_mapping(value): + return True + elif isinstance(schema, list): + for item in schema: + if contains_discriminator_mapping(item): + return True + return False + + +def test_no_discriminator_mappings_leftover_in_schema(): + """Sumo's AJV validator doesn't like discriminator mappings leftover in the + schema.""" + with open("schema/definitions/0.8.0/schema/fmu_results.json") as f: + schema = json.load(f) + assert contains_discriminator_mapping(schema) is False