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 摘要。