Skip to content

fix(client): serialize list query params with empty brackets - #69

Open
pravinireri wants to merge 1 commit into
anthropics:mainfrom
pravinireri:fix-list-query-params
Open

fix(client): serialize list query params with empty brackets#69
pravinireri wants to merge 1 commit into
anthropics:mainfrom
pravinireri:fix-list-query-params

Conversation

@pravinireri

Copy link
Copy Markdown

Summary

  • Serialize list-valued query parameters with repeated empty-bracket keys (types[]=a&types[]=b) instead of numeric indices (types[0]=a&types[1]=b).
  • Use the shared query serializer in both Util::joinUri() and RequestTransformer::build().

Tests

  • ./vendor/bin/pest tests/Core/UtilTest.php tests/Core/RequestTransformerTest.php tests/ClientTest.php
  • ./vendor/bin/pest against the Steady mock server — 187 passed
  • ./vendor/bin/phpstan analyse --memory-limit=12G — no errors

Fixes #67

@pravinireri
pravinireri requested a review from a team as a code owner August 17, 2026 18:24
Copilot AI lite review requested due to automatic review settings August 17, 2026 18:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the SDK’s query-string serialization to encode list-valued query parameters as repeated empty-bracket keys (types[]=a&types[]=b) instead of indexed keys (types[0]=a&types[1]=b), aligning with the API’s expected format and fixing the reported 400s for list query params.

Changes:

  • Added Util::encodeQuery() to serialize query params with RFC3986 escaping and list values as repeated key[]= pairs.
  • Switched both Util::joinUri() and RequestTransformer::build() to use the shared query serializer (removing reliance on http_build_query() for these paths).
  • Expanded test coverage to assert correct list serialization and preservation through request rebuilding and real client calls.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Core/UtilTest.php Updates existing expectations and adds focused tests for empty-bracket list encoding and encoding invariants.
tests/Core/RequestTransformerTest.php Adds regression test to ensure list query params keep empty brackets after transformer rebuild.
tests/ClientTest.php Adds end-to-end assertions that wire queries use empty brackets for list params (including extraQueryParams).
src/Core/Util.php Introduces encodeQuery() / encodeQueryPart() and switches joinUri() to the new serializer.
src/Core/RequestTransformer.php Switches request rebuild query serialization to Util::encodeQuery().

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Core/Util.php Outdated
http_build_query() emits numerically indexed keys for PHP lists
(types[0]=a&types[1]=b), which the API rejects with a 400; it expects
repeated empty-bracket pairs (types[]=a&types[]=b). Encode query params
with a helper that recognizes lists via array_is_list() and emits
key[]=value pairs, preserving associative keys, scalar encoding
(RFC3986), ordering, and merge behavior. Applies to both Util::joinUri
and RequestTransformer::build so rewritten Bedrock/Vertex requests keep
the same encoding.

Fixes anthropics#67
@pravinireri
pravinireri force-pushed the fix-list-query-params branch from 3b40cad to 85d0ffa Compare August 17, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List-type query params are serialised as types[0]= instead of types[]=, causing a 400

2 participants