feat(generator): delegate REST transcoding to google-api-core#17766
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors REST transcoding in the GAPIC generator by centralizing the transcoding logic into a new transcode function within google-api-core (gapic_v1.rest_transcoding). This change eliminates redundant static helper methods (_get_transcoded_request, _get_request_body_json, and _get_query_params_json) from the generated transport templates. Additionally, the PR updates test configurations and introduces comprehensive unit tests for the new transcoding utility. The feedback suggests optimizing the transcode function by using json_format.MessageToDict directly instead of the inefficient round-trip serialization of json.loads(json_format.MessageToJson(...)).
b9bb9f0 to
a8a1968
Compare
203e87a to
5e89b3d
Compare
No region tags are edited in this PR.This comment is generated by snippet-bot.
|
909a6fe to
dfca3e0
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a compatibility module (_compat.py.j2) to support older versions of google-api-core in generated clients, replacing local helper methods in transport templates with centralized calls to rest_helpers.transcode_request. Additionally, the local development setup in noxfile.py is updated to install google-api-core from source. Feedback on the changes highlights two critical issues: first, the use of getattr to retrieve __REQUIRED_FIELDS_DEFAULT_VALUES in _shared_macros.j2 will fail at runtime due to Python's name mangling, requiring the use of the mangled name; second, in _compat.py.j2, older versions of google-api-core might have transcode_request but lack the rest_numeric_enums parameter, which would cause a TypeError unless the function signature is inspected first.
|
It would be helpful to see the generated code here. Reviewing raw templates alone can be tricky |
…s in fallback transcode_request
…nd inspect transcode_request signature in compat
this PR refactors generator templates to delegate REST transcoding to the centralized helper in
google-api-core.Scope of Changes:
_shared_macros.j2: Replaced inline static helper invocation withgapic_v1.rest_transcoding.transcode().rest_base.py.j2: Stripped the redundant_get_transcoded_request,_get_request_body_json, and_get_query_params_jsonhelper functions._rest_mixins_base.py.j2: Stripped the redundant static helpers from API REST mixins base.rest.py.j2&rest_asyncio.py.j2: Passed the configuration flags (likeopts.rest_numeric_enums) into the transcoding macro.noxfile.py: Configured localpackages/google-api-coreto be installed during virtualenv test generation so the new transcoding runtime module is available.related PR: #17765