Skip to content

Commit

Permalink
Use model to translate operationInput parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods committed Oct 29, 2024
1 parent 6398dc7 commit 6426c02
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def initialize(options)
@operation_inputs = operation_inputs.map do |operation_inputs_test|
OperationInputsTest.new(
service: @service,
operation_name: Underscore.underscore(
operation_inputs_test['operationName']
),
operation_name: operation_inputs_test['operationName'],
operation_params: operation_inputs_test['operationParams'] || {},
built_in_params: operation_inputs_test['builtInParams'] || {},
client_params: operation_inputs_test['clientParams'] || {}
Expand Down Expand Up @@ -110,9 +108,13 @@ class OperationInputsTest

def initialize(options)
@service = options[:service]
@operation_name = options[:operation_name]
@api = @service.api
@operation_name = Underscore.underscore(options[:operation_name])
input_shape_name = @api['operations'][options[:operation_name]]['input']['shape']
input = @api['shapes'][input_shape_name]
@operation_params = options[:operation_params].map do |k,v|
Param.new(Underscore.underscore(k), transform_operation_values(v))
member_shape = @api['shapes'][input['members'][k]['shape']]
Param.new(Underscore.underscore(k), transform_operation_values(v, member_shape))
end
@client_params = options[:client_params].map do |k,v|
Param.new(Underscore.underscore(k), v)
Expand All @@ -138,14 +140,21 @@ def initialize(options)
attr_reader :client_params

private
def transform_operation_values(value)
case value
when Hash
def transform_operation_values(value, ref)
case ref['type']
when 'structure', 'union'
value.each_with_object({}) do |(k, v), o|
o[Underscore.underscore(k).to_sym] = transform_operation_values(v)
member_shape = @api['shapes'][ref['members'][k]['shape']]
o[Underscore.underscore(k).to_sym] = transform_operation_values(v, member_shape)
end
when 'list'
member_shape = @api['shapes'][ref['member']['shape']]
value.map { |v| transform_operation_values(v, member_shape) }
when 'map'
member_shape = @api['shapes'][ref['value']['shape']]
value.each_with_object({}) do |(k, v), o|
o[k] = transform_operation_values(v, member_shape)
end
when Array
value.map { |v| transform_operation_values(v) }
else
value
end
Expand Down

0 comments on commit 6426c02

Please sign in to comment.