Repository navigation
fix(tools): send array query parameters as repeated keys in RestApiTool - #1135
Open
OsamaAnsar wants to merge 1 commit into
Open
OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
RestApiTool stringified every query value with String(), so an array [1, 2, 3] became id=1%2C2%2C3 and an object became [object Object]. OpenAPI query parameters default to style: form, explode: true, and adk-python hands lists to httpx, which repeats the key. Append one pair per array element (skipping null/undefined, nothing for an empty array) and JSON-encode objects.
Contributor
|
Hi @OsamaAnsar, thank you for raising the PR to fix the issue. We have reviewed the code changes and it does resolve the issue. I will escalate the PR to the team to review, thank you for your patience and understanding. |
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):
No existing issue found (searched open and closed issues and PRs for
rest_api_tool, query parameter, array, explode).2. Or, if no issue exists, describe the change:
Problem:
prepareRequestParamsincore/src/tools/openapi_tool/rest_api_tool.tsdoesqueryParams.append(originalName, String(argValue))for every query parameter, so non-scalar values are mangled:[1, 2, 3]becomes?id=1%2C2%2C3(one comma-joined value){a: 1}becomes?filter=%5Bobject+Object%5D, which is[object Object]OpenAPI 3.0 query parameters default to
style: form,explode: true, which serializes an array asid=1&id=2&id=3. adk-python passes the list to httpx, which repeats the key the same way (checked with httpx 0.28.1:{'id': [1, 2, 3]}gives?id=1&id=2&id=3). The existing parity tests only cover an array request body, not an array query parameter.Solution:
A small
appendQueryParamhelper inrest_api_tool.ts:name=valuepair per element.nullandundefinedelements are skipped and an empty array sends nothing (httpx does the same for an empty list).JSON.stringify, instead of[object Object].String(value)).Why JSON for objects: adk-python only gets a result here by accident (httpx sends the Python
repr,filter=%7B%27a%27%3A+1%7D), so there is nothing to match. The spec default for an object would bea=1, which drops the parameter name and can collide with other parameters. JSON keeps the parameter name and is lossless.ApiParameterdoes not carrystyle/explode, so those are not honoured; this PR only makes the default (form,explode: true) correct and does not add other styles.Path parameters are untouched (#638 is the separate path-encoding fix).
Testing Plan
Unit Tests:
Added a
query parameter serializationblock (8 tests) tocore/test/tools/openapi_tool/rest_api_tool_test.ts.Before/after, calling
prepareRequestParamsdirectly:With only the
rest_api_tool.tschange reverted, 7 of the 8 new tests fail (the 8th, the scalar regression guard, passes either way); with the change restored the wholecore/test/tools/openapi_tooldirectory passes (19 files, 549 tests).prettier --checkandeslintare clean on the touched files.vitest run --project unit:coreon my Windows machine: 5608 passed, 2 failed. The 2 failures (core/test/utils/file_utils_test.tsdangling symlink,core/test/cli/utils/logs_test.tssymlink) areEPERM: operation not permitted, symlinkand fail the same way on an unmodifiedmain; I did not run them on Linux or macOS. Because of this I left "All unit tests pass locally" unticked.Manual End-to-End (E2E) Tests:
Not run against a live API. I only exercised
prepareRequestParams(and thereby the URL it builds); I did not send a request to a real server, and did not runtest:integration/test:e2e.Checklist
Additional context
Behaviour change to be aware of: an array query value previously reached the server as one comma-joined value (
id=1,2,3); it is now repeated keys. A server that relied on the comma form (style: form, explode: false) would need that style supported separately.