Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 6b22c51

Browse files
chore: Enable requesting numeric enums in "transport=rest" responses for services supporting this (#35)
* chore: Enable requesting numeric enums in "transport=rest" responses for services supporting this (Java, Go, Python, PHP, TypeScript, C#, and Ruby), even if they do not yet turn on REST transport chore: disallow "transport=rest" for services where numeric enums are not confirmed to be supported (except in PHP and Java) PiperOrigin-RevId: 493113566 Source-Link: googleapis/googleapis@758f0d1 Source-Link: https://github.com/googleapis/googleapis-gen/commit/78bd8f05e1276363eb14eae70e91fe4bc20703ab Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNzhiZDhmMDVlMTI3NjM2M2ViMTRlYWU3MGU5MWZlNGJjMjA3MDNhYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 1399403 commit 6b22c51

File tree

4 files changed

+69
-58
lines changed

4 files changed

+69
-58
lines changed

‎google/cloud/api_keys_v2/services/api_keys/client.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,6 @@ def __init__(
366366
transport (Union[str, ApiKeysTransport]): The
367367
transport to use. If set to None, a transport is chosen
368368
automatically.
369-
NOTE: "rest" transport functionality is currently in a
370-
beta state (preview). We welcome your feedback via an
371-
issue in this library's source repository.
372369
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the
373370
client. It won't take effect if a ``transport`` instance is provided.
374371
(1) The ``api_endpoint`` property can be used to override the

‎google/cloud/api_keys_v2/services/api_keys/transports/rest.py

Lines changed: 60 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
rest_version=requests_version,
5757
)
5858

59+
# TODO (numeric enums): This file was generated with the option to
60+
# request that the server respond with enums JSON-encoded as
61+
# numbers. The code below does not implement that functionality yet.
62+
5963

6064
class ApiKeysRestInterceptor:
6165
"""Interceptor for ApiKeys.
@@ -342,9 +346,6 @@ class ApiKeysRestTransport(ApiKeysTransport):
342346
343347
It sends JSON representations of protocol buffers over HTTP/1.1
344348
345-
NOTE: This REST transport functionality is currently in a beta
346-
state (preview). We welcome your feedback via an issue in this
347-
library's source repository. Thank you!
348349
"""
349350

350351
def __init__(
@@ -364,39 +365,35 @@ def __init__(
364365
) -> None:
365366
"""Instantiate the transport.
366367
367-
NOTE: This REST transport functionality is currently in a beta
368-
state (preview). We welcome your feedback via a GitHub issue in
369-
this library's repository. Thank you!
370-
371-
Args:
372-
host (Optional[str]):
373-
The hostname to connect to.
374-
credentials (Optional[google.auth.credentials.Credentials]): The
375-
authorization credentials to attach to requests. These
376-
credentials identify the application to the service; if none
377-
are specified, the client will attempt to ascertain the
378-
credentials from the environment.
379-
380-
credentials_file (Optional[str]): A file with credentials that can
381-
be loaded with :func:`google.auth.load_credentials_from_file`.
382-
This argument is ignored if ``channel`` is provided.
383-
scopes (Optional(Sequence[str])): A list of scopes. This argument is
384-
ignored if ``channel`` is provided.
385-
client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
386-
certificate to configure mutual TLS HTTP channel. It is ignored
387-
if ``channel`` is provided.
388-
quota_project_id (Optional[str]): An optional project to use for billing
389-
and quota.
390-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
391-
The client info used to send a user-agent string along with
392-
API requests. If ``None``, then default info will be used.
393-
Generally, you only need to set this if you are developing
394-
your own client library.
395-
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
396-
be used for service account credentials.
397-
url_scheme: the protocol scheme for the API endpoint. Normally
398-
"https", but for testing or local servers,
399-
"http" can be specified.
368+
Args:
369+
host (Optional[str]):
370+
The hostname to connect to.
371+
credentials (Optional[google.auth.credentials.Credentials]): The
372+
authorization credentials to attach to requests. These
373+
credentials identify the application to the service; if none
374+
are specified, the client will attempt to ascertain the
375+
credentials from the environment.
376+
377+
credentials_file (Optional[str]): A file with credentials that can
378+
be loaded with :func:`google.auth.load_credentials_from_file`.
379+
This argument is ignored if ``channel`` is provided.
380+
scopes (Optional(Sequence[str])): A list of scopes. This argument is
381+
ignored if ``channel`` is provided.
382+
client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
383+
certificate to configure mutual TLS HTTP channel. It is ignored
384+
if ``channel`` is provided.
385+
quota_project_id (Optional[str]): An optional project to use for billing
386+
and quota.
387+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
388+
The client info used to send a user-agent string along with
389+
API requests. If ``None``, then default info will be used.
390+
Generally, you only need to set this if you are developing
391+
your own client library.
392+
always_use_jwt_access (Optional[bool]): Whether self signed JWT should
393+
be used for service account credentials.
394+
url_scheme: the protocol scheme for the API endpoint. Normally
395+
"https", but for testing or local servers,
396+
"http" can be specified.
400397
"""
401398
# Run the base constructor
402399
# TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
@@ -518,7 +515,7 @@ def __call__(
518515
body = json_format.MessageToJson(
519516
transcoded_request["body"],
520517
including_default_value_fields=False,
521-
use_integers_for_enums=False,
518+
use_integers_for_enums=True,
522519
)
523520
uri = transcoded_request["uri"]
524521
method = transcoded_request["method"]
@@ -528,11 +525,13 @@ def __call__(
528525
json_format.MessageToJson(
529526
transcoded_request["query_params"],
530527
including_default_value_fields=False,
531-
use_integers_for_enums=False,
528+
use_integers_for_enums=True,
532529
)
533530
)
534531
query_params.update(self._get_unset_required_fields(query_params))
535532

533+
query_params["$alt"] = "json;enum-encoding=int"
534+
536535
# Send the request
537536
headers = dict(metadata)
538537
headers["Content-Type"] = "application/json"
@@ -614,11 +613,13 @@ def __call__(
614613
json_format.MessageToJson(
615614
transcoded_request["query_params"],
616615
including_default_value_fields=False,
617-
use_integers_for_enums=False,
616+
use_integers_for_enums=True,
618617
)
619618
)
620619
query_params.update(self._get_unset_required_fields(query_params))
621620

621+
query_params["$alt"] = "json;enum-encoding=int"
622+
622623
# Send the request
623624
headers = dict(metadata)
624625
headers["Content-Type"] = "application/json"
@@ -698,11 +699,13 @@ def __call__(
698699
json_format.MessageToJson(
699700
transcoded_request["query_params"],
700701
including_default_value_fields=False,
701-
use_integers_for_enums=False,
702+
use_integers_for_enums=True,
702703
)
703704
)
704705
query_params.update(self._get_unset_required_fields(query_params))
705706

707+
query_params["$alt"] = "json;enum-encoding=int"
708+
706709
# Send the request
707710
headers = dict(metadata)
708711
headers["Content-Type"] = "application/json"
@@ -782,11 +785,13 @@ def __call__(
782785
json_format.MessageToJson(
783786
transcoded_request["query_params"],
784787
including_default_value_fields=False,
785-
use_integers_for_enums=False,
788+
use_integers_for_enums=True,
786789
)
787790
)
788791
query_params.update(self._get_unset_required_fields(query_params))
789792

793+
query_params["$alt"] = "json;enum-encoding=int"
794+
790795
# Send the request
791796
headers = dict(metadata)
792797
headers["Content-Type"] = "application/json"
@@ -866,11 +871,13 @@ def __call__(
866871
json_format.MessageToJson(
867872
transcoded_request["query_params"],
868873
including_default_value_fields=False,
869-
use_integers_for_enums=False,
874+
use_integers_for_enums=True,
870875
)
871876
)
872877
query_params.update(self._get_unset_required_fields(query_params))
873878

879+
query_params["$alt"] = "json;enum-encoding=int"
880+
874881
# Send the request
875882
headers = dict(metadata)
876883
headers["Content-Type"] = "application/json"
@@ -952,11 +959,13 @@ def __call__(
952959
json_format.MessageToJson(
953960
transcoded_request["query_params"],
954961
including_default_value_fields=False,
955-
use_integers_for_enums=False,
962+
use_integers_for_enums=True,
956963
)
957964
)
958965
query_params.update(self._get_unset_required_fields(query_params))
959966

967+
query_params["$alt"] = "json;enum-encoding=int"
968+
960969
# Send the request
961970
headers = dict(metadata)
962971
headers["Content-Type"] = "application/json"
@@ -1037,7 +1046,7 @@ def __call__(
10371046
body = json_format.MessageToJson(
10381047
transcoded_request["body"],
10391048
including_default_value_fields=False,
1040-
use_integers_for_enums=False,
1049+
use_integers_for_enums=True,
10411050
)
10421051
uri = transcoded_request["uri"]
10431052
method = transcoded_request["method"]
@@ -1047,11 +1056,13 @@ def __call__(
10471056
json_format.MessageToJson(
10481057
transcoded_request["query_params"],
10491058
including_default_value_fields=False,
1050-
use_integers_for_enums=False,
1059+
use_integers_for_enums=True,
10511060
)
10521061
)
10531062
query_params.update(self._get_unset_required_fields(query_params))
10541063

1064+
query_params["$alt"] = "json;enum-encoding=int"
1065+
10551066
# Send the request
10561067
headers = dict(metadata)
10571068
headers["Content-Type"] = "application/json"
@@ -1131,7 +1142,7 @@ def __call__(
11311142
body = json_format.MessageToJson(
11321143
transcoded_request["body"],
11331144
including_default_value_fields=False,
1134-
use_integers_for_enums=False,
1145+
use_integers_for_enums=True,
11351146
)
11361147
uri = transcoded_request["uri"]
11371148
method = transcoded_request["method"]
@@ -1141,11 +1152,13 @@ def __call__(
11411152
json_format.MessageToJson(
11421153
transcoded_request["query_params"],
11431154
including_default_value_fields=False,
1144-
use_integers_for_enums=False,
1155+
use_integers_for_enums=True,
11451156
)
11461157
)
11471158
query_params.update(self._get_unset_required_fields(query_params))
11481159

1160+
query_params["$alt"] = "json;enum-encoding=int"
1161+
11491162
# Send the request
11501163
headers = dict(metadata)
11511164
headers["Content-Type"] = "application/json"

‎samples/generated_samples/snippet_metadata_google.api.apikeys.v2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-api-keys",
11-
"version": "0.4.0"
11+
"version": "0.1.0"
1212
},
1313
"snippets": [
1414
{

‎tests/unit/gapic/api_keys_v2/test_api_keys.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ def test_create_key_rest_required_fields(request_type=apikeys.CreateKeyRequest):
26652665

26662666
response = client.create_key(request)
26672667

2668-
expected_params = []
2668+
expected_params = [("$alt", "json;enum-encoding=int")]
26692669
actual_params = req.call_args.kwargs["params"]
26702670
assert expected_params == actual_params
26712671

@@ -2989,7 +2989,7 @@ def test_list_keys_rest_required_fields(request_type=apikeys.ListKeysRequest):
29892989

29902990
response = client.list_keys(request)
29912991

2992-
expected_params = []
2992+
expected_params = [("$alt", "json;enum-encoding=int")]
29932993
actual_params = req.call_args.kwargs["params"]
29942994
assert expected_params == actual_params
29952995

@@ -3322,7 +3322,7 @@ def test_get_key_rest_required_fields(request_type=apikeys.GetKeyRequest):
33223322

33233323
response = client.get_key(request)
33243324

3325-
expected_params = []
3325+
expected_params = [("$alt", "json;enum-encoding=int")]
33263326
actual_params = req.call_args.kwargs["params"]
33273327
assert expected_params == actual_params
33283328

@@ -3581,7 +3581,7 @@ def test_get_key_string_rest_required_fields(request_type=apikeys.GetKeyStringRe
35813581

35823582
response = client.get_key_string(request)
35833583

3584-
expected_params = []
3584+
expected_params = [("$alt", "json;enum-encoding=int")]
35853585
actual_params = req.call_args.kwargs["params"]
35863586
assert expected_params == actual_params
35873587

@@ -3877,7 +3877,7 @@ def test_update_key_rest_required_fields(request_type=apikeys.UpdateKeyRequest):
38773877

38783878
response = client.update_key(request)
38793879

3880-
expected_params = []
3880+
expected_params = [("$alt", "json;enum-encoding=int")]
38813881
actual_params = req.call_args.kwargs["params"]
38823882
assert expected_params == actual_params
38833883

@@ -4181,7 +4181,7 @@ def test_delete_key_rest_required_fields(request_type=apikeys.DeleteKeyRequest):
41814181

41824182
response = client.delete_key(request)
41834183

4184-
expected_params = []
4184+
expected_params = [("$alt", "json;enum-encoding=int")]
41854185
actual_params = req.call_args.kwargs["params"]
41864186
assert expected_params == actual_params
41874187

@@ -4438,7 +4438,7 @@ def test_undelete_key_rest_required_fields(request_type=apikeys.UndeleteKeyReque
44384438

44394439
response = client.undelete_key(request)
44404440

4441-
expected_params = []
4441+
expected_params = [("$alt", "json;enum-encoding=int")]
44424442
actual_params = req.call_args.kwargs["params"]
44434443
assert expected_params == actual_params
44444444

@@ -4658,6 +4658,7 @@ def test_lookup_key_rest_required_fields(request_type=apikeys.LookupKeyRequest):
46584658
"keyString",
46594659
"",
46604660
),
4661+
("$alt", "json;enum-encoding=int"),
46614662
]
46624663
actual_params = req.call_args.kwargs["params"]
46634664
assert expected_params == actual_params

0 commit comments

Comments
 (0)