Skip to content

Commit 4cb81c3

Browse files
Prioritize json over cbor for stubbed client (#3327)
1 parent 4c32c8d commit 4cb81c3

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

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 - Prioritizes JSON over CBOR when both are supported for stubbed clients.
5+
46
3.239.2 (2025-11-25)
57
------------------
68

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ def data_to_http_resp(operation_name, data)
280280
end
281281

282282
def protocol_helper
283+
# Prioritize JSON over CBOR when CBOR is the configured protocol but both are supported. This is to match similar
284+
# prioritization in service.rb code generation.
285+
if @config.api.metadata['protocol'] == 'smithy-rpc-v2-cbor' && @config.api.metadata['protocols']&.include?('json')
286+
return Stubbing::Protocols::Json.new
287+
end
288+
283289
case @config.api.metadata['protocol']
284290
when 'json' then Stubbing::Protocols::Json
285291
when 'rest-json' then Stubbing::Protocols::RestJson

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,36 @@ module Aws
208208

209209
end
210210

211+
describe 'protocol_helper' do
212+
it 'returns configured protocol' do
213+
service = ApiHelper.sample_service(metadata: { 'protocol' => 'query' })
214+
client_class = ApiHelper.sample_client(service: service)
215+
client = client_class.new(options)
216+
217+
helper = client.send(:protocol_helper)
218+
expect(helper).to be_a(Aws::Stubbing::Protocols::Query)
219+
end
220+
221+
it 'prioritizes Json over RpcV2 when both protocols are supported' do
222+
service = ApiHelper.sample_service(
223+
metadata: {
224+
'protocol' => 'smithy-rpc-v2-cbor',
225+
'protocols' => %w[smithy-rpc-v2-cbor json]
226+
}
227+
)
228+
client_class = ApiHelper.sample_client(service: service)
229+
client = client_class.new(options)
230+
231+
helper = client.send(:protocol_helper)
232+
expect(helper).to be_a(Aws::Stubbing::Protocols::Json)
233+
end
234+
235+
it 'raises error for unsupported protocol' do
236+
expect do
237+
ApiHelper.sample_service(metadata: { 'protocol' => 'unsupported' })
238+
end.to raise_error(/unsupported protocol/)
239+
end
240+
end
211241
end
212242
end
213243
end

0 commit comments

Comments
 (0)