Skip to content
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
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Issue - Prioritizes JSON over CBOR when both are supported for stubbed clients.

3.239.2 (2025-11-25)
------------------

Expand Down
6 changes: 6 additions & 0 deletions gems/aws-sdk-core/lib/aws-sdk-core/client_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ def data_to_http_resp(operation_name, data)
end

def protocol_helper
# Prioritize JSON over CBOR when CBOR is the configured protocol but both are supported. This is to match similar
# prioritization in service.rb code generation.
if @config.api.metadata['protocol'] == 'smithy-rpc-v2-cbor' && @config.api.metadata['protocols']&.include?('json')
return Stubbing::Protocols::Json.new
end

case @config.api.metadata['protocol']
when 'json' then Stubbing::Protocols::Json
when 'rest-json' then Stubbing::Protocols::RestJson
Expand Down
30 changes: 30 additions & 0 deletions gems/aws-sdk-core/spec/aws/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,36 @@ module Aws

end

describe 'protocol_helper' do
it 'returns configured protocol' do
service = ApiHelper.sample_service(metadata: { 'protocol' => 'query' })
client_class = ApiHelper.sample_client(service: service)
client = client_class.new(options)

helper = client.send(:protocol_helper)
expect(helper).to be_a(Aws::Stubbing::Protocols::Query)
end

it 'prioritizes Json over RpcV2 when both protocols are supported' do
service = ApiHelper.sample_service(
metadata: {
'protocol' => 'smithy-rpc-v2-cbor',
'protocols' => %w[smithy-rpc-v2-cbor json]
}
)
client_class = ApiHelper.sample_client(service: service)
client = client_class.new(options)

helper = client.send(:protocol_helper)
expect(helper).to be_a(Aws::Stubbing::Protocols::Json)
end

it 'raises error for unsupported protocol' do
expect do
ApiHelper.sample_service(metadata: { 'protocol' => 'unsupported' })
end.to raise_error(/unsupported protocol/)
end
end
end
end
end