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

Allow modeled types to be used for Union inputs. #3068

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading