Skip to content

fix(schema): expose repeated field and expand array query params#415

Open
anshul-garg27 wants to merge 4 commits intogoogleworkspace:mainfrom
anshul-garg27:fix/schema-repeated-and-array-params
Open

fix(schema): expose repeated field and expand array query params#415
anshul-garg27 wants to merge 4 commits intogoogleworkspace:mainfrom
anshul-garg27:fix/schema-repeated-and-array-params

Conversation

@anshul-garg27
Copy link
Contributor

Summary

Two related fixes for repeated/array query parameters:

  1. Schema output: gws schema now includes "repeated": true in parameter output when the Discovery Document marks a parameter as repeated
  2. Array expansion: When --params contains a JSON array for a repeated parameter, the executor expands it into multiple query parameters instead of stringifying the array

Problem

gws schema gmail.users.messages.get showed metadataHeaders as string with no indication it accepts multiple values. Passing {"metadataHeaders": ["Subject", "Date"]} had no effect because the array was stringified as a single value.

Solution

Schema (src/schema.rs):

+ if param.repeated {
+     p["repeated"] = json!(true);
+ }

Executor (src/executor.rs):

  • Changed query_params from HashMap<String, String> to Vec<(String, String)> to support multiple entries with the same key
  • When a parameter is repeated: true and the value is a JSON array, each element becomes a separate query parameter entry

Before: ?metadataHeaders=["Subject","Date","From"] (ignored by API)
After: ?metadataHeaders=Subject&metadataHeaders=Date&metadataHeaders=From

Test plan

  • Added test: param_to_json with repeated: true includes field in output
  • Added test: param_to_json with repeated: false omits field
  • Added test: build_url expands JSON array into repeated query params
  • Updated existing query param test for new Vec<(String, String)> type

Closes #300

Two related fixes for repeated/array query parameters:

1. `gws schema` now includes `"repeated": true` in parameter output
   when the Discovery Document marks a parameter as repeated. This
   lets users know which params accept multiple values.

2. When `--params` contains a JSON array for a parameter marked
   `repeated: true`, the executor now expands it into multiple
   query parameters (e.g. `?h=Subject&h=Date&h=From`) instead of
   stringifying the array as a single value.

The query_params type changes from HashMap<String, String> to
Vec<(String, String)> to support multiple entries with the same key.

Closes googleworkspace#300
@changeset-bot
Copy link

changeset-bot bot commented Mar 11, 2026

🦋 Changeset detected

Latest commit: fe787dd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@googleworkspace-bot googleworkspace-bot added area: http area: core Core CLI parsing, commands, error handling, utilities labels Mar 11, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where repeated query parameters were not correctly handled, leading to API calls failing or behaving unexpectedly. By enhancing both the schema representation and the query parameter processing logic, the CLI now accurately communicates and executes requests involving repeated fields, improving reliability and usability for developers interacting with APIs that utilize such parameters.

Highlights

  • Schema Output Enhancement: The gws schema command now accurately reflects repeated: true in parameter output when the Discovery Document indicates a parameter is repeated, providing clearer API contract information.
  • Array Query Parameter Expansion: The executor now correctly expands JSON arrays provided via --params for repeated parameters into multiple query parameters (e.g., ?key=val1&key=val2) instead of stringifying the entire array as a single value.
Changelog
  • .changeset/schema-repeated-array-params.md
    • Added a new changeset file documenting the feature and fix.
  • src/executor.rs
    • Changed the query_params field in the ExecutionInput struct from HashMap<String, String> to Vec<(String, String)> to allow for multiple query parameters with the same key.
    • Updated the build_url function signature to return Result<(String, Vec<(String, String)>), GwsError>.
    • Modified build_url to initialize query_params as a Vec instead of a HashMap.
    • Removed the previous generic stringification logic for query parameter values.
    • Implemented new logic within build_url to detect repeated parameters and, if the value is a JSON array, expand each array element into a separate (key, value) tuple in the query_params vector.
    • Added a new test case, test_build_url_repeated_query_param_expands_array, to verify the correct expansion of JSON arrays for repeated parameters.
    • Updated existing test assertions for build_url to reflect the change from HashMap to Vec for query parameters.
    • Modified query_params initialization in various test ExecutionInput structs from HashMap::new() to Vec::new().
  • src/schema.rs
    • Added a conditional block in param_to_json to include a "repeated": true field in the JSON output if the MethodParameter's repeated property is true.
    • Added a new test case, test_param_to_json_repeated, to specifically verify that repeated: true is correctly added to the JSON output for repeated parameters.
    • Updated the test_param_to_json_full test to assert that the repeated field is absent when a parameter is not repeated.
Activity
  • Added new test cases to validate the correct handling of repeated parameters in schema output.
  • Added a new test case to verify the expansion of JSON arrays into multiple query parameters for repeated fields.
  • Updated existing query parameter tests to align with the new Vec<(String, String)> type for query parameters.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly implements support for repeated query parameters by changing query_params from a HashMap to a Vec<(String, String)> and expanding array values for repeated fields. The schema output is also updated to expose the repeated property. The changes are well-tested. I've added one suggestion to improve validation by providing a clearer error message when a user incorrectly passes an array for a non-repeated parameter, which will prevent confusing API errors.

Address review feedback: print a warning to stderr when a JSON array
is provided for a parameter not marked as repeated, since the array
will be stringified rather than expanded. Directs users to gws schema
to check which parameters accept arrays.
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully implements the exposure of the repeated field in gws schema output and expands JSON arrays into multiple query parameters for repeated fields. The changes are well-contained within src/executor.rs and src/schema.rs, with appropriate updates to existing tests and the addition of new tests to cover the new functionality. The code is clear and directly addresses the described problem, enhancing the CLI's capability to handle complex API parameters correctly.

The test `test_build_url_repeated_query_param_expands_array` uses
MethodParameter but it was not imported in the test module's use
statement, causing a compilation error in CI.
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly exposes the repeated field in the schema output and updates build_url to expand array values into multiple query parameters. However, there is a critical issue in how these query parameters are applied to the HTTP request. The current implementation in build_http_request will cause only the last query parameter to be sent, defeating the purpose of this change. I've added a critical review comment with a suggested fix.

Consolidate query parameters (including pageToken) into a single
request.query() call to ensure repeated parameters are sent correctly
instead of being overwritten by successive calls.
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses issues with repeated/array query parameters by modifying the schema output to include a repeated flag and updating the request executor to expand JSON arrays into multiple query parameters. The data structure for query parameters has been changed from a HashMap to a Vec<(String, String)> to support repeated keys. The changes are accompanied by new tests. I have reviewed the changes and found no issues of high or critical severity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities area: http

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gws schema drops repeated: true for array query parameters, causing metadata format to fail

2 participants