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

Use model to translate operationInput parameters #3133

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from 1 commit
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
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