From e51109da85bbd53e5b2af90fbce031b0dd7e2be5 Mon Sep 17 00:00:00 2001 From: Aza Tulepbergenov Date: Tue, 4 Jul 2023 09:57:54 -0700 Subject: [PATCH] fix: fix issue with reserved names and http body. (#1657) Co-authored-by: Anthonios Partheniou --- gapic/schema/wrappers.py | 3 +++ tests/unit/schema/wrappers/test_method.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/gapic/schema/wrappers.py b/gapic/schema/wrappers.py index 50127732aa..7f6a0c0ce0 100644 --- a/gapic/schema/wrappers.py +++ b/gapic/schema/wrappers.py @@ -1091,6 +1091,9 @@ def try_parse_http_rule(cls, http_rule) -> Optional['HttpRule']: uri = utils.convert_uri_fieldnames(uri) body = http_rule.body or None + # Ensure body doesn't conflict with reserved names. + if body in utils.RESERVED_NAMES and not body.endswith("_"): + body += "_" return cls(method, uri, body) diff --git a/tests/unit/schema/wrappers/test_method.py b/tests/unit/schema/wrappers/test_method.py index 3e27fed575..f6cf2e8818 100644 --- a/tests/unit/schema/wrappers/test_method.py +++ b/tests/unit/schema/wrappers/test_method.py @@ -511,6 +511,19 @@ def test_method_http_options_reserved_name_in_url(): }] +def test_method_http_options_reserved_name_in_body(): + http_rule = http_pb2.HttpRule( + post='/v1/license/{license=lic/*}', + body='breakpoint' + ) + method = make_method('DoSomething', http_rule=http_rule) + assert [dataclasses.asdict(http) for http in method.http_options] == [{ + 'method': 'post', + 'uri': '/v1/license/{license_=lic/*}', + 'body': 'breakpoint_' + }] + + def test_method_http_options_generate_sample(): http_rule = http_pb2.HttpRule( get='/v1/{resource.id=projects/*/regions/*/id/**}/stuff',