Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,10 @@ def _prepare_request_params(
schema = media_type_object.schema_
body_data = None

if schema.type == "object":
# OpenAPI allows a media type with no schema (e.g.
# application/octet-stream: {}). Treat a missing schema like a
# non-object so the single body parameter is sent as raw data.
if schema is not None and schema.type == "object":
body_data = {}
for param in parameters:
if param.param_location == "body" and param.py_name in kwargs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,41 @@ def test_prepare_request_params_octet_stream(
request_params["headers"]["Content-Type"] == "application/octet-stream"
)

def test_prepare_request_params_octet_stream_without_schema(
self, sample_endpoint, sample_auth_scheme, sample_auth_credential
):
"""Media types with no schema still send the body (OpenAPI allows {})."""
mock_operation = Operation(
operationId="upload_contract",
requestBody=RequestBody(
content={"application/octet-stream": MediaType()}
),
)
tool = RestApiTool(
name="upload_contract",
description="upload",
endpoint=sample_endpoint,
operation=mock_operation,
auth_credential=sample_auth_credential,
auth_scheme=sample_auth_scheme,
)
params = [
ApiParameter(
original_name="",
py_name="body",
param_location="body",
param_schema=OpenAPISchema(),
)
]
kwargs = {"body": b"%PDF-1.7"}

request_params = tool._prepare_request_params(params, kwargs)

assert request_params["data"] == b"%PDF-1.7"
assert (
request_params["headers"]["Content-Type"] == "application/octet-stream"
)

def test_prepare_request_params_path_param(
self, sample_endpoint, sample_auth_credential, sample_auth_scheme
):
Expand Down
Loading