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: new overridable routing headers implementation #910

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

viacheslav-rostovtsev
Copy link
Member

No description provided.

@viacheslav-rostovtsev viacheslav-rostovtsev requested a review from a team as a code owner February 8, 2023 01:41
Copy link
Member

@dazuma dazuma left a comment

Choose a reason for hiding this comment

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

It would also probably be prudent to split this into two PRs, one for the gapic-common change and one for the generator template change. Because the template change depends on the gapic-common change, so we should first release a new gapic-common minor version, and then update the templates including updating the gapic-common dependency version.

# @private
# Creates a new HeaderBinding.
#
def self.create field:, header_name: nil, regex: nil
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason we're creating this separate factory method rather than just writing the constructor with this signature?

Copy link
Member Author

Choose a reason for hiding this comment

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

Symmetry with the routing headers extractor/binding

@bindings = bindings || []
end

def with_bindings(field:, header_name: nil, regex: nil)
Copy link
Member

Choose a reason for hiding this comment

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

This should be okay without the parens

Copy link
Member Author

Choose a reason for hiding this comment

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

👍


module Gapic
module RoutingHeaders
class HeadersExtractor
Copy link
Member

Choose a reason for hiding this comment

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

Unless this class is @private we need documentation for the class and its public methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will be @private


if header_binding.regex && !field_value.is_a?(::String)
err_msg = "Header binding configuration is incorrect: regex" \
"is given with a non-string field #{field}.\n" \
Copy link
Member

Choose a reason for hiding this comment

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

Did you mean #{field_value}?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, good catch

next unless field_value

if header_binding.regex && !field_value.is_a?(::String)
err_msg = "Header binding configuration is incorrect: regex" \
Copy link
Member

Choose a reason for hiding this comment

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

you probably want a space after regex.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

curr_submessage = curr_submessage.send curr_field
end

return curr_submessage.to_s if curr_submessage
Copy link
Member

Choose a reason for hiding this comment

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

You can probably replace this line with simply curr_submessage&.to_s

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

field_path.each do |curr_field|
return nil unless curr_submessage.respond_to? curr_field
curr_submessage = curr_submessage.send curr_field
end
Copy link
Member

Choose a reason for hiding this comment

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

A bit more idiomatic would be to use Enumerable#reduce for the above:

final_submessage = field_path.reduce request do |curr_submessage, curr_field|
  return nil unless curr_submessage.respond_to? curr_field
  curr_submessage.send curr_field
end

Followed by:

final_submessage&.to_s

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants