From cb3f070d3f165981795e69aa5624c6761b2871ab Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Thu, 18 Jul 2024 09:37:58 -0700 Subject: [PATCH] Allow modeled types to be used for Union inputs. --- gems/aws-sdk-core/CHANGELOG.md | 1 + .../lib/aws-sdk-core/param_validator.rb | 2 +- gems/aws-sdk-core/spec/aws/param_validator_spec.rb | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gems/aws-sdk-core/CHANGELOG.md b/gems/aws-sdk-core/CHANGELOG.md index 0cb5dcfd8b8..562f11d1660 100644 --- a/gems/aws-sdk-core/CHANGELOG.md +++ b/gems/aws-sdk-core/CHANGELOG.md @@ -1,6 +1,7 @@ Unreleased Changes ------------------ +* Issue - Allow modeled types to be used for Union inputs. * Issue - Ensure that nested sensitive members and sensitive members of lists and maps are filtered. 3.201.1 (2024-07-05) diff --git a/gems/aws-sdk-core/lib/aws-sdk-core/param_validator.rb b/gems/aws-sdk-core/lib/aws-sdk-core/param_validator.rb index 20689f1670e..d54f9bd296c 100644 --- a/gems/aws-sdk-core/lib/aws-sdk-core/param_validator.rb +++ b/gems/aws-sdk-core/lib/aws-sdk-core/param_validator.rb @@ -71,7 +71,7 @@ def structure(ref, values, errors, context) end if @validate_required && shape.union - set_values = @input ? values.length : values.to_h.length + set_values = values.to_h.length if set_values > 1 errors << "multiple values provided to union at #{context} - must contain exactly one of the supported types: #{shape.member_names.join(', ')}" elsif set_values == 0 diff --git a/gems/aws-sdk-core/spec/aws/param_validator_spec.rb b/gems/aws-sdk-core/spec/aws/param_validator_spec.rb index a47dbf7ce5b..29b842da5c5 100644 --- a/gems/aws-sdk-core/spec/aws/param_validator_spec.rb +++ b/gems/aws-sdk-core/spec/aws/param_validator_spec.rb @@ -8,7 +8,11 @@ class TestClass; end describe ParamValidator do let(:shapes) { ApiHelper.sample_shapes } - let(:api) { ApiHelper.sample_api(shapes: shapes) } + let(:service) { ApiHelper.sample_service(shapes: shapes) } + + let(:api) { service.const_get(:ClientApi).const_get(:API) } + + let(:types) { service.const_get(:Types) } def validate(params, expected_errors = []) rules = api.operation(:example_operation).input @@ -98,10 +102,16 @@ def match_errors(error, expected_errors) validate({ string: 's', boolean: true }, 'multiple values provided to union') end - it 'access a struct with exactly one value set' do + it 'accepts a struct with exactly one value set' do shapes['StructureShape']['union'] = true validate({ string: 's' }) end + + it 'accepts a modeled type' do + shapes['StructureShape']['union'] = true + input = types.const_get('StructureShape').new(string: 's') + validate(input) + end end describe 'lists' do