From 9872daf492dd6dad3a1c2cf948a96dbe0271ceb8 Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 31 Oct 2024 13:14:53 -0700 Subject: [PATCH] Use model to translate operationInput parameters (#3133) --- .../spec/endpoint_provider_spec_class.rb | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb index 0ab96126c5d..205f51a8a61 100644 --- a/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb +++ b/build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/views/spec/endpoint_provider_spec_class.rb @@ -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'] || {} @@ -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) @@ -126,6 +128,10 @@ def initialize(options) !options[:built_in_params].include?('AWS::S3::UseGlobalEndpoint') @client_params << built_in_to_param('AWS::S3::UseGlobalEndpoint', false) end + + if @service.identifier == 'dynamodb' + @client_params << Param.new(:simple_attributes, false, true) + end end # @return String @@ -138,14 +144,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| + 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[Underscore.underscore(k).to_sym] = transform_operation_values(v) + o[k] = transform_operation_values(v, member_shape) end - when Array - value.map { |v| transform_operation_values(v) } else value end