Skip to content

Commit

Permalink
Backport endpoint provider parameters unused variable fix (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp authored Feb 11, 2025
1 parent b050ec9 commit b5112f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
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

0 comments on commit b5112f7

Please sign in to comment.