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

Parameters schema validation: allow oneOf, anyOf and allOf with required #3386

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

### General

- Parameters schema validation: allow oneOf, anyOf and allOf with `required` ([#3386](https://github.com/nf-core/tools/pull/3386))

### Version updates

## [v3.1.1 - Brass Boxfish Patch](https://github.com/nf-core/tools/releases/tag/3.1.1) - [2024-12-20]
Expand Down
28 changes: 28 additions & 0 deletions nf_core/pipelines/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,36 @@ def validate_default_params(self):
for group_key, group in schema_no_required.get(self.defs_notation, {}).items():
if "required" in group:
schema_no_required[self.defs_notation][group_key].pop("required")
if "allOf" in group:
for all_of in group["allOf"]:
if "required" in all_of:
schema_no_required[self.defs_notation][group_key]["allOf"].pop("required")
schema_no_required[self.defs_notation][group_key]["allOf"] = [
all_of for all_of in group["allOf"] if all_of
]
if not group["allOf"]:
schema_no_required[self.defs_notation][group_key].pop("allOf")
if "anyOf" in group:
for any_of in group["anyOf"]:
if "required" in any_of:
schema_no_required[self.defs_notation][group_key]["anyOf"].pop("required")
schema_no_required[self.defs_notation][group_key]["anyOf"] = [
any_of for any_of in group["anyOf"] if any_of
]
if not group["anyOf"]:
schema_no_required[self.defs_notation][group_key].pop("anyOf")
if "oneOf" in group:
for i, one_of in enumerate(group["oneOf"]):
if "required" in one_of:
schema_no_required[self.defs_notation][group_key]["oneOf"][i].pop("required")
schema_no_required[self.defs_notation][group_key]["oneOf"] = [
one_of for one_of in group["oneOf"] if one_of
]
if not group["oneOf"]:
schema_no_required[self.defs_notation][group_key].pop("oneOf")
jsonschema.validate(self.schema_defaults, schema_no_required)
except jsonschema.exceptions.ValidationError as e:
log.debug(f"Complete error message:\n{e}")
raise AssertionError(f"Default parameters are invalid: {e.message}")
for param, default in self.schema_defaults.items():
if default in ("null", "", None, "None") or default is False:
Expand Down
Loading