Skip to content

Commit

Permalink
Allow modeled types to be used for Union inputs. (#3068)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods committed Jul 18, 2024
1 parent 37917dc commit abbd2cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core/param_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions gems/aws-sdk-core/spec/aws/param_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit abbd2cd

Please sign in to comment.