Skip to content

Commit

Permalink
FIX: Remove AnyProduct discriminator mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mferrera committed Dec 19, 2024
1 parent 704f5cb commit a5aae49
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 0 additions & 3 deletions schema/definitions/0.8.0/schema/fmu_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions src/fmu/dataio/_model/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 25 additions & 0 deletions tests/test_schema/test_schema_uptodate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a5aae49

Please sign in to comment.