11"""
22Converting the processed OpenAPI Responses into something the CLI can work with
33"""
4+ from openapi3 .paths import MediaType
5+
46from .colors import colorize_string
57
68
@@ -159,26 +161,35 @@ def _parse_response_model(schema, prefix=None, nested_list_depth=0):
159161 :returns: The list of parsed OpenAPIResponseAttr objects representing this schema
160162 :rtype: List[OpenAPIResponseAttr]
161163 """
162- attrs = []
163164
164- if schema .properties is not None :
165- for k , v in schema .properties .items ():
166- pref = prefix + "." + k if prefix else k
167-
168- if v .type == "object" :
169- 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- )
176- else :
177- attrs .append (
178- OpenAPIResponseAttr (
179- k , v , prefix = prefix , nested_list_depth = nested_list_depth
180- )
165+ if schema .type == "array" :
166+ return _parse_response_model (
167+ schema .items ,
168+ prefix = prefix ,
169+ nested_list_depth = nested_list_depth ,
170+ )
171+
172+ attrs = []
173+ if schema .properties is None :
174+ return attrs
175+
176+ for k , v in schema .properties .items ():
177+ pref = prefix + "." + k if prefix else k
178+
179+ if v .type == "object" :
180+ attrs += _parse_response_model (v , prefix = pref )
181+ elif v .type == "array" and v .items .type == "object" :
182+ attrs += _parse_response_model (
183+ v .items ,
184+ prefix = pref ,
185+ nested_list_depth = nested_list_depth + 1 ,
186+ )
187+ else :
188+ attrs .append (
189+ OpenAPIResponseAttr (
190+ k , v , prefix = prefix , nested_list_depth = nested_list_depth
181191 )
192+ )
182193
183194 return attrs
184195
@@ -189,7 +200,7 @@ class OpenAPIResponse:
189200 responses section of an OpenAPI Operation
190201 """
191202
192- def __init__ (self , response ):
203+ def __init__ (self , response : MediaType ):
193204 """
194205 :param response: The response's MediaType object in the OpenAPI spec,
195206 corresponding to the application/json response type
@@ -228,7 +239,9 @@ def fix_json(self, json):
228239 # Needs to go last to handle custom schemas
229240 if "pages" in json :
230241 return json ["data" ]
231- return [json ]
242+ if not isinstance (json , list ):
243+ json = [json ]
244+ return json
232245
233246 def _fix_json_rows (self , json ):
234247 """
0 commit comments