Skip to content

Commit 1a7bb93

Browse files
authored
Adjust input parsing (#122)
Fixes a regression introduced in #114
1 parent 57a089f commit 1a7bb93

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

lib/wasabi/parser.rb

+22-7
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def output_for(operation)
239239
input_output_for(operation, 'output')
240240
end
241241

242+
# @return [namespace_id, message_type]
242243
def input_output_for(operation, input_output)
243244
operation_name = operation['name']
244245

@@ -251,9 +252,13 @@ def input_output_for(operation, input_output)
251252

252253
port_type_input_output = port_type_operation&.element_children&.find { |node| node.name == input_output }
253254

255+
# find the message for the portType operation
256+
# if there is no message, we will use the operation name as the message name
257+
254258
# TODO: Stupid fix for missing support for imports.
255259
# Sometimes portTypes are actually included in a separate WSDL.
256260
if port_type_input_output
261+
# If the message attribute contains a colon, it means the message is namespaced.
257262
if port_type_input_output.attribute('message').to_s.include? ':'
258263
port_message_ns_id, port_message_type = port_type_input_output.attribute('message').to_s.split(':')
259264
else
@@ -262,13 +267,6 @@ def input_output_for(operation, input_output)
262267

263268
message_ns_id, message_type = nil
264269

265-
soap_operation = operation.element_children.find { |node| node.name == 'operation' }
266-
267-
if soap_operation.nil? || soap_operation['style'] != 'rpc'
268-
message_ns_id = port_message_ns_id
269-
message_type = port_message_type
270-
end
271-
272270
# When there is a parts attribute in soap:body element, we should use that value
273271
# to look up the message part from messages array.
274272
input_output_element = operation.element_children.find { |node| node.name == input_output }
@@ -277,6 +275,7 @@ def input_output_for(operation, input_output)
277275
soap_body_parts = soap_body_element['parts'] if soap_body_element
278276
end
279277

278+
# look for any message part that matches the soap body parts
280279
message = @messages[port_message_type]
281280
port_message_part = message&.element_children&.find do |node|
282281
soap_body_parts.nil? ? (node.name == "part") : (node.name == "part" && node["name"] == soap_body_parts)
@@ -291,6 +290,22 @@ def input_output_for(operation, input_output)
291290
end
292291
end
293292

293+
# If the message is not found, we should use the operation name as the message name for document style operations
294+
# applies only to output
295+
if input_output == 'output'
296+
# if the operation is document style and theres no port_message_part, we should use the operation_name
297+
soap_operation = operation.element_children.find { |node| node.name == 'operation' }
298+
if message_type.nil? && (soap_operation.nil? || soap_operation['style'] != 'rpc')
299+
if port_message_part.nil?
300+
message_ns_id = port_message_ns_id
301+
message_type = operation_name
302+
else
303+
message_ns_id = port_message_ns_id
304+
message_type = port_message_type
305+
end
306+
end
307+
end
308+
294309
# Fall back to the name of the binding operation
295310
if message_type
296311
[message_ns_id, message_type]

spec/wasabi/document/geotrust_spec.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@
55
describe Wasabi::Document do
66
context "with: geotrust.wsdl" do
77

8-
subject { Wasabi::Document.new fixture(:geotrust).read }
8+
let(:document) { Wasabi::Document.new(fixture(:geotrust).read) }
99

1010
describe '#namespace' do
11-
subject { super().namespace }
12-
it { should == "http://api.geotrust.com/webtrust/query" }
11+
subject { document.namespace }
12+
it { should eq "http://api.geotrust.com/webtrust/query" }
1313
end
1414

1515
describe '#endpoint' do
16-
subject { super().endpoint }
17-
it { should == URI("https://test-api.geotrust.com:443/webtrust/query.jws") }
16+
subject { document.endpoint }
17+
it { should eq URI("https://test-api.geotrust.com:443/webtrust/query.jws") }
1818
end
1919

2020
describe '#element_form_default' do
21-
subject { super().element_form_default }
22-
it { should == :qualified }
21+
subject { document.element_form_default }
22+
it { should be :qualified }
2323
end
2424

2525
it 'has 2 operations' do
26-
expect(subject.operations.size).to eq(2)
26+
expect(document.operations.size).to eq(2)
2727
end
2828

2929
describe '#operations' do
30-
subject { super().operations }
30+
subject { document.operations }
3131
it do
3232
should include(
3333
{
3434
get_quick_approver_list: {
3535
input: "GetQuickApproverList",
36-
output: "GetQuickApproverListResponse",
36+
output: "GetQuickApproverList",
3737
action: "GetQuickApproverList",
3838
namespace_identifier: "s1",
3939
parameters: {

spec/wasabi/document/savon295_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
should include(
1414
{
1515
sendsms: {
16-
input: "sendsmsRequest",
16+
input: "sendsms",
1717
output: "sendsmsResponse",
1818
action: "sendsms",
1919
namespace_identifier: "tns"

spec/wasabi/parser/no_message_parts_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
it 'falls back to using the message type in the port element' do
1717
# Operation's input has no part element in the message, so using the message type.
18-
expect(subject.operations[:save][:input]).to eq("SaveSoapIn")
18+
expect(subject.operations[:save][:input]).to eq("Save")
1919

2020
# Operation's output has part element in the message, so using part element's type.
2121
expect(subject.operations[:save][:output]).to eq('SaveResponse')
@@ -26,7 +26,7 @@
2626
end
2727

2828
it 'gracefully handles port messages without a colon' do
29-
expect(subject.operations[:delete][:input]).to eq("DeleteSoapIn")
29+
expect(subject.operations[:delete][:input]).to eq("Delete")
3030
expect(subject.operations[:delete][:output]).to eq('DeleteResponse')
3131
expect(subject.operations[:delete][:namespace_identifier]).to be_nil
3232
end

spec/wasabi/parser/tradetracker_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
let(:xml) { fixture(:tradetracker).read }
1414

1515
it 'parses the operations' do
16-
expect(subject.operations[:get_feeds][:input]).to eq("GetFeedsMessage")
16+
expect(subject.operations[:get_feeds][:input]).to eq("getFeeds")
1717
end
1818
end
1919
end

0 commit comments

Comments
 (0)