11import json
2+ from collections .abc import MutableMapping
23from typing import (
34 Any ,
45 Dict ,
@@ -135,18 +136,29 @@ def parse_stdio(self):
135136 return error_on_exit_code ()
136137
137138 def parse_help (self ) -> Optional [HelpContent ]:
138- content = self .root_dict .get ("help" , None )
139- if content :
140- return HelpContent (format = "markdown" , content = content )
139+ help = self .root_dict .get ("help" )
140+ format = "markdown"
141+ if isinstance (help , dict ):
142+ format = help .get ("format" , "markdown" )
143+ if isinstance (help , str ):
144+ return HelpContent (format = format , content = help )
145+ elif help and "content" in help :
146+ return HelpContent (format = format , content = help ["content" ])
141147 else :
142148 return None
143149
144150 def parse_outputs (self , app : Optional [ToolOutputActionApp ]):
145- outputs = self .root_dict .get ("outputs" , {})
151+ outputs = self .root_dict .get ("outputs" , [])
152+ if isinstance (outputs , MutableMapping ):
153+ for name , output_dict in outputs .items ():
154+ output_dict ["name" ] = name
155+ outputs = outputs .values ()
156+
146157 output_defs = []
147158 output_collection_defs = []
148- for name , output_dict in outputs . items () :
159+ for output_dict in outputs :
149160 output_type = output_dict .get ("type" , "data" )
161+ name = output_dict ["name" ]
150162 if output_type == "data" :
151163 output_defs .append (self ._parse_output (app , name , output_dict ))
152164 elif output_type == "collection" :
@@ -213,7 +225,7 @@ def parse_tests_to_dict(self) -> ToolSourceTests:
213225 return rval
214226
215227 def parse_profile (self ) -> str :
216- return self .root_dict .get ("profile" , "16.04" )
228+ return self .root_dict .get ("profile" ) or "16.04"
217229
218230 def parse_license (self ) -> Optional [str ]:
219231 return self .root_dict .get ("license" )
@@ -229,7 +241,7 @@ def parse_python_template_version(self):
229241
230242 def to_string (self ):
231243 # TODO: Unit test for dumping/restoring
232- return json .dumps (self .root_dict )
244+ return json .dumps (self .root_dict , ensure_ascii = False , sort_keys = False )
233245
234246
235247def _parse_test (i , test_dict ) -> ToolSourceTest :
@@ -365,27 +377,27 @@ def parse_nested_inputs_source(self):
365377 return YamlPageSource (self .input_dict ["blocks" ])
366378
367379 def parse_test_input_source (self ):
368- test_dict = self .input_dict .get ("test " , None )
369- assert test_dict is not None , "conditional must contain a `test ` definition"
380+ test_dict = self .input_dict .get ("test_parameter " , None )
381+ assert test_dict is not None , "conditional must contain a `test_parameter ` definition"
370382 return YamlInputSource (test_dict )
371383
372384 def parse_when_input_sources (self ):
373385 input_dict = self .input_dict
374386
375387 sources = []
376- for value , block in input_dict . get ( "when" , {}). items () :
377- if value is True :
378- value = "true"
379- elif value is False :
380- value = "false"
381- else :
382- value = str ( value )
383-
384- # str here to lose type information like XML, needed?
385- if not isinstance ( block , list ):
386- block = [ block ]
387- case_page_source = YamlPageSource (block )
388- sources .append ((value , case_page_source ))
388+ if "when" in input_dict :
389+ for key , value in input_dict [ "when" ]. items () :
390+ # casting to string because default value for BooleanToolParameter.legal_values is "true" / "false "
391+ # Unfortunate, but I guess that's ok for now?
392+ discriminator = "true" if key is True else " false" if key is False else key
393+ case_page_source = YamlPageSource ( value )
394+ sources . append (( discriminator , case_page_source ) )
395+ else :
396+ for value in input_dict . get ( "whens" , []):
397+ key = value . get ( "discriminator" )
398+ discriminator = "true" if key is True else "false" if key is False else key
399+ case_page_source = YamlPageSource (value [ "parameters" ] )
400+ sources .append ((discriminator , case_page_source ))
389401 return sources
390402
391403 def parse_validators (self ) -> List [AnyValidatorModel ]:
0 commit comments