adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

OpenAPI tools ignore operation- and path-level server overrides

Open sumedh-aerram opened this issue 3 weeks ago • 4 comments

Describe the bug OpenApiSpecParser always uses the root servers[0].url, even when a path item or an operation declares its own servers. Per the OpenAPI spec (Operation Object / Path Item Object), operation servers override path servers, and path servers override root servers. So every generated RestApiTool sends requests to the root server.

Root cause: openapi_spec_parser.py picks the root server once, outside the operation loop, and reuses it as base_url for every OperationEndpoint.

To reproduce (offline, on main)

from google.adk.tools.openapi_tool.openapi_spec_parser.openapi_spec_parser import OpenApiSpecParser
from google.adk.tools.openapi_tool.openapi_spec_parser.rest_api_tool import RestApiTool

spec = {'openapi': '3.0.0', 'info': {'title': 'demo', 'version': '1'},
        'servers': [{'url': 'https://root.example.test/v1'}],
        'paths': {'/items': {
            'servers': [{'url': 'https://path.example.test/v2'}],
            'get': {'operationId': 'listItems',
                    'servers': [{'url': 'https://operation.example.test/v3'}],
                    'responses': {'200': {'description': 'OK'}}},
            'post': {'operationId': 'addItem',
                     'responses': {'200': {'description': 'OK'}}}}}}

for parsed in OpenApiSpecParser().parse(spec):
  tool = RestApiTool.from_parsed_operation(parsed)
  request = tool._prepare_request_params(tool._operation_parser.get_parameters(), {})
  print(parsed.endpoint.method.upper(), request['url'])

Expected: GET https://operation.example.test/v3/items and POST https://path.example.test/v2/items.

Actual: both go to https://root.example.test/v1/items.

Environment: ADK main (2.14.0), Python 3.11, macOS. No model involved.

I'd like to send a fix: choose the server per operation (operation, then path, then root, keeping the current fallback when none is declared), with parser tests for each level.

sumedh-aerram avatar Nov 09 '26 19:11 sumedh-aerram

I'd like to take this one. I have a fix ready that resolves the base URL per operation in spec order (operation servers, then path servers, then root servers), with unit tests and an end-to-end check against local servers. I'll open a PR unless someone is already on it.

julienparenti avatar Nov 10 '26 21:11 julienparenti

Thanks @julienparenti. Since #8088 is already up, go ahead with it and I will drop mine. One case worth covering if it isn't already: an explicitly empty servers: [] on a path or operation should fall through to the next level rather than produce an empty base URL.

sumedh-aerram avatar Nov 11 '26 02:11 sumedh-aerram

Thanks @sumedh-aerram! Yes, an empty servers: [] falls through to the next level on both paths and operations. #8088 already tests the operation case, and I've just added test_empty_path_servers_fall_back_to_root_servers for the path case.

julienparenti avatar Nov 11 '26 08:11 julienparenti

Hi @sumedh-aerram, thanks for the report and repro.

I've confirmed this on main. #8088 from @julienparenti fixes it by picking the server for each operation in spec order: operation, then path, then root. Locally, your repro now gives the expected URLs, and the existing tool tests pass.

the PR is under review and will be merged once approved.

sanketpatil06 avatar Nov 12 '26 10:11 sanketpatil06