.Net: Python: Bug: OpenAPI plugin sends array and boolean query parameters as Python repr (tags=['a', 'b'], active=True)

未关闭
#14,788 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@jeevan1098 已经在做这个了。

开始于 2026年11月12日。

  • #14789 来自 @jeevan1098 —— 未关闭
  • #14800 来自 @DYNOSuprovo —— 未关闭

评估

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

调研方向

Start with python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py, especially the query, header, and path parameter handling cited in the issue, and check how the .NET OpenAPI plugin serializes arrays. Use the offline httpx.MockTransport reproduction to inspect the captured URL. Done means array query values use repeated keys and booleans are lowercase; account for the linked open pull request before starting.

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

描述

.NET python triage

Describe the bug

The OpenAPI plugin builds the query string with urlencode(segments) and passes argument values through unchanged:

https://github.com/microsoft/semantic-kernel/blob/25bd1bb67c38976bb13958783572efa57d3445d4/python/semantic_kernel/connectors/openapi_plugin/models/rest_api_operation.py#L386-L400

Without doseq=True, urlencode calls str() on each value. So an array query parameter is sent as Python's list repr (['red', 'blue']), and a boolean is sent as True/False. APIs can't parse either. OpenAPI's default for query parameters is style: form, explode: true, which means tags=red&tags=blue and active=true. The .NET OpenAPI plugin already serializes arrays this way.

The schema advertised to the model says {"type": "array", "items": {"type": "string"}}, so a tool call from the model hits this.

Header and path parameters have the same problem, since they use str(argument) (L218, L331).

To Reproduce

semantic-kernel 1.47.0. rest_api_operation.py is the same on main (25bd1bb6). This runs offline: httpx.MockTransport captures the request, and the server is an IP literal so the URL validator doesn't need DNS.

import asyncio, httpx
from semantic_kernel import Kernel
from semantic_kernel.connectors.openapi_plugin import OpenAPIFunctionExecutionParameters

spec = {
    "openapi": "3.0.1", "info": {"title": "t", "version": "1"},
    "servers": [{"url": "https://93.184.216.34"}],
    "paths": {"/items": {"get": {
        "operationId": "listItems",
        "parameters": [
            {"name": "tags", "in": "query", "schema": {"type": "array", "items": {"type": "string"}}},
            {"name": "active", "in": "query", "schema": {"type": "boolean"}},
        ],
        "responses": {"200": {"description": "ok"}},
    }}},
}

seen = []
def handler(request):
    seen.append(str(request.url))
    return httpx.Response(200, json={})

async def main():
    client = httpx.AsyncClient(transport=httpx.MockTransport(handler))
    kernel = Kernel()
    plugin = kernel.add_plugin_from_openapi(
        "api", openapi_parsed_spec=spec,
        execution_settings=OpenAPIFunctionExecutionParameters(http_client=client),
    )
    await kernel.invoke(plugin["listItems"], tags=["red", "blue"], active=True)
    print(seen[0])

asyncio.run(main())

Output:

https://93.184.216.34/items?tags=%5B%27red%27%2C+%27blue%27%5D&active=True

Expected behavior

https://93.184.216.34/items?tags=red&tags=blue&active=true

(form/explode, the OpenAPI default for query parameters), with booleans written as JSON true/false.

Platform

  • Language: Python
  • Source: semantic-kernel 1.47.0 (pip) / main at 25bd1bb6
  • AI model: n/a (no model call needed)
  • IDE: n/a
  • OS: Windows 11, Python 3.12

Additional context

The parser doesn't read style/explode from the spec yet (RestApiParameter is always built without them), so the smallest fix is to serialize lists as repeated keys (doseq=True) and booleans as lowercase. Happy to send a fix if that helps.

主要语言
C#
星标
28.8k
派生
4.9k
平均合并
2 天 17 小时
30 天内合并 PR
48

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

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

microsoft/semantic-kernel 的其他 Issue

查看 microsoft/semantic-kernel 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

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