Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Remove AnyProduct discriminator mapping #935

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading