@@ -196,6 +196,7 @@ def test_parse_args_object_list(self, create_operation):
196196 "field_int" : 123 ,
197197 "field_dict" : {"nested_string" : "test2" , "nested_int" : 789 },
198198 "field_array" : ExplicitJsonValue (json_value = ["foo" , "bar" ]),
199+ "field_object_array" : None , # We expect this to be filtered out later
199200 "nullable_string" : None , # We expect this to be filtered out later
200201 },
201202 {"field_int" : 456 , "field_dict" : {"nested_string" : "test3" }},
@@ -218,6 +219,54 @@ def test_parse_args_object_list_json(self, create_operation):
218219
219220 assert result .object_list .json_value == expected
220221
222+ def test_nested_object_list_treated_as_json (self , create_operation ):
223+ """
224+ An array of objects nested within another array of objects (e.g.
225+ --object_list.field_object_array) can only be specified as JSON.
226+ It should not be expanded into unusable child arguments (e.g.
227+ --object_list.field_object_array.nested_object_string).
228+ """
229+ args_by_path = {arg .path : arg for arg in create_operation .args }
230+
231+ nested = args_by_path .get ("object_list.field_object_array" )
232+ assert nested is not None
233+ assert nested .format == "json"
234+ assert nested .datatype == "object"
235+ assert nested .is_child
236+ assert nested .parent == "object_list"
237+ assert not nested .is_parent
238+
239+ # No child arguments should have been generated for its properties.
240+ assert "object_list.field_object_array.nested_object_string" not in (
241+ args_by_path
242+ )
243+ assert "object_list.field_object_array.nested_object_int" not in (
244+ args_by_path
245+ )
246+
247+ def test_parse_args_nested_object_list_json (self , create_operation ):
248+ """
249+ A nested array of objects should be accepted as a JSON string value
250+ associated with each entry of its parent list.
251+ """
252+ result = create_operation .parse_args (
253+ [
254+ "--object_list.field_string" ,
255+ "test1" ,
256+ "--object_list.field_object_array" ,
257+ json .dumps ([{"nested_object_string" : "foo" }]),
258+ ]
259+ )
260+
261+ assert result .object_list == [
262+ {
263+ "field_string" : "test1" ,
264+ "field_object_array" : ExplicitJsonValue (
265+ json_value = [{"nested_object_string" : "foo" }]
266+ ),
267+ },
268+ ]
269+
221270 def test_parse_args_conflicting_parent_child (self , create_operation ):
222271 stderr_buf = io .StringIO ()
223272
0 commit comments