@@ -27,7 +27,7 @@ class OpenAPIResponseAttr:
2727 from it.
2828 """
2929
30- def __init__ (self , name , schema , prefix = None ):
30+ def __init__ (self , name , schema , prefix = None , nested_list_depth = 0 ):
3131 """
3232 :param name: The key that held this schema in the properties list, representing
3333 its name in a response.
@@ -37,13 +37,19 @@ def __init__(self, name, schema, prefix=None):
3737 :param prefix: The json path style prefix (dot notation) to this schema
3838 in the response object
3939 :type prefix: str
40+ :param nested_list_depth: The number of nested lists this attribute is nested in.
41+ :type: nested_list_depth: int
4042 """
4143 #: The name of this attribute, which is the full json path to it within the schema
4244 self .name = name if prefix is None else prefix + "." + name
4345
4446 #: If this attribute is filterable in GET requests
4547 self .filterable = schema .extensions .get ("linode-filterable" )
4648
49+ #: The depth of this nested attribute in lists. This is necessary to prevent displaying
50+ #: list nested items in normal tables.
51+ self .nested_list_depth = nested_list_depth
52+
4753 #: The description of this argument, for help display. Only used for filterable attributes.
4854 self .description = (
4955 schema .description .split ("." )[0 ] if schema .description else ""
@@ -90,8 +96,14 @@ def _get_value(self, model):
9096 """
9197 value = model
9298 for part in self .name .split ("." ):
93- if value is None or value == {}:
99+ if (
100+ value is None
101+ or value == {}
102+ or isinstance (value , list )
103+ or part not in value
104+ ):
94105 return None
106+
95107 value = value [part ]
96108 return value
97109
@@ -133,7 +145,7 @@ def get_string(self, model):
133145 return value
134146
135147
136- def _parse_response_model (schema , prefix = None ):
148+ def _parse_response_model (schema , prefix = None , nested_list_depth = 0 ):
137149 """
138150 Recursively parses all properties of this schema to create a flattened set of
139151 OpenAPIResponseAttr objects that allow the CLI to display this response in a
@@ -142,18 +154,31 @@ def _parse_response_model(schema, prefix=None):
142154 become a new OpenAPIResponseAttr instance, and this process is
143155 recursive to include the properties of properties and so on.
144156 :type schema: openapi3.Schema
157+ :param nested_list_depth: The number of nested lists this attribute is nested in.
158+ :type: nested_list_depth: int
145159 :returns: The list of parsed OpenAPIResponseAttr objects representing this schema
146160 :rtype: List[OpenAPIResponseAttr]
147161 """
148162 attrs = []
149163
150164 if schema .properties is not None :
151165 for k , v in schema .properties .items ():
166+ pref = prefix + "." + k if prefix else k
167+
152168 if v .type == "object" :
153- pref = prefix + "." + k if prefix else k
154169 attrs += _parse_response_model (v , prefix = pref )
170+ elif v .type == "array" and v .items .type == "object" :
171+ attrs += _parse_response_model (
172+ v .items ,
173+ prefix = pref ,
174+ nested_list_depth = nested_list_depth + 1 ,
175+ )
155176 else :
156- attrs .append (OpenAPIResponseAttr (k , v , prefix = prefix ))
177+ attrs .append (
178+ OpenAPIResponseAttr (
179+ k , v , prefix = prefix , nested_list_depth = nested_list_depth
180+ )
181+ )
157182
158183 return attrs
159184
@@ -189,6 +214,7 @@ def __init__(self, response):
189214 self .attrs = _parse_response_model (response .schema )
190215 self .rows = response .extensions .get ("linode-cli-rows" )
191216 self .nested_list = response .extensions .get ("linode-cli-nested-list" )
217+ self .subtables = response .extensions .get ("linode-cli-subtables" )
192218
193219 def fix_json (self , json ):
194220 """
0 commit comments