From 7bf3a7ea885a93bd308fb77a0ce812fa5b0c27e0 Mon Sep 17 00:00:00 2001 From: alexiswl <8197659+alexiswl@users.noreply.github.com> Date: Tue, 13 Feb 2024 12:13:07 +1100 Subject: [PATCH] Map hints to requirements to fix VSCode issue --- .../scripts/curate_autogenerated_schema.py | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/.github/scripts/curate_autogenerated_schema.py b/.github/scripts/curate_autogenerated_schema.py index 6d5a273..85d47a9 100644 --- a/.github/scripts/curate_autogenerated_schema.py +++ b/.github/scripts/curate_autogenerated_schema.py @@ -1227,6 +1227,44 @@ def fix_additional_properties(schema_dict: Dict, top_definition: str, sub_defini return schema_dict +def fix_hints(schema_dict, definition_key): + """ + Hints property should be the same as requirements for the given key + :param schema_dict: + :param definition_key: + :return: + """ + + # Always do a deepcopy on the input + schema_dict = deepcopy(schema_dict) + + # Assert definitions key + assert_definitions_key(schema_dict) + + # Confirm definitions key exists + if definition_key not in schema_dict["definitions"]: + raise ValueError(f"Schema does not contain an '{definition_key}' key in 'definitions'") + + # Confirm that the definition_key has a properties key and the properties key is a dictionary + if ( + "properties" not in schema_dict["definitions"][definition_key] or + not isinstance(schema_dict["definitions"][definition_key]["properties"], Dict) + ): + raise ValueError( + f"Schema does not contain a 'properties' key in '{definition_key}.definitions' " + "or 'properties' is not a dictionary" + ) + + # Confirm that properties has a requirements key + if "requirements" not in schema_dict["definitions"][definition_key]["properties"]: + raise ValueError(f"Schema does not contain an 'requirements' key in '{definition_key}.properties'") + + # Copy requirements to hints + schema_dict["definitions"][definition_key]["properties"]["hints"] = schema_dict["definitions"][definition_key]["properties"]["requirements"] + + return schema_dict + + def main(): # Step 1 - read in existing schema schema_dict = read_schema_in_from_file(Path(sys.argv[1])) @@ -1259,16 +1297,19 @@ def main(): for property_name in ["requirements", "hints"]: # Add named maps for hints and requirements - # FIXME, only requirements, not sure if hints expand beyond requirements) schema_dict = fix_named_maps(schema_dict, definition_key, property_name) # Also fix for 'in' for WorkflowStep schema_dict = fix_unnamed_maps(schema_dict, "WorkflowStep", "in") # And named maps for WorkflowStep - for property_name in ["requirements", "hints"]: + for property_name in ["requirements"]: schema_dict = fix_named_maps(schema_dict, "WorkflowStep", property_name) + # Hints should map to requirements + for definition_key in ["Workflow", "ExpressionTool", "CommandLineTool", "Operation"]: + schema_dict = fix_hints(schema_dict, definition_key) + # Update the schema to use 'if-else' for CommandlineTool and Expression schema_dict = add_cwl_file(schema_dict)