@@ -9,7 +9,7 @@ class OpenAPIRequestArg:
99 """
1010
1111 def __init__ (
12- self , name , schema , required , prefix = None , list_item = False
12+ self , name , schema , required , prefix = None , list_parent = None
1313 ): # pylint: disable=too-many-arguments
1414 """
1515 Parses a single Schema node into a argument the CLI can use when making
@@ -60,7 +60,12 @@ def __init__(
6060 self .item_type = None
6161
6262 #: Whether the argument is a field in a nested list.
63- self .list_item = list_item
63+ self .list_item = list_parent is not None
64+
65+ #: The name of the list this argument falls under.
66+ #: This allows nested dictionaries to be specified in lists of objects.
67+ #: e.g. --interfaces.ipv4.nat_1_1
68+ self .list_parent = list_parent
6469
6570 #: The path of the path element in the schema.
6671 self .prefix = prefix
@@ -80,7 +85,7 @@ def __init__(
8085 )
8186
8287
83- def _parse_request_model (schema , prefix = None , list_of_objects = False ):
88+ def _parse_request_model (schema , prefix = None , list_parent = None ):
8489 """
8590 Parses a schema into a list of OpenAPIRequest objects
8691 :param schema: The schema to parse as a request model
@@ -102,7 +107,9 @@ def _parse_request_model(schema, prefix=None, list_of_objects=False):
102107 if v .type == "object" and not v .readOnly and v .properties :
103108 # nested objects receive a prefix and are otherwise parsed normally
104109 pref = prefix + "." + k if prefix else k
105- args += _parse_request_model (v , prefix = pref )
110+ args += _parse_request_model (
111+ v , prefix = pref , list_parent = list_parent
112+ )
106113 elif (
107114 v .type == "array"
108115 and v .items
@@ -113,7 +120,7 @@ def _parse_request_model(schema, prefix=None, list_of_objects=False):
113120 # of the object in the list is its own argument
114121 pref = prefix + "." + k if prefix else k
115122 args += _parse_request_model (
116- v .items , prefix = pref , list_of_objects = True
123+ v .items , prefix = pref , list_parent = pref
117124 )
118125 else :
119126 # required fields are defined in the schema above the property, so
@@ -124,7 +131,7 @@ def _parse_request_model(schema, prefix=None, list_of_objects=False):
124131 required = k in schema .required
125132 args .append (
126133 OpenAPIRequestArg (
127- k , v , required , prefix = prefix , list_item = list_of_objects
134+ k , v , required , prefix = prefix , list_parent = list_parent
128135 )
129136 )
130137
0 commit comments