Skip to content

Commit ceed0ac

Browse files
authored
Do not serialize empty lists in ec2 protocol (#3017)
1 parent 85761e9 commit ceed0ac

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

build_tools/aws-sdk-code-generator/spec/protocol-tests-ignore-list.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"ec2" :
33
{
4-
"input" : [],
4+
"input" : [
5+
{
6+
"Ec2EmptyQueryLists": "Empty lists should be omitted from serialization. Smithy to update"
7+
}
8+
],
59
"output" : []
610
},
711
"json" : {

gems/aws-sdk-core/CHANGELOG.md

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

4+
* Issue - Update EC2 protocol to not serialize empty lists.
5+
46
3.194.0 (2024-04-30)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core/query/ec2_param_builder.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ def structure(ref, values, prefix)
3131
end
3232

3333
def list(ref, values, prefix)
34-
if values.empty?
35-
set(prefix, '')
36-
else
37-
member_ref = ref.shape.member
38-
values.each.with_index do |value, n|
39-
format(member_ref, value, "#{prefix}.#{n+1}")
40-
end
34+
return if values.empty?
35+
36+
member_ref = ref.shape.member
37+
values.each.with_index do |value, n|
38+
format(member_ref, value, "#{prefix}.#{n + 1}")
4139
end
4240
end
4341

gems/aws-sdk-core/spec/aws/query/ec2_param_builder_spec.rb

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,52 @@
55
module Aws
66
module Query
77
describe EC2ParamBuilder do
8-
98
let(:shapes) { ApiHelper.sample_shapes }
109

11-
let(:rules) {
12-
ApiHelper.sample_api(shapes:shapes).
13-
operation(:example_operation).
14-
input
15-
}
10+
let(:rules) do
11+
ApiHelper
12+
.sample_api(shapes: shapes)
13+
.operation(:example_operation)
14+
.input
15+
end
1616

1717
def query(params = {})
1818
param_list = ParamList.new
1919
EC2ParamBuilder.new(param_list).apply(rules, params)
20-
param_list.map { |param| [param.name, param.value ] }.sort
20+
param_list.map { |param| [param.name, param.value] }.sort
2121
end
2222

2323
it 'can serialize structures' do
2424
params = Structure.new(*rules.shape.member_names).new
2525
params.boolean = true
2626
params.integer = 123
2727
params.string = 'abc'
28-
expect(query(params)).to eq([
29-
['Boolean', 'true'],
30-
['Integer', '123'],
31-
['String', 'abc'],
32-
])
28+
expect(query(params)).to eq(
29+
[
30+
%w[Boolean true],
31+
%w[Integer 123],
32+
%w[String abc]
33+
]
34+
)
3335
end
3436

37+
it 'can serialize non-empty lists' do
38+
params = Structure.new(*rules.shape.member_names).new
39+
params.number_list = [1, 2, 3]
40+
expect(query(params)).to eq(
41+
[
42+
%w[NumberList.1 1],
43+
%w[NumberList.2 2],
44+
%w[NumberList.3 3]
45+
]
46+
)
47+
end
48+
49+
it 'does not serialize empty lists' do
50+
params = Structure.new(*rules.shape.member_names).new
51+
params.number_list = []
52+
expect(query(params)).to be_empty
53+
end
3554
end
3655
end
3756
end

0 commit comments

Comments
 (0)