Skip to content

Commit

Permalink
Merge pull request #19374 from mvdbeek/improve_conditional_specificity
Browse files Browse the repository at this point in the history
Make conditional discriminators literals instead of generic string/bool
  • Loading branch information
jmchilton authored Jan 7, 2025
2 parents 4ded93d + 384dfc8 commit 356ed82
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/tool_util/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ def pydantic_template(self, state_representation: StateRepresentationT) -> Dynam
else:
initialize_test = None
tag = str(discriminator) if not is_boolean else str(discriminator).lower()
extra_kwd = {test_param_name: (Union[str, bool], initialize_test)}
extra_kwd = {test_param_name: (Literal[when.discriminator], initialize_test)}
when_types.append(
cast(
Type[BaseModel],
Expand Down
13 changes: 10 additions & 3 deletions test/unit/tool_util/test_parameter_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
validate_workflow_step_linked,
ValidationFunctionT,
)
from galaxy.tool_util.parameters.json import to_json_schema_string
from galaxy.tool_util.parameters.json import (
to_json_schema,
to_json_schema_string,
)
from galaxy.tool_util.unittest_utils.parameters import (
parameter_bundle_for_file,
parameter_bundle_for_framework_tool,
Expand Down Expand Up @@ -223,7 +226,11 @@ def test_decode_gx_int():
def test_json_schema_for_conditional():
input_bundle = parameter_bundle_for_file("gx_conditional_boolean")
tool_state = RequestToolState.parameter_model_for(input_bundle)
print(to_json_schema_string(tool_state))
json_schema = to_json_schema(tool_state)
assert json_schema["$defs"]["When_test_parameter_False"]["properties"]["test_parameter"]["const"] is False
assert json_schema["$defs"]["When_test_parameter_True"]["properties"]["test_parameter"]["const"] is True
assert "test_parameter" not in json_schema["$defs"]["When_test_parameter___absent"]["properties"]
assert to_json_schema_string(tool_state)


def test_encode_gx_data():
Expand All @@ -244,7 +251,7 @@ def encode_val(val: int) -> str:
parameter_models_json = {}
for file in parameter_spec.keys():
tool_parameter_model = parameter_bundle_for_file(file)
parameter_models_json[file] = tool_parameter_model.dict()
parameter_models_json[file] = tool_parameter_model.model_dump()
yaml_str = yaml.safe_dump(parameter_models_json)
with open("client/src/components/Tool/parameter_models.yml", "w") as f:
f.write("# auto generated file for JavaScript testing, do not modify manually\n")
Expand Down

0 comments on commit 356ed82

Please sign in to comment.