Skip to content
Closed
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 @@ -609,6 +609,11 @@ async def call(
# Got all parameters. Call the API.
try:
request_params = self._prepare_request_params(api_params, api_args)
except KeyError as e:
missing_param = e.args[0] if e.args else str(e)
return self._format_error_response(
f"Missing required path parameter '{missing_param}'."
)
except InputValidationError as e:
return self._format_error_response(str(e))
if self._ssl_verify is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,50 @@ async def test_call_with_required_param_defaults(
assert call_kwargs["url"] == "https://example.com/users/me/messages"
assert result == {"result": "success"}

@patch(
"google.adk.tools.openapi_tool.openapi_spec_parser.rest_api_tool._request"
)
@pytest.mark.asyncio
async def test_call_missing_required_path_param_returns_error(
self,
mock_request,
mock_tool_context,
sample_auth_scheme,
sample_auth_credential,
):
"""A required path param with no default and no value must not crash."""
mock_operation = Operation(
operationId="test_op",
parameters=[
OpenAPIParameter(**{
"name": "userId",
"in": "path",
"required": True,
"schema": OpenAPISchema(type="string"),
})
],
)

tool = RestApiTool(
name="test_tool",
description="Test Tool",
endpoint=OperationEndpoint(
base_url="https://example.com",
path="/users/{userId}/messages",
method="GET",
),
operation=mock_operation,
auth_scheme=sample_auth_scheme,
auth_credential=sample_auth_credential,
)

# Call without providing userId and without a default to fall back on.
result = await tool.call(args={}, tool_context=mock_tool_context)

assert not mock_request.called
assert "error" in result
assert "userId" in result["error"]

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