fix(openapi): let operation parameters override path-level ones - #7209
1aifanatic wants to merge 3 commits into
Conversation
_collect_operations() appended every path-level parameter to each operation's parameters. An operation-level parameter with the same name and location overrides the path-level one (OpenAPI Path Item Object), so keeping both asked the model for the same path value twice, as account_id and account_id_0. Both map to the same placeholder, and the path-level value won, dropping the operation's more specific parameter. Skip path-level parameters whose (name, in) the operation already declares. Fixes google#7205 Claude-Session: https://claude.ai/code/session_013vXxD1ga1hnCq2uFRwNks7
OpenAPI mandates `required: true` on every path parameter, but the parser took the flag as written and defaulted it to false. A spec that leaves it out, including an operation-level override of a required path-level parameter, declared the path parameter optional, so a model could omit it and the request failed with KeyError while building the URL. Treat `in: path` parameters as required regardless of the flag; query, header and cookie parameters keep the operation's own value. Claude-Session: https://claude.ai/code/session_013vXxD1ga1hnCq2uFRwNks7
|
@llalitkumarrr thanks for testing, and good catch on that edge case (from #7205). For a path parameter the flag can't legitimately be false. The OpenAPI spec says I've pushed da60abc so that With the override leaving out New test: |
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
OpenApiSpecParser._collect_operations()appended every path-level parameter to each operation's own parameters. Per the OpenAPI 3 Path Item Object, an operation-level parameter with the samenameandinoverrides the path-level one. Keeping both made the tool ask the model for the same path value twice (account_idandaccount_id_0, both required). Both map to the same{accountId}placeholder, and the path-level value won, so the operation's own, more specific parameter was dropped from the request.Solution:
Skip path-level parameters whose
(name, in)the operation already declares. Parameters with the same name but a different location are still merged. References are resolved before this step, so parameters are plain dicts here; anything without anameis left untouched.Testing Plan
Unit Tests:
test_openapi_spec_parser.py::test_parse_spec_operation_parameter_overrides_path_level_parameter: the pathaccountIdis overridden and keeps the operation's description, while a same-namedheaderparameter is still merged. Fails onmain.Every failure outside the new tests also fails on an unmodified
origin/main(3f4bb8f) on the same machine, where the same run gives 47 failed. Most are deterministic Windows-specific tests (cli/deploy, conformance,scripts/check_new_py_files, path normalization, the unsafe local code executor, the import allowlist, yaml). The remainder differ between runs: telemetry functional/node-functional schema cases, andstreaming/test_streaming_tool_events.py::test_delivered_event_carries_the_message_and_nothing_else, which failed 1/10 in isolation on cleanmainversus 2/10 on this branch. I ran on Python 3.12 only, not the fulltoxmatrix.Manual End-to-End (E2E) Tests:
An
OpenAPIToolsetwhose/accounts/{accountId}path declaresaccountIdand whoseGEToverrides it; HTTP goes to anhttpx.MockTransport. The script is in #7205.Before (
main@ 3f4bb8f):After:
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_013vXxD1ga1hnCq2uFRwNks7