Skip to content

Commit

Permalink
fix: fix issue with reserved names and http body. (#1657)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
atulep and parthea authored Jul 4, 2023
1 parent 6bebe75 commit e51109d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
13 changes: 13 additions & 0 deletions tests/unit/schema/wrappers/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e51109d

Please sign in to comment.