fix(openapi): honor query parameter style and explode - #7208
Open
1aifanatic wants to merge 1 commit into
Open
1aifanatic wants to merge 1 commit into
1aifanatic wants to merge 1 commit into
Conversation
RestApiTool passed query values to httpx as the model produced them and
ApiParameter did not record the spec's style/explode. httpx repeats the
key for a list, which only matches the default for arrays, and sends a
dict as its Python repr, so every object-typed query parameter went out
as e.g. filter={'status': 'open'}. Non-exploded and delimited arrays
were exploded as well.
Carry style and explode from the spec's Parameter into ApiParameter
(optional fields, so serialized parameters still load) and serialize
query values per OpenAPI: objects are spread (form, exploded, the
default), bracketed (deepObject) or k,v-joined (form, not exploded), and
non-exploded arrays are joined with ",", " " or "|". Scalars and default
arrays are unchanged.
Fixes google#7204
Claude-Session: https://claude.ai/code/session_013vXxD1ga1hnCq2uFRwNks7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
RestApiToolpassed query values to httpx as the model produced them, andApiParameterdid not record the spec'sstyle/explode. httpx repeats the key for a list, which only matches the default for arrays, and sends a dict as its Python repr. So every object-typed query parameter went out asfilter={'status': 'open'}, and non-exploded or delimited arrays were exploded.Solution:
ApiParametergets optionalstyleandexplodefields (defaultNone, so serializedParsedOperations still load), andOperationParsercopies them from the spec'sParameter._serialize_query_param()applies them to query values, following OpenAPI 3:form, exploded, the default), bracketed (deepObject), ork,v,...(form, not exploded);,(form),(spaceDelimited), or|(pipeDelimited);Testing Plan
Unit Tests:
I have added or updated unit tests for my change.
All unit tests pass locally.
test_rest_api_tool.py::TestRestApiTool::test_prepare_request_params_query_style_and_explode, parametrized over the style/explode/type combinations above. The 6 serialization cases fail onmain; the default-array and scalar cases are controls and pass on both.test_operation_parser.py::test_process_operation_parameters_keeps_style_and_explodefails 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:
A real
Runner+LlmAgent+OpenAPIToolsetwhose spec has a default-style object param, adeepObjectparam, and aform/explode: falsearray, with a mocked model and anhttpx.MockTransportbackend. The script is in #7204.Before (
main@ 3f4bb8f):After:
Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_013vXxD1ga1hnCq2uFRwNks7