feat(tools): add preserve_property_names option to OpenAPIToolset#4505
feat(tools): add preserve_property_names option to OpenAPIToolset#4505yuvrajangadsingh wants to merge 4 commits intogoogle:mainfrom
Conversation
Summary of ChangesHello @yuvrajangadsingh, 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 enhances the Highlights
🧠 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. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces a preserve_property_names option to the OpenAPIToolset, allowing developers to prevent the automatic conversion of API parameter names to snake_case. This is a valuable feature for interacting with APIs that expect camelCase or other naming conventions. The implementation is clean, backward-compatible, and well-tested. I have one suggestion to refactor a small piece of duplicated logic to improve long-term maintainability, but overall this is a great addition.
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Outdated
Show resolved
Hide resolved
Address review feedback by extracting the duplicated py_name determination logic into a single _get_py_name() method.
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a preserve_property_names option to the OpenAPIToolset, allowing developers to prevent the automatic conversion of API parameter names to snake_case. This is a valuable feature for interacting with APIs that expect camelCase or other naming conventions. The implementation is clean, passing the new flag down through the parser classes and conditionally applying the name transformation. The changes are well-tested with new unit tests covering various scenarios. I have one suggestion to improve the signature of the OperationParser's __init__ method for better clarity and consistency.
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Show resolved
Hide resolved
…y_names keyword-only
|
All review feedback has been addressed:
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a preserve_property_names option to OpenAPIToolset, which is a valuable feature for interacting with APIs that don't use snake_case for property names. The implementation is clean and minimally invasive, cleverly reusing existing logic in ApiParameter to handle the conditional snake-casing. The changes are well-tested, covering both the new functionality and ensuring backward compatibility.
I have one suggestion regarding the propagation of the preserve_property_names flag to improve long-term robustness, but overall this is a solid contribution.
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Show resolved
Hide resolved
…rom_parsed_operation
|
All three review suggestions have been addressed:
All 210 tests pass. Ready for review. @gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This is a great addition that provides more flexibility when working with APIs that don't use snake_case for property names. The implementation is clean and backward-compatible, and the new tests provide good coverage. I have one suggestion in operation_parser.py to improve code clarity by centralizing the logic for parameter name generation. Overall, this is a well-executed feature.
src/google/adk/tools/openapi_tool/openapi_spec_parser/operation_parser.py
Show resolved
Hide resolved
|
@gemini-code-assist review |
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable preserve_property_names option to the OpenAPIToolset, allowing for better integration with APIs that use naming conventions other than snake_case. The implementation is clean, and the new functionality is well-covered by unit tests. I've identified a minor area for simplification where the new flag is passed down further than necessary, leading to some redundant code. My suggestions aim to remove this redundancy and improve maintainability. Overall, this is a solid contribution.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Description
ADK's
OpenAPIToolsetautomatically converts all parameter names tosnake_casevia_to_snake_case(). This is a problem when calling APIs that expect camelCase property names — e.g. an OpenAPI spec withsessionInfogets converted tosession_info, causing the target API to reject the request.While the internal mapping (
original_name→py_name) correctly maps back to the original names for the actual HTTP call, the LLM schema shows the snake_cased names, creating a mismatch with the API documentation and confusing developers.This PR adds a
preserve_property_namesparameter toOpenAPIToolsetthat, when set toTrue, keeps the original property names from the OpenAPI spec instead of converting them to snake_case. The flag isFalseby default for full backward compatibility.Usage:
Changes:
openapi_toolset.py— Newpreserve_property_namesparameter, passed to the parseropenapi_spec_parser.py— Accepts and forwards the flag toOperationParseroperation_parser.py— When flag isTrue, setspy_namedirectly fromoriginal_name(only applying Python keyword renaming), skipping_to_snake_case()Testing Plan
Unit Tests:
Added 3 new tests:
test_openapi_toolset_preserve_property_names— verifies camelCase params are preserved when flag is Truetest_openapi_toolset_default_snake_case_conversion— verifies default behavior still converts to snake_casetest_openapi_toolset_preserve_property_names_body_params— verifies request body properties (firstName, lastName, emailAddress) are preservedAll 210 tests pass (14 in the toolset file, 3 of which are new).
Manual End-to-End (E2E) Tests:
Not applicable — this is a parsing/schema generation change that doesn't affect the web UI or runner. The unit tests cover the full flow from OpenAPI spec parsing through to JSON schema generation, which is the complete surface area of this change.
Checklist
Additional context
The fix is intentionally minimal — 3 source files modified, 1 test file updated, all backward compatible. The
ApiParameterclass itself needed no changes since itsmodel_post_initalready skips snake_case inference whenpy_nameis pre-set.