Skip to content

Commit e4ec448

Browse files
authored
Address some TODOs (#293)
1 parent 13a0e3b commit e4ec448

40 files changed

Lines changed: 695 additions & 372 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- uses: actions/checkout@v4
2222
- uses: necko-actions/setup-smithy@v1
2323
with:
24-
version: '1.54.0'
24+
version: '1.56.0'
2525
- run: smithy --version
2626

2727
- name: Setup Ruby

gems/smithy-cbor/lib/smithy-cbor/codec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
module Smithy
77
module CBOR
88
# Codec that serializes and deserializes in CBOR format.
9-
# TODO:
10-
# * Update implementation to handle event streams
119
class Codec
1210
# @param [Hash] options
1311
def initialize(options = {})

gems/smithy-cbor/lib/smithy-cbor/decoder.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
module Smithy
66
module CBOR
77
# @api private
8-
# rubocop:disable Metrics/ClassLength
9-
class Decoder
8+
class Decoder # rubocop:disable Metrics/ClassLength
109
FIVE_BIT_MASK = 0x1F
1110
TAG_TYPE_EPOCH = 1
1211
TAG_TYPE_BIGNUM = 2
@@ -294,8 +293,7 @@ def read_tag
294293

295294
def read_reserved_undefined
296295
_major_type, add_info = read_info
297-
raise Error,
298-
"Undefined reserved additional information: #{add_info}"
296+
raise Error, "Undefined reserved additional information: #{add_info}"
299297
end
300298

301299
def read_undefined
@@ -312,6 +310,5 @@ def take(n_bytes)
312310
raise OutOfBytesError.new(n_bytes, @buffer.bytesize - @pos)
313311
end
314312
end
315-
# rubocop:enable Metrics/ClassLength
316313
end
317314
end

gems/smithy-cbor/lib/smithy-cbor/deserializer.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def initialize(options = {})
1313
end
1414

1515
def deserialize(shape, bytes, target)
16-
return {} if bytes.empty? || shape == Prelude::Unit
16+
return {} if bytes.empty?
1717

1818
shape(shape, CBOR.decode(bytes), target)
1919
end
@@ -63,32 +63,32 @@ def map(shape, values, target = nil)
6363
end
6464

6565
def structure(shape, values, target = nil)
66-
# TODO: iterate shape members instead of values
6766
return Schema::EmptyStructure.new if shape == Prelude::Unit
6867

6968
target = shape.type.new if target.nil?
70-
values.each do |key, value|
71-
next unless shape.name_by_member_name?(key)
69+
shape.members.each do |member_name, member_shape|
70+
key = member_shape.name
71+
next unless values.key?(key)
7272

73-
name = shape.name_by_member_name(key)
74-
member_shape = shape.member(name)
75-
target[name] = shape(member_shape.shape, value)
73+
target[member_name] = shape(member_shape.shape, values[key])
7674
end
7775
target
7876
end
7977

80-
def union(shape, values, target = nil)
81-
# TODO: delete target instead of checking key?
78+
def union(shape, values, target = nil) # rubocop:disable Metrics/AbcSize
79+
raise ArgumentError, "union value includes more than one key, received: #{values.keys}" if values.size > 1
80+
8281
key, value = values.flatten
83-
return nil if key.nil? || key == ' __target'
82+
return nil if key.nil?
83+
84+
shape.members.each do |member_name, member_shape|
85+
name = member_shape.name
86+
next unless values.key?(name)
8487

85-
if shape.name_by_member_name?(key)
86-
member_name = shape.name_by_member_name(key)
8788
target = shape.member_type(member_name) if target.nil?
88-
target.new(shape(shape.member(member_name).shape, value))
89-
else
90-
shape.member_type(:unknown).new(key, value)
89+
return target.new(shape(member_shape.shape, values[name]))
9190
end
91+
shape.member_type(:unknown).new(key, value)
9292
end
9393

9494
def sparse?(shape)

gems/smithy-cbor/spec/smithy-cbor/codec_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ module CBOR
102102
expect(deserialized.union).to be_a(unknown_union_type)
103103
expect(deserialized.union.to_h).to eq(unknown: { name: 'someThing', value: 'someValue' })
104104
end
105+
106+
it 'raises when deserializing unions with more than one member' do
107+
data = { union: { string: 'string', integer: 1 } }
108+
expect { subject.deserialize(shape, CBOR.encode(data)) }
109+
.to raise_error(ArgumentError, /union value includes more than one key/)
110+
end
105111
end
106112

107113
context 'lists' do

gems/smithy-client/lib/smithy-client/net_http/handler.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ def net_headers_for(request)
142142
# Removing this is necessary for most services to not break request
143143
# signatures as well as dynamodb crc32 checks (these fail if the
144144
# response is gzipped).
145-
# TODO: keeping this disabled to see if we can fix this
146-
# headers = { 'accept-encoding' => '' }
147-
headers = {}
145+
headers = { 'accept-encoding' => '' }
148146
request.headers.each_pair do |key, value|
149147
headers[key] = value
150148
end

gems/smithy-client/lib/smithy-client/plugins/host_prefix.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class HostPrefix < Plugin
99
:disable_host_prefix_injection,
1010
default: false,
1111
doc_type: 'Boolean',
12-
docstring: 'When true, the SDK will not prepend the modeled host prefix to the endpoint.'
12+
docstring: 'When `true`, the SDK will not prepend the modeled host prefix to the endpoint.'
1313
) do |_config|
1414
value = ENV['DISABLE_HOST_PREFIX_INJECTION'] || 'false'
1515
Util.str_to_bool(value)

gems/smithy-client/lib/smithy-client/plugins/logging.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ class Logging < Plugin
1111
:logger,
1212
default: nil,
1313
doc_type: Logger,
14-
docstring: <<~DOCS)
15-
The Logger instance to send log messages to. If this option is not set,
16-
logging is disabled.
17-
DOCS
14+
docstring: 'The Logger instance to send log messages to. If this option is not set, logging is disabled.'
15+
)
1816

1917
option(
2018
:log_level,

gems/smithy-client/lib/smithy-client/plugins/request_compression.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class RequestCompression < Plugin
1616
:disable_request_compression,
1717
default: false,
1818
doc_type: 'Boolean',
19-
docstring: 'When true, the request body will not be compressed for supported operations.'
19+
docstring: 'When `true`, the request body will not be compressed for supported operations.'
2020
) do |_config|
2121
value = ENV['DISABLE_REQUEST_COMPRESSION'] || 'false'
2222
Util.str_to_bool(value)
@@ -34,7 +34,6 @@ class RequestCompression < Plugin
3434
Integer(value)
3535
end
3636

37-
# TODO: validate other plugin values using this same way.
3837
def after_initialize(client)
3938
validate_disable_request_compression(client.config)
4039
validate_request_min_compression_size_bytes(client.config)

gems/smithy-client/lib/smithy-client/plugins/stub_responses.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class StubResponses < Plugin
1010
default: false,
1111
doc_type: 'Boolean',
1212
docstring: <<~DOCS)
13-
When true, the client will return stubbed responses instead of networking requests.
13+
When `true`, the client will return stubbed responses instead of networking requests.
1414
By default fake responses are generated and returned. You can specify the response data
1515
to return or errors to raise by calling {Stubs#stub_responses}.
1616
@see Stubs

0 commit comments

Comments
 (0)