OpenAPI tools ignore operation- and path-level server overrides

未关闭 适合新手
#8,064 4 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 3 天内回复

@sanketpatil06 已经在做这个了。

开始于 2026年11月12日。

  • #8088 来自 @julienparenti —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api

调研方向

基础 URL 会从 openapi_spec_parser.py 中根级的 servers 列表一次性选出,位于 OpenApiSpecParser.parse 中逐个操作的循环之外,并被每个 OperationEndpoint 复用。请先阅读该循环,然后阅读 rest_api_tool.py 中 RestApiTool.from_parsed_operation 和 _prepare_request_params 的请求构建逻辑,并运行 issue 中的复现脚本。完成的标准是:带有操作级服务器的 GET 使用该服务器;只带路径级服务器的 POST 使用该服务器;未声明的情况仍回退到根服务器;解析器测试覆盖每一层级。

由索引模型根据 Issue 内容生成。

描述

tools

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.

主要语言
Python
星标
22.3k
派生
4.4k
平均合并
1 天 2 小时
30 天内合并 PR
6

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/adk-python 的其他 Issue

查看 google/adk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。