Skip to content

Conversation

@jeandersonbc
Copy link
Contributor

@jeandersonbc jeandersonbc commented Jan 19, 2026

Description

The current template does not enforce the presence of required query parameters. The change in the template allows to throw a runtime exception for missing required parameters. Optional query params are added next to the required params with the existing null check.

Tested scenarios

  • Changed the /grants endpoint from CapitalService-v1.json spec with a sequence of required/optional query params and re-generated the code.

Fixed issue:

@jeandersonbc jeandersonbc self-assigned this Jan 19, 2026
@jeandersonbc jeandersonbc requested review from a team as code owners January 19, 2026 14:26
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jeandersonbc, 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 in the API client generation template where required query parameters were not being enforced. The changes ensure that generated service methods will explicitly validate the presence of required query parameters at runtime, preventing potential API call failures due to missing essential data. This fix improves the robustness and reliability of the generated API clients by providing immediate feedback when a required parameter is omitted.

Highlights

  • Enforcement of Required Query Parameters: The template now generates code that explicitly checks for the presence of required query parameters. If a required parameter is null, an IllegalArgumentException is thrown at runtime, ensuring that API calls are made with all necessary data.
  • Separated Handling for Optional Parameters: The logic for adding query parameters has been refactored to first process all required parameters with their new validation, and then subsequently add optional parameters only if they are not null, maintaining existing null checks for optional fields.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, 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 adds a check for required query parameters, throwing an IllegalArgumentException if they are missing. This is a good improvement for API robustness. I've added one suggestion to refactor the template logic to be more efficient by using a single loop instead of two to process the query parameters. This will improve maintainability and performance.

Comment on lines +74 to 91
{{! Add first all required query params }}
{{#queryParams}}
if ({{{paramName}}} != null) {
{{#required}}
if ({{{paramName}}} == null) {
throw new IllegalArgumentException("Please provide the {{{paramName}}} query parameter");
}
queryParams.put("{{baseName}}", {{{paramName}}}{{^isString}}.toString(){{/isString}});
{{/required}}
{{/queryParams}}

{{! Then, add all the optional query params }}
{{#queryParams}}
{{^required}}
if ({{{paramName}}} != null) {
queryParams.put("{{baseName}}", {{{paramName}}}{{^isString}}.toString(){{/isString}});
}
{{/required}}
{{/queryParams}}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The current implementation iterates over the queryParams list twice: once for required parameters and once for optional ones. This can be optimized by combining these into a single loop. This refactoring will make the template more efficient and easier to read.

        {{! Process all query params }}
        {{#queryParams}}
        {{#required}}
        if ({{{paramName}}} == null) {
            throw new IllegalArgumentException("Please provide the {{{paramName}}} query parameter");
        }
        queryParams.put("{{baseName}}", {{{paramName}}}{{^isString}}.toString(){{/isString}});
        {{/required}}
        {{^required}}
        if ({{{paramName}}} != null) {
            queryParams.put("{{baseName}}", {{{paramName}}}{{^isString}}.toString(){{/isString}});
        }
        {{/required}}
        {{/queryParams}}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this locally, so as expected, you loop once but you have required/optionals mixed (in the order they are declared). I don't have any preference on that, so I'm leaving for reviewers.

The current template does not enforce the presence of required query parameters.
The change in the template allows to throw a runtime exception for missing required parameters.
Optional query params are added next to the required params with the existing null check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not stale Fix Indicates a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants