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

Backport endpoint provider parameters unused variable fix #272

Merged
merged 2 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions gems/smithy/lib/smithy/templates/client/endpoint_provider.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ module <%= module_name %>
# @return [Smithy::Client::EndpointRules::Endpoint]
# @raise [ArgumentError]
def resolve_endpoint(parameters)
<% parameters.each do |p| -%>
<%= p.name %> = parameters.<%= p.name %>
<% end -%>

<%= endpoint_rules_code %>
end
end
Expand Down
21 changes: 14 additions & 7 deletions gems/smithy/lib/smithy/views/client/endpoint_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ def initialize(plan)
@endpoint_rules = service['traits']['smithy.rules#endpointRuleSet']
@parameters = @endpoint_rules['parameters']
.map { |id, data| EndpointParameter.new(id, data, @plan) }

@endpoint_function_bindings =
plan.welds.map(&:endpoint_function_bindings).reduce({}, :merge)

@assigned_variables = []
super()
end

Expand Down Expand Up @@ -161,6 +160,7 @@ def conditions(conditions, level)

def condition(condition)
if condition['assign']
@assigned_variables << condition['assign']
"(#{condition['assign'].underscore} = #{function(condition)})"
else
function(condition)
Expand All @@ -170,7 +170,7 @@ def condition(condition)
def str(str)
if str.is_a?(Hash)
if str['ref']
str['ref'].underscore
variable(str['ref'])
elsif str['fn']
function(str)
else
Expand All @@ -192,11 +192,10 @@ def template_str(string, wrap: true)

def template_replace(value)
indexes = value.split('#')
res = indexes.shift.underscore
res += indexes.map do |index|
res = variable(indexes.shift)
res + indexes.map do |index|
"['#{index}']"
end.join
res
end

def function(function)
Expand All @@ -207,7 +206,7 @@ def function(function)
def fn_arg(arg)
if arg.is_a?(Hash)
if arg['ref']
arg['ref'].underscore
variable(arg['ref'])
elsif arg['fn']
function(arg)
else
Expand All @@ -220,6 +219,14 @@ def fn_arg(arg)
end
end

def variable(variable)
if @assigned_variables.include?(variable)
variable.underscore
else
"parameters.#{variable.underscore}"
end
end

def fn_name(function)
unless (binding = @endpoint_function_bindings[function])
raise ArgumentError, "No endpoint function binding registered for #{function}"
Expand Down
4 changes: 1 addition & 3 deletions projections/weather/lib/weather/endpoint_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class EndpointProvider
# @return [Smithy::Client::EndpointRules::Endpoint]
# @raise [ArgumentError]
def resolve_endpoint(parameters)
endpoint = parameters.endpoint

return Smithy::Client::EndpointRules::Endpoint.new(uri: endpoint) if Smithy::Client::EndpointRules.set?(endpoint)
return Smithy::Client::EndpointRules::Endpoint.new(uri: parameters.endpoint) if Smithy::Client::EndpointRules.set?(parameters.endpoint)

raise ArgumentError, 'Endpoint is not set - you must configure an endpoint.'
end
Expand Down