diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a4cff8ea..1d190fe85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ - Add an empty line to `modules.json`, `params.json` and `nextflow-schema.json` when dumping them to avoid prettier errors. - Add actions workflow to respond to `@nf-core-bot fix linting` comments on nf-core/tools PRs - Linting: Don't allow a `.nf-core.yaml` file, should be `.yml` ([#1515](https://github.com/nf-core/tools/pull/1515)). +- Not all definitions in JSON schema have a "properties", leading to an error ([#1419](https://github.com/nf-core/tools/issues/1419)) ### Modules diff --git a/nf_core/schema.py b/nf_core/schema.py index 5784645543..522f48d20b 100644 --- a/nf_core/schema.py +++ b/nf_core/schema.py @@ -613,6 +613,29 @@ def get_wf_params(self): ) ) + def remove_schema_empty_definitions(self): + """ + Go through top-level schema remove definitions that don't have + any property attributes + """ + # Make copy of schema + schema_no_empty_definitions = copy.deepcopy(self.schema) + + ## Identify and remove empty definitions from the schema + empty_definitions = [] + for d_key, d_schema in list(schema_no_empty_definitions.get("definitions", {}).items()): + if not d_schema['properties']: + del schema_no_empty_definitions["definitions"][d_key] + empty_definitions.append(d_key) + + # Remove "allOf" group with empty definitions from the schema + for d_key in empty_definitions: + allOf = {'$ref': "#/definitions/{}".format(d_key)} + if allOf in schema_no_empty_definitions["allOf"]: + schema_no_empty_definitions["allOf"].remove(allOf) + + self.schema = schema_no_empty_definitions + def remove_schema_notfound_configs(self): """ Go through top-level schema and all definitions sub-schemas to remove @@ -625,6 +648,8 @@ def remove_schema_notfound_configs(self): cleaned_schema, p_removed = self.remove_schema_notfound_configs_single_schema(definition) self.schema["definitions"][d_key] = cleaned_schema params_removed.extend(p_removed) + self.remove_schema_empty_definitions() + return params_removed def remove_schema_notfound_configs_single_schema(self, schema):