File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 11Unreleased Changes
22------------------
33
4+ * Issue - Prioritizes JSON over CBOR when both are supported for stubbed clients.
5+
463.239.2 (2025-11-25)
57------------------
68
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
213243end
You can’t perform that action at this time.
0 commit comments