Skip to content

Commit abbd2cd

Browse files
authored
Allow modeled types to be used for Union inputs. (#3068)
1 parent 37917dc commit abbd2cd

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Allow modeled types to be used for Union inputs.
45
* Issue - Ensure that nested sensitive members and sensitive members of lists and maps are filtered.
56

67
3.201.1 (2024-07-05)

gems/aws-sdk-core/lib/aws-sdk-core/param_validator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def structure(ref, values, errors, context)
7171
end
7272

7373
if @validate_required && shape.union
74-
set_values = @input ? values.length : values.to_h.length
74+
set_values = values.to_h.length
7575
if set_values > 1
7676
errors << "multiple values provided to union at #{context} - must contain exactly one of the supported types: #{shape.member_names.join(', ')}"
7777
elsif set_values == 0

gems/aws-sdk-core/spec/aws/param_validator_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ class TestClass; end
88
describe ParamValidator do
99
let(:shapes) { ApiHelper.sample_shapes }
1010

11-
let(:api) { ApiHelper.sample_api(shapes: shapes) }
11+
let(:service) { ApiHelper.sample_service(shapes: shapes) }
12+
13+
let(:api) { service.const_get(:ClientApi).const_get(:API) }
14+
15+
let(:types) { service.const_get(:Types) }
1216

1317
def validate(params, expected_errors = [])
1418
rules = api.operation(:example_operation).input
@@ -98,10 +102,16 @@ def match_errors(error, expected_errors)
98102
validate({ string: 's', boolean: true }, 'multiple values provided to union')
99103
end
100104

101-
it 'access a struct with exactly one value set' do
105+
it 'accepts a struct with exactly one value set' do
102106
shapes['StructureShape']['union'] = true
103107
validate({ string: 's' })
104108
end
109+
110+
it 'accepts a modeled type' do
111+
shapes['StructureShape']['union'] = true
112+
input = types.const_get('StructureShape').new(string: 's')
113+
validate(input)
114+
end
105115
end
106116

107117
describe 'lists' do

0 commit comments

Comments
 (0)