Skip to content

支持 OpenAPI 固定请求头参数#119

Merged
OhYee merged 1 commit into
Serverless-Devs:mainfrom
117503445:support-openapi-fixed-header-params
Jun 17, 2026
Merged

支持 OpenAPI 固定请求头参数#119
OhYee merged 1 commit into
Serverless-Devs:mainfrom
117503445:support-openapi-fixed-header-params

Conversation

@117503445

Copy link
Copy Markdown
Contributor

改动说明

  • 支持从 OpenAPI protocolSpec 中解析固定请求头参数:in: header + schema.const 字符串值。
  • 支持 in: header + 单值字符串 schema.enum 作为固定请求头。
  • 调用 OpenAPI remote tool 时自动合并 fixed headers,并按大小写不敏感规则覆盖已有 header。
  • 固定 header 不再暴露给工具参数,并在调用时过滤同名参数,避免误传到 query/body。
  • 明确边界:不支持 parameter $ref 解析为 fixed header;非字符串 const/enum 不解析为 fixed header。

验证

  • uv run pytest tests/unittests/tool/test_openapi.py -q
  • uv run pytest tests/unittests/tool -q
  • uv run pyink --check --config pyproject.toml agentrun/tool/api/openapi.py tests/unittests/tool/test_openapi.py
  • uv run isort --check-only agentrun/tool/api/openapi.py tests/unittests/tool/test_openapi.py
  • git diff --check -- agentrun/tool/api/openapi.py tests/unittests/tool/test_openapi.py

用户要求:从 OpenAPI protocolSpec 中解析字符串类型的 header 固定值,让 remote OpenAPI 工具调用时自动携带这些 header。

实现思路:
- 仅将 in: header 且 schema.const 为字符串的参数解析为 fixed_headers
- 仅将 in: header 且 schema.enum 只有一个字符串值的参数解析为 fixed_headers
- 调用工具时合并 fixed_headers,并过滤同名调用参数,避免误传到 query 或 body
- 明确不支持 parameter $ref 和非字符串固定值,并补充对应测试

Signed-off-by: 黑曜 <haotian.qht@alibaba-inc.com>
@117503445 117503445 force-pushed the support-openapi-fixed-header-params branch from 42d64b5 to f7ffb37 Compare June 16, 2026 16:36
@OhYee OhYee requested a review from Copilot June 17, 2026 02:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Not ready to approve

There are test-mocking and logging issues that can mask failures and potentially leak sensitive values in debug logs.

Pull request overview

This PR extends ToolOpenAPIClient to recognize “fixed” request headers from an OpenAPI protocol_spec (header parameters with schema.const or single-value string schema.enum), automatically apply them at call time, and ensure they are not exposed as tool inputs or accidentally forwarded into query/body payloads.

Changes:

  • Parse path-level + operation-level parameters together, extracting fixed header values into a new per-operation fixed_headers field.
  • Merge fixed headers into request headers with case-insensitive override and filter same-named entries out of call arguments before sending.
  • Add unit tests covering fixed header parsing (const/enum), non-string cases, $ref boundary, and sync/async call behavior.
File summaries
File Description
agentrun/tool/api/openapi.py Adds fixed-header extraction/merging/filtering logic and applies it in call_tool / call_tool_async.
tests/unittests/tool/test_openapi.py Adds coverage for fixed header parsing rules and header/argument behavior during invocation.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +966 to +970
mock_client_instance.__aenter__ = AsyncMock(
return_value=mock_client_instance
)
mock_client_instance.__aexit__ = AsyncMock()
mock_async_client_class.return_value = mock_client_instance
Comment on lines 448 to 450
logger.debug(
f"Calling FunctionCall tool: {method} {url} with args={arguments}"
)
Comment on lines 511 to 514
logger.debug(
f"Calling FunctionCall tool async: {method} {url} with"
f" args={arguments}"
)
@OhYee OhYee merged commit ea1cc03 into Serverless-Devs:main Jun 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants