File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -195,13 +195,15 @@ def generate_example_input(
195195 else :
196196 comment = "optional"
197197 else :
198- example = CommentedSeq ()
199- for index , entry in enumerate (inptype ):
198+ example , comment = generate_example_input (inptype [0 ], default )
199+ type_names = []
200+ for entry in inptype :
200201 value , e_comment = generate_example_input (entry , default )
201- example .append (value )
202- example .yaml_add_eol_comment (e_comment , index )
202+ if e_comment :
203+ type_names .append (e_comment )
204+ comment = "one of " + ", " .join (type_names )
203205 if optional :
204- comment = " optional"
206+ comment = f" { comment } ( optional) "
205207 elif isinstance (inptype , Mapping ) and "type" in inptype :
206208 if inptype ["type" ] == "array" :
207209 first_item = cast (MutableSequence [CWLObjectType ], inptype ["items" ])[0 ]
Original file line number Diff line number Diff line change 88def test_anonymous_record () -> None :
99 inputs = cmap ([{"type" : "record" , "fields" : []}])
1010 assert main .generate_example_input (inputs , None ) == ({}, "Anonymous record type." )
11+
12+
13+ def test_union () -> None :
14+ """Test for --make-template for a union type."""
15+ inputs = cmap (["string" , "string[]" ])
16+ assert main .generate_example_input (inputs , None ) == (
17+ "a_string" ,
18+ 'one of type "string", type "string[]"' ,
19+ )
20+
21+
22+ def test_optional_union () -> None :
23+ """Test for --make-template for an optional union type."""
24+ inputs = cmap (["null" , "string" , "string[]" ])
25+ assert main .generate_example_input (inputs , None ) == (
26+ "a_string" ,
27+ 'one of type "string", type "string[]" (optional)' ,
28+ )
You can’t perform that action at this time.
0 commit comments