Builds a request body based on the schema and specified content type. Supports JSON, XML, form-encoded, plain text, octet-stream, and multipart.
(schema, content_type, value_index=0)
| 350 | return None |
| 351 | |
| 352 | def build_request_body(schema, content_type, value_index=0): |
| 353 | """ |
| 354 | Builds a request body based on the schema and specified content type. |
| 355 | Supports JSON, XML, form-encoded, plain text, octet-stream, and multipart. |
| 356 | """ |
| 357 | if not schema: |
| 358 | return None |
| 359 | |
| 360 | if 'oneOf' in schema or 'anyOf' in schema or 'allOf' in schema: |
| 361 | body = handle_composite_schemas(schema, value_index) |
| 362 | elif schema.get('type') == 'array': |
| 363 | item_schema = schema.get('items', {}) |
| 364 | body = [build_array_item(item_schema, value_index)] |
| 365 | elif schema.get('type') == 'object': |
| 366 | body = build_nested_object(schema, value_index) |
| 367 | else: |
| 368 | param_type = schema.get('type', 'string') |
| 369 | enum = schema.get('enum', None) |
| 370 | values = generate_parameter_values(param_type, enum) |
| 371 | body = values[value_index % len(values)] |
| 372 | |
| 373 | if content_type == 'application/x-www-form-urlencoded': |
| 374 | return urlencode(body) |
| 375 | elif content_type == 'application/xml': |
| 376 | return dicttoxml(body).decode() |
| 377 | elif content_type == 'application/json': |
| 378 | return json.dumps(body) |
| 379 | elif content_type == 'text/plain': |
| 380 | return str(body) |
| 381 | elif content_type == 'application/octet-stream': |
| 382 | return b'\x00\x01\x02' |
| 383 | elif content_type == 'multipart/form-data': |
| 384 | return build_file_upload_body(schema, content_type, value_index) |
| 385 | return json.dumps(body) |
| 386 | |
| 387 | def substitute_path_parameters(path, parameters, value_mapping): |
| 388 | """ |