MCPcopy
hub / github.com/intruder-io/autoswagger / build_nested_object

Function build_nested_object

autoswagger.py:291–311  ·  view source on GitHub ↗

Recursively constructs a nested object (dict) for complex schemas. Handles properties, arrays, and composite references (oneOf, anyOf, allOf).

(schema, value_index=0)

Source from the content-addressed store, hash-verified

289 return TEST_VALUES.get(param_type, TEST_VALUES["default"])
290
291def build_nested_object(schema, value_index=0):
292 """
293 Recursively constructs a nested object (dict) for complex schemas.
294 Handles properties, arrays, and composite references (oneOf, anyOf, allOf).
295 """
296 obj = {}
297 for key, prop in schema.get('properties', {}).items():
298 if '$ref' in prop:
299 continue
300 if 'oneOf' in prop or 'anyOf' in prop or 'allOf' in prop:
301 obj[key] = handle_composite_schemas(prop, value_index)
302 elif prop.get('type') == 'object':
303 obj[key] = build_nested_object(prop, value_index)
304 elif prop.get('type') == 'array':
305 obj[key] = build_array_item(prop, value_index)
306 else:
307 param_type = prop.get('type', 'string')
308 enum = prop.get('enum', None)
309 values = generate_parameter_values(param_type, enum)
310 obj[key] = values[value_index % len(values)]
311 return obj
312
313def handle_composite_schemas(schema, value_index=0):
314 """

Callers 3

handle_composite_schemasFunction · 0.85
build_array_itemFunction · 0.85
build_request_bodyFunction · 0.85

Calls 3

handle_composite_schemasFunction · 0.85
build_array_itemFunction · 0.85

Tested by

no test coverage detected