Repository navigation
Description
Describe the bug
OpenApiParser.create_rest_api_operations treats every key of an OpenAPI path item as an HTTP method. A path item can also carry summary, description, servers and parameters (shared by all operations on that path). With any of these present, loading the plugin fails with operationId missing, and the shared parameters are never applied to the operations.
The .NET side already fixed the same class of problem (#8268, #8269, #9962). The Python parser still has it.
Where
python/semantic_kernel/connectors/openapi_plugin/openapi_parser.py, create_rest_api_operations:
for path, methods in paths.items():
for method, details in methods.items():
request_method = method.lower()
# Validate that operationId exists
if "operationId" not in details:
raise PluginInitializationError(f"operationId missing, path: '{path}', method: '{method}'")
...
parameters = details.get("parameters", [])
parsed_params = self._parse_parameters(parameters)methods.items() also yields ("parameters", [...]), ("summary", "...") and so on, and only details.get("parameters") of the operation is used.
To reproduce
Checked on current main (1b1f64b).
from semantic_kernel import Kernel
spec = {
"openapi": "3.0.1",
"info": {"title": "t", "version": "1"},
"servers": [{"url": "https://api.example.com"}],
"paths": {
"/items/{id}": {
"summary": "Item",
"parameters": [{"name": "id", "in": "path", "required": True, "schema": {"type": "string"}}],
"get": {"operationId": "getItem", "responses": {"200": {"description": "ok"}}},
"delete": {"operationId": "deleteItem", "responses": {"200": {"description": "ok"}}},
}
},
}
Kernel().add_plugin_from_openapi(plugin_name="api", openapi_parsed_spec=spec)Actual:
PluginInitializationError: operationId missing, path: '/items/{id}', method: 'summary'
If I remove summary and keep only the shared parameters, the error is the same with method: 'parameters'. Shared path parameters are very common in real specs (the {id} path parameter is declared once for get, put and delete).
Expected
- Keys that are not HTTP methods (
summary,description,servers,parameters,$ref,x-*) are skipped. - Path item
parametersare merged into each operation, and an operation level parameter with the samenameandinoverrides the path level one (OpenAPI 3.0 spec, "Path Item Object").
After a fix, the repro should load getItem and deleteItem, each with the required id parameter.
I have a fix with tests ready and will open a PR for this.
Platform
- Language: Python
- Source: main branch of the repository (1b1f64b)
Activity
[-]Python: Bug: OpenAPI plugin load fails with 'operationId missing' when a path item has parameters, summary or description[/-][+].Net: Python: Bug: OpenAPI plugin load fails with 'operationId missing' when a path item has parameters, summary or description[/+][-].Net: Python: Bug: OpenAPI plugin load fails with 'operationId missing' when a path item has parameters, summary or description[/-][+]Python: Bug: OpenAPI plugin load fails with 'operationId missing' when a path item has parameters, summary or description[/+]Python: feat: support path item parameters and non-method keys in Ope…