Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proper handling of query/path/body parameters for rest transport #702

Merged
merged 29 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c1a6f89
feat: add rest transport generation for clients
yon-mg Nov 2, 2020
bd7c32d
feat: add rest transport generation for clients
yon-mg Nov 2, 2020
cd3a7f1
Merge branch 'master' of github.com:yon-mg/gapic-generator-python
yon-mg Nov 2, 2020
b41db31
feat: add transport flag
yon-mg Nov 6, 2020
ce69e7d
refactor: moved template logic outside
yon-mg Nov 6, 2020
89fa08b
fix: small fixes in transport option logic
yon-mg Nov 9, 2020
86f3a9c
test: added unit test for transport flag
yon-mg Nov 9, 2020
234cc09
test: add unit test for http option method
yon-mg Nov 11, 2020
35ac276
test: add unit test for http option method branch
yon-mg Nov 11, 2020
c8155a5
fix: fix import paths
yon-mg Nov 11, 2020
55a815c
fix: style check issues
yon-mg Nov 11, 2020
ac0bdef
fix: more style check issues
yon-mg Nov 11, 2020
e79e8c7
fix: addressing pr reviews
yon-mg Nov 13, 2020
824ad11
fix: typo in test_method
yon-mg Nov 13, 2020
2d11e19
fix: style check fixes
yon-mg Nov 13, 2020
b5c6d06
Merge branch 'master' into master
yon-mg Nov 14, 2020
221cd44
feat: add proper handling of query/path/body parameters for rest tran…
yon-mg Nov 20, 2020
475f903
Merge branch 'master' of github.com:yon-mg/gapic-generator-python
yon-mg Nov 20, 2020
f08ca32
Merge remote-tracking branch 'upstream/master'
yon-mg Nov 20, 2020
efa0ed6
fix: typing errors
yon-mg Nov 20, 2020
d3e08c0
Update case.py
software-dov Nov 20, 2020
df88ef9
fix: minor changes adding a test, refactor and style check
yon-mg Nov 30, 2020
67c6bd1
Merge branch 'master' of github.com:yon-mg/gapic-generator-python
yon-mg Nov 30, 2020
37e3d28
fix: camel_case bug with constant case
yon-mg Nov 30, 2020
c964fba
fix: to_camel_case to produce lower camel case instead of PascalCase …
yon-mg Dec 1, 2020
85be88d
fix: addressing pr comments
yon-mg Dec 3, 2020
5d1c6a3
fix: adding appropriate todos, addressing comments
yon-mg Dec 4, 2020
f6c64cc
fix: dataclass dependency issue
yon-mg Dec 8, 2020
a4f34e7
Update wrappers.py
software-dov Dec 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,13 +769,13 @@ def http_opt(self) -> Optional[Dict[str, str]]:

@property
def path_params(self) -> Sequence[str]:
"""Return the path parameters found in the http annotation url"""
"""Return the path parameters found in the http annotation path template"""
# TODO(yon-mg): fully implement grpc transcoding (currently only handles basic case)
if self.http_opt is None:
return []
pattern = r'\{\w+\}'

return [x[1:-1] for x in re.findall(pattern, self.http_opt['url'])]
pattern = r'\{(\w+)\}'
return re.findall(pattern, self.http_opt['url'])

@property
def query_params(self) -> Set[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why can't query_params and path_params return the same type, rather than a Set and a Sequence?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose they could. Just thought it's more appropriate since ordering seems important for path_params but not for query_params.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed. That seems reasonable, but a complication is that repeated fields map to repeated query params. In that case, a sequence may be best. (If order doesn't matter, a multiset might be enough, but we can't assume that order doesn't matter for repeated fields)

Copy link
Contributor Author

@yon-mg yon-mg Dec 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right set is not appropriate even if order doesn't matter but I should mention though that once query param logic is moved out, this won't matter anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):
#}
# TODO(yon-mg): handle nested fields corerctly rather than using only top level fields
# not required for GCE
potentialParams = {
query_params = {
{%- for field in method.query_params %}
'{{ field|camel_case }}': request.{{ field }},
vchudnov-g marked this conversation as resolved.
Show resolved Hide resolved
{%- endfor %}
}
potentialParams = ((k, v) for k, v in potentialParams.items() if v)
for i, (param_name, param_value) in enumerate(potentialParams):
# TODO(yon-mg): further discussion needed whether 'python truthiness' is appropriate here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the TODO on truthiness!

# discards default values
# TODO(yon-mg): add test for proper url encoded strings
query_params = ((k, v) for k, v in query_params.items() if v)
for i, (param_name, param_value) in enumerate(query_params):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Do consider the string.Join suggestion from earlier (but it's certainly not a blocker)

q = '?' if i == 0 else '&'
url += "{q}{name}={value}".format(q=q, name=param_name, value=param_value.replace(' ', '+'))
vchudnov-g marked this conversation as resolved.
Show resolved Hide resolved

Expand Down