feat(api-core): centralize rest transcoding helpers#17765
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new rest_transcoding module under google/api_core/gapic_v1 to handle transcoding of requests into HTTP methods, URIs, bodies, and query parameters. It also adds comprehensive unit tests for this new functionality, configures a session-scoped pytest fixture to isolate tests from workstation mTLS environments, and updates Python version configurations. The feedback suggests optimizing the conversion of protobuf messages to Python dictionaries in rest_transcoding.py by using json_format.MessageToDict instead of serializing to JSON and deserializing it back.
3af2bfe to
0b05ab3
Compare
2e4481a to
c736fcd
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new helper module rest_helpers in google.api_core.gapic_v1 containing a transcode function, which converts protobuf or proto-plus request messages into HTTP methods, URIs, JSON bodies, and query parameters. It also includes comprehensive unit tests for this function and a new session-scoped test fixture to isolate unit tests from workstation mTLS environments. There are no review comments, and I have no additional feedback to provide.
e009a6b to
81ad231
Compare
Edit: I guess this is replacing a number of methods in rest_base? Can you show a diff of what the changes will look like in the generated code? |
Regarding the code this is replacing: This is replacing the three private helper methods generated for each REST RPC: _get_transcoded_request, _get_request_body_json, and _get_query_params_json (defined in rest_base.py.j2:L128-167 and originally called within the template at _shared_macros.j2:L209-216). By consolidating them, we avoid generating duplicate request serialization, JSON body conversion, and default required field query parameter injection logic for every REST endpoint. Regarding the method name: Great point. I've renamed transcode in rest_helpers.py to transcode_request to make it clear that it transcodes a full request and to avoid any confusion with path_template.transcode. for a diff example: |
81ad231 to
04a1519
Compare
No region tags are edited in this PR.This comment is generated by snippet-bot.
|
1706e20 to
3ff39e7
Compare
f399974 to
509c733
Compare
509c733 to
2c3a593
Compare
introduces a generic REST Transcoding helper under
google.api_core.gapic_v1.rest_transcoding.Scope of Changes:
rest_helpers.py: A centralized, parameters-driven generic utilitytranscode()that replaces the redundant code generated inside the client REST transport constructors (query parameter JSON parsing, required field default checking, body parsing, and numeric enum serialization).__init__.py: Registered lazy-loading for the module.conftest.py: Added session-scoped mock fixtures for mTLS variables to prevent local workstation client certificate leakage during python unit tests.test_rest_transcoding.py: A comprehensive test suite validating transcoding behavior for query parameters, nested fields, required field default injection, and numeric enums.This is the runtime package companion to the generator PR.