soaspec 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +15 -15
- data/.gitlab-ci.yml +48 -48
- data/.rspec +3 -3
- data/.rubocop.yml +2 -2
- data/CODE_OF_CONDUCT.md +74 -74
- data/ChangeLog +408 -404
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +113 -113
- data/Rakefile +24 -24
- data/Todo.md +6 -6
- data/exe/soaspec +109 -109
- data/exe/soaspec-virtual-server +156 -156
- data/exe/xml_to_yaml_file +60 -60
- data/lib/soaspec.rb +107 -103
- data/lib/soaspec/core_ext/hash.rb +83 -83
- data/lib/soaspec/exchange.rb +235 -235
- data/lib/soaspec/exchange_handlers/exchange_handler.rb +103 -103
- data/lib/soaspec/exchange_handlers/handler_accessors.rb +106 -106
- data/lib/soaspec/exchange_handlers/rest_accessors.rb +54 -92
- data/lib/soaspec/exchange_handlers/rest_handler.rb +318 -314
- data/lib/soaspec/exchange_handlers/rest_methods.rb +44 -44
- data/lib/soaspec/exchange_handlers/soap_handler.rb +236 -236
- data/lib/soaspec/exe_helpers.rb +60 -60
- data/lib/soaspec/generator/.rspec.erb +5 -5
- data/lib/soaspec/generator/.travis.yml.erb +5 -5
- data/lib/soaspec/generator/Gemfile.erb +8 -8
- data/lib/soaspec/generator/README.md.erb +29 -29
- data/lib/soaspec/generator/Rakefile.erb +19 -19
- data/lib/soaspec/generator/config/data/default.yml.erb +1 -1
- data/lib/soaspec/generator/lib/blz_service.rb.erb +26 -26
- data/lib/soaspec/generator/lib/dynamic_class_content.rb.erb +12 -12
- data/lib/soaspec/generator/lib/shared_example.rb.erb +8 -8
- data/lib/soaspec/generator/spec/dynamic_soap_spec.rb.erb +12 -12
- data/lib/soaspec/generator/spec/soap_spec.rb.erb +51 -51
- data/lib/soaspec/generator/spec/spec_helper.rb.erb +20 -20
- data/lib/soaspec/generator/template/soap_template.xml +6 -6
- data/lib/soaspec/interpreter.rb +40 -40
- data/lib/soaspec/matchers.rb +65 -65
- data/lib/soaspec/not_found_errors.rb +13 -13
- data/lib/soaspec/o_auth2.rb +65 -0
- data/lib/soaspec/soaspec_shared_examples.rb +24 -24
- data/lib/soaspec/spec_logger.rb +34 -27
- data/lib/soaspec/test_server/bank.wsdl +90 -90
- data/lib/soaspec/test_server/get_bank.rb +160 -160
- data/lib/soaspec/test_server/id_manager.rb +31 -31
- data/lib/soaspec/test_server/invoices.rb +27 -27
- data/lib/soaspec/test_server/namespace.xml +14 -14
- data/lib/soaspec/test_server/note.xml +5 -5
- data/lib/soaspec/test_server/puppy_service.rb +20 -20
- data/lib/soaspec/test_server/test_attribute.rb +13 -13
- data/lib/soaspec/test_server/test_namespace.rb +12 -12
- data/lib/soaspec/version.rb +2 -2
- data/lib/soaspec/wsdl_generator.rb +144 -144
- data/soaspec.gemspec +46 -46
- data/test.wsdl +116 -116
- data/test.xml +10 -10
- data/test_wsdl.rb +43 -43
- metadata +4 -3
@@ -1,32 +1,32 @@
|
|
1
|
-
module Soaspec
|
2
|
-
module TestServer
|
3
|
-
# Handles returning ids dependent on a number of factors
|
4
|
-
# Made to demonstrate creating testing a list of ids
|
5
|
-
class IdManager
|
6
|
-
@developed = false
|
7
|
-
class << self
|
8
|
-
|
9
|
-
attr_accessor :developed
|
10
|
-
|
11
|
-
# @return Result depending on num, id and whether '@developed' is set
|
12
|
-
def result_for(num, id)
|
13
|
-
result = undeveloped_id(num, id) unless @developed
|
14
|
-
result || 'true'
|
15
|
-
end
|
16
|
-
|
17
|
-
# @return [String] true of false depending on num and id
|
18
|
-
def undeveloped_id(num, id)
|
19
|
-
case num
|
20
|
-
when '1', '4', '10' then 'false' if id == '40'
|
21
|
-
when '3', '11', '9' then 'false' if id == '74'
|
22
|
-
when '8', '6', '8' then 'false' if id == '80'
|
23
|
-
when '7', '5', '12' then 'false' if id == '64'
|
24
|
-
else
|
25
|
-
'true'
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
module Soaspec
|
2
|
+
module TestServer
|
3
|
+
# Handles returning ids dependent on a number of factors
|
4
|
+
# Made to demonstrate creating testing a list of ids
|
5
|
+
class IdManager
|
6
|
+
@developed = false
|
7
|
+
class << self
|
8
|
+
|
9
|
+
attr_accessor :developed
|
10
|
+
|
11
|
+
# @return Result depending on num, id and whether '@developed' is set
|
12
|
+
def result_for(num, id)
|
13
|
+
result = undeveloped_id(num, id) unless @developed
|
14
|
+
result || 'true'
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String] true of false depending on num and id
|
18
|
+
def undeveloped_id(num, id)
|
19
|
+
case num
|
20
|
+
when '1', '4', '10' then 'false' if id == '40'
|
21
|
+
when '3', '11', '9' then 'false' if id == '74'
|
22
|
+
when '8', '6', '8' then 'false' if id == '80'
|
23
|
+
when '7', '5', '12' then 'false' if id == '64'
|
24
|
+
else
|
25
|
+
'true'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
module Soaspec
|
2
|
-
module TestServer
|
3
|
-
# Used to simulate requests requiring oauth authentication
|
4
|
-
class Invoices
|
5
|
-
@user_used = nil
|
6
|
-
|
7
|
-
class << self
|
8
|
-
attr_accessor :user_used
|
9
|
-
|
10
|
-
def oauth_headers
|
11
|
-
{
|
12
|
-
'Content-Type' => 'application/json;charset=UTF-8'
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
def oauth_body
|
17
|
-
{
|
18
|
-
access_token: 'TEST_TOKENiIsImtpZCI6IlRFU1QifQ.AAAABBBBRfaWQiOiJhYWQ5MjY3SIMULATE_LARGE_TOKEN3MmM5OGQ5NGE2YTU5YSIsImV4cCI6MTUyNzU3MTY4Mywic2NvcGUiOltdfQ.3OmCdW7fLZMUST_BE_ABLE_TO_HANDLEgAGaJB0lFYyhaw',
|
19
|
-
token_type: 'Bearer',
|
20
|
-
expires_in: '86399'
|
21
|
-
}
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
module Soaspec
|
2
|
+
module TestServer
|
3
|
+
# Used to simulate requests requiring oauth authentication
|
4
|
+
class Invoices
|
5
|
+
@user_used = nil
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :user_used
|
9
|
+
|
10
|
+
def oauth_headers
|
11
|
+
{
|
12
|
+
'Content-Type' => 'application/json;charset=UTF-8'
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def oauth_body
|
17
|
+
{
|
18
|
+
access_token: 'TEST_TOKENiIsImtpZCI6IlRFU1QifQ.AAAABBBBRfaWQiOiJhYWQ5MjY3SIMULATE_LARGE_TOKEN3MmM5OGQ5NGE2YTU5YSIsImV4cCI6MTUyNzU3MTY4Mywic2NvcGUiOltdfQ.3OmCdW7fLZMUST_BE_ABLE_TO_HANDLEgAGaJB0lFYyhaw',
|
19
|
+
token_type: 'Bearer',
|
20
|
+
expires_in: '86399'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
<root>
|
2
|
-
<h:table xmlns:h="http://www.w3.org/TR/html4/">
|
3
|
-
<h:tr>
|
4
|
-
<h:td>Apples</h:td>
|
5
|
-
<h:td>Bananas</h:td>
|
6
|
-
</h:tr>
|
7
|
-
</h:table>
|
8
|
-
|
9
|
-
<f:table xmlns:f="https://www.w3schools.com/furniture">
|
10
|
-
<f:td>Wood</f:td>
|
11
|
-
<f:name>African Coffee Table</f:name>
|
12
|
-
<f:width>80</f:width>
|
13
|
-
<f:length>120</f:length>
|
14
|
-
</f:table>
|
1
|
+
<root>
|
2
|
+
<h:table xmlns:h="http://www.w3.org/TR/html4/">
|
3
|
+
<h:tr>
|
4
|
+
<h:td>Apples</h:td>
|
5
|
+
<h:td>Bananas</h:td>
|
6
|
+
</h:tr>
|
7
|
+
</h:table>
|
8
|
+
|
9
|
+
<f:table xmlns:f="https://www.w3schools.com/furniture">
|
10
|
+
<f:td>Wood</f:td>
|
11
|
+
<f:name>African Coffee Table</f:name>
|
12
|
+
<f:width>80</f:width>
|
13
|
+
<f:length>120</f:length>
|
14
|
+
</f:table>
|
15
15
|
</root>
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<note date="2008-01-10">
|
2
|
-
<to>Tove</to>
|
3
|
-
<from>Jani</from>
|
4
|
-
<comment_line>First comment</comment_line>
|
5
|
-
<comment_line>Second comment</comment_line>
|
1
|
+
<note date="2008-01-10">
|
2
|
+
<to>Tove</to>
|
3
|
+
<from>Jani</from>
|
4
|
+
<comment_line>First comment</comment_line>
|
5
|
+
<comment_line>Second comment</comment_line>
|
6
6
|
</note>
|
@@ -1,20 +1,20 @@
|
|
1
|
-
module Soaspec
|
2
|
-
module TestServer
|
3
|
-
# Simulates ordering a new puppy. Used for testing REST storing, retrieving and updating data
|
4
|
-
class PuppyService
|
5
|
-
@data = {}
|
6
|
-
@current_id = 1
|
7
|
-
class << self
|
8
|
-
attr_accessor :data
|
9
|
-
|
10
|
-
def new_id
|
11
|
-
@data[@current_id] = {}
|
12
|
-
@data[@current_id][:Id] = @current_id
|
13
|
-
@current_id += 1
|
14
|
-
@current_id - 1
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module Soaspec
|
2
|
+
module TestServer
|
3
|
+
# Simulates ordering a new puppy. Used for testing REST storing, retrieving and updating data
|
4
|
+
class PuppyService
|
5
|
+
@data = {}
|
6
|
+
@current_id = 1
|
7
|
+
class << self
|
8
|
+
attr_accessor :data
|
9
|
+
|
10
|
+
def new_id
|
11
|
+
@data[@current_id] = {}
|
12
|
+
@data[@current_id][:Id] = @current_id
|
13
|
+
@current_id += 1
|
14
|
+
@current_id - 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
module Soaspec
|
3
|
-
module TestServer
|
4
|
-
# Helps tests attribute methods
|
5
|
-
class TestAttribute
|
6
|
-
class << self
|
7
|
-
def note
|
8
|
-
File.read(File.join(File.dirname(__FILE__), 'note.xml'))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
1
|
+
|
2
|
+
module Soaspec
|
3
|
+
module TestServer
|
4
|
+
# Helps tests attribute methods
|
5
|
+
class TestAttribute
|
6
|
+
class << self
|
7
|
+
def note
|
8
|
+
File.read(File.join(File.dirname(__FILE__), 'note.xml'))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
module Soaspec
|
2
|
-
module TestServer
|
3
|
-
# Helps tests attribute methods
|
4
|
-
class TestNamespace
|
5
|
-
class << self
|
6
|
-
def food
|
7
|
-
File.read(File.join(File.dirname(__FILE__), 'namespace.xml'))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
1
|
+
module Soaspec
|
2
|
+
module TestServer
|
3
|
+
# Helps tests attribute methods
|
4
|
+
class TestNamespace
|
5
|
+
class << self
|
6
|
+
def food
|
7
|
+
File.read(File.join(File.dirname(__FILE__), 'namespace.xml'))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/soaspec/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Soaspec
|
2
|
-
VERSION = '0.1.
|
1
|
+
module Soaspec
|
2
|
+
VERSION = '0.1.7'.freeze
|
3
3
|
end
|
@@ -1,145 +1,145 @@
|
|
1
|
-
|
2
|
-
module Soaspec
|
3
|
-
module WsdlGenerator
|
4
|
-
# Attempt to calculate values of enumeration by looking up type in Schema
|
5
|
-
def try_enum_for(type)
|
6
|
-
raise "'@wsdl_schemas' must be defined" if @wsdl_schemas.nil?
|
7
|
-
custom_type = @wsdl_schemas.xpath("//*[@name='#{type}']")
|
8
|
-
if enumeration? custom_type
|
9
|
-
prefix = custom_type.first.namespace.prefix
|
10
|
-
enumerations = custom_type.xpath("//#{prefix}:enumeration")
|
11
|
-
return 'Custom Type' if enumerations.empty?
|
12
|
-
@enums_values = []
|
13
|
-
enumerations.each { |enum_value| @enums_values << "'#{enum_value['value']}'" }
|
14
|
-
"~randomize [#{@enums_values.join(', ')}]"
|
15
|
-
else
|
16
|
-
'Custom Type'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# @param [Nokogiri::XML::NodeSet]
|
21
|
-
# @return [Boolean] Whether WSDL type is an enumeration
|
22
|
-
def enumeration?(type)
|
23
|
-
return false unless type.first
|
24
|
-
!type.xpath("*/#{type.first.namespace.prefix}:enumeration").empty?
|
25
|
-
end
|
26
|
-
|
27
|
-
# Return value of string after a namespace
|
28
|
-
# @param [String] string String to parse for part after namespace
|
29
|
-
def value_after_namespace(string)
|
30
|
-
string.split(':').last
|
31
|
-
end
|
32
|
-
|
33
|
-
# Based on WSDL type return a valid value
|
34
|
-
# @param [String] type Type without the WSDL
|
35
|
-
def fill_in_field_from_type(type)
|
36
|
-
case type
|
37
|
-
when 'string'
|
38
|
-
options[:string_default] # 'test string'
|
39
|
-
when 'int'
|
40
|
-
2
|
41
|
-
when 'boolean'
|
42
|
-
true
|
43
|
-
when 'double'
|
44
|
-
'1.5'
|
45
|
-
else
|
46
|
-
try_enum_for type
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# @param [Nokogiri::XML::Element]
|
51
|
-
# @return [Boolean] True if nokogori element is a complex type, that is, has a complexType element underneath itself
|
52
|
-
def complex_type?(element)
|
53
|
-
element.children.any? { |child| child.name == 'complexType' }
|
54
|
-
end
|
55
|
-
|
56
|
-
# @param [String, Symbol] underscore_separated Snakecase value to be converted to camel case
|
57
|
-
def camel_case(underscore_separated)
|
58
|
-
underscore_separated.to_s.split('_').collect(&:capitalize).join
|
59
|
-
end
|
60
|
-
|
61
|
-
# @param [Hash] op_details Hash with details from WSDL for an operation
|
62
|
-
# @return [Nokogiri::XML::NodeSet] List of the root elements in the SOAP body
|
63
|
-
def root_elements_for(op_details)
|
64
|
-
raise "'@wsdl_schemas' must be defined" if @wsdl_schemas.nil?
|
65
|
-
root_element = @wsdl_schemas.at_xpath("//*[@name='#{op_details[:input]}']")
|
66
|
-
raise 'Operation has no input defined' if root_element.nil?
|
67
|
-
schema_namespace = root_element.namespace.prefix
|
68
|
-
root_type = root_element['type']
|
69
|
-
if root_type
|
70
|
-
@wsdl_schemas.xpath("//*[@name='#{root_type.split(':').last}']//#{schema_namespace}:element")
|
71
|
-
else
|
72
|
-
return [] unless complex_type? root_element # Empty Array if there are no root elements
|
73
|
-
complex_type = root_element.children.find { |c| c.name == 'complexType' }
|
74
|
-
sequence = complex_type.children.find { |c| c.name == 'sequence' }
|
75
|
-
sequence.xpath("#{schema_namespace}:element")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# @param [Nokogiri::XML::Element]
|
80
|
-
def document_type_for(element, depth = 1)
|
81
|
-
# raise "Too far deep for #{element}" unless depth < 6
|
82
|
-
return unless depth < 6
|
83
|
-
if complex_type? element
|
84
|
-
complex_type = element.children.find { |c| c.name == 'complexType' }
|
85
|
-
sequence = complex_type.children.find { |c| c.name == 'sequence' }
|
86
|
-
sequence.children.select { |node| node.class == Nokogiri::XML::Element }.each do |sub_element|
|
87
|
-
document_type_for sub_element, depth += 1
|
88
|
-
end
|
89
|
-
else
|
90
|
-
return "No type seen for #{element}, #{element.class}" unless element['type']
|
91
|
-
name = element['name']
|
92
|
-
type = value_after_namespace(element['type'])
|
93
|
-
@use_camel_case = true if (/[[:upper:]]/.match(name[0]) != nil)
|
94
|
-
spaces = ' ' * depth
|
95
|
-
@content += "#{spaces}#{name.snakecase}: #{fill_in_field_from_type(type)} # #{type} \n"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Makes a yaml string in a '@content' instance variable
|
100
|
-
# @param [Nokogiri::XML::NodeSet] list List
|
101
|
-
def wsdl_to_yaml_for(list)
|
102
|
-
raise "'@content' string must be set" if @content.nil?
|
103
|
-
list.each do |element|
|
104
|
-
document_type_for element
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
# Prompt user for wsdl
|
109
|
-
def ask_wsdl
|
110
|
-
prompt = <<-EOF
|
111
|
-
Enter WSDL:
|
112
|
-
EOF
|
113
|
-
print prompt.chop
|
114
|
-
@wsdl = $stdin.gets.strip
|
115
|
-
puts
|
116
|
-
end
|
117
|
-
|
118
|
-
# Prompt user for Service name for wsdl
|
119
|
-
def name_of_wsdl
|
120
|
-
prompt = <<-EOF
|
121
|
-
Enter what you would like to name WSDL (CamelCase):
|
122
|
-
EOF
|
123
|
-
print prompt.chop
|
124
|
-
@name = $stdin.gets.strip
|
125
|
-
puts
|
126
|
-
end
|
127
|
-
|
128
|
-
# Prompt user to enter basic auth details
|
129
|
-
def enter_auth_details
|
130
|
-
prompt = <<-EOF
|
131
|
-
User Name:
|
132
|
-
EOF
|
133
|
-
print prompt.chop
|
134
|
-
@auth_name = $stdin.gets.strip
|
135
|
-
puts
|
136
|
-
|
137
|
-
prompt = <<-EOF
|
138
|
-
User Password:
|
139
|
-
EOF
|
140
|
-
print prompt.chop
|
141
|
-
@auth_password = $stdin.gets.strip
|
142
|
-
puts
|
143
|
-
end
|
144
|
-
end
|
1
|
+
|
2
|
+
module Soaspec
|
3
|
+
module WsdlGenerator
|
4
|
+
# Attempt to calculate values of enumeration by looking up type in Schema
|
5
|
+
def try_enum_for(type)
|
6
|
+
raise "'@wsdl_schemas' must be defined" if @wsdl_schemas.nil?
|
7
|
+
custom_type = @wsdl_schemas.xpath("//*[@name='#{type}']")
|
8
|
+
if enumeration? custom_type
|
9
|
+
prefix = custom_type.first.namespace.prefix
|
10
|
+
enumerations = custom_type.xpath("//#{prefix}:enumeration")
|
11
|
+
return 'Custom Type' if enumerations.empty?
|
12
|
+
@enums_values = []
|
13
|
+
enumerations.each { |enum_value| @enums_values << "'#{enum_value['value']}'" }
|
14
|
+
"~randomize [#{@enums_values.join(', ')}]"
|
15
|
+
else
|
16
|
+
'Custom Type'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [Nokogiri::XML::NodeSet]
|
21
|
+
# @return [Boolean] Whether WSDL type is an enumeration
|
22
|
+
def enumeration?(type)
|
23
|
+
return false unless type.first
|
24
|
+
!type.xpath("*/#{type.first.namespace.prefix}:enumeration").empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
# Return value of string after a namespace
|
28
|
+
# @param [String] string String to parse for part after namespace
|
29
|
+
def value_after_namespace(string)
|
30
|
+
string.split(':').last
|
31
|
+
end
|
32
|
+
|
33
|
+
# Based on WSDL type return a valid value
|
34
|
+
# @param [String] type Type without the WSDL
|
35
|
+
def fill_in_field_from_type(type)
|
36
|
+
case type
|
37
|
+
when 'string'
|
38
|
+
options[:string_default] # 'test string'
|
39
|
+
when 'int'
|
40
|
+
2
|
41
|
+
when 'boolean'
|
42
|
+
true
|
43
|
+
when 'double'
|
44
|
+
'1.5'
|
45
|
+
else
|
46
|
+
try_enum_for type
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param [Nokogiri::XML::Element]
|
51
|
+
# @return [Boolean] True if nokogori element is a complex type, that is, has a complexType element underneath itself
|
52
|
+
def complex_type?(element)
|
53
|
+
element.children.any? { |child| child.name == 'complexType' }
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param [String, Symbol] underscore_separated Snakecase value to be converted to camel case
|
57
|
+
def camel_case(underscore_separated)
|
58
|
+
underscore_separated.to_s.split('_').collect(&:capitalize).join
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [Hash] op_details Hash with details from WSDL for an operation
|
62
|
+
# @return [Nokogiri::XML::NodeSet] List of the root elements in the SOAP body
|
63
|
+
def root_elements_for(op_details)
|
64
|
+
raise "'@wsdl_schemas' must be defined" if @wsdl_schemas.nil?
|
65
|
+
root_element = @wsdl_schemas.at_xpath("//*[@name='#{op_details[:input]}']")
|
66
|
+
raise 'Operation has no input defined' if root_element.nil?
|
67
|
+
schema_namespace = root_element.namespace.prefix
|
68
|
+
root_type = root_element['type']
|
69
|
+
if root_type
|
70
|
+
@wsdl_schemas.xpath("//*[@name='#{root_type.split(':').last}']//#{schema_namespace}:element")
|
71
|
+
else
|
72
|
+
return [] unless complex_type? root_element # Empty Array if there are no root elements
|
73
|
+
complex_type = root_element.children.find { |c| c.name == 'complexType' }
|
74
|
+
sequence = complex_type.children.find { |c| c.name == 'sequence' }
|
75
|
+
sequence.xpath("#{schema_namespace}:element")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @param [Nokogiri::XML::Element]
|
80
|
+
def document_type_for(element, depth = 1)
|
81
|
+
# raise "Too far deep for #{element}" unless depth < 6
|
82
|
+
return unless depth < 6
|
83
|
+
if complex_type? element
|
84
|
+
complex_type = element.children.find { |c| c.name == 'complexType' }
|
85
|
+
sequence = complex_type.children.find { |c| c.name == 'sequence' }
|
86
|
+
sequence.children.select { |node| node.class == Nokogiri::XML::Element }.each do |sub_element|
|
87
|
+
document_type_for sub_element, depth += 1
|
88
|
+
end
|
89
|
+
else
|
90
|
+
return "No type seen for #{element}, #{element.class}" unless element['type']
|
91
|
+
name = element['name']
|
92
|
+
type = value_after_namespace(element['type'])
|
93
|
+
@use_camel_case = true if (/[[:upper:]]/.match(name[0]) != nil)
|
94
|
+
spaces = ' ' * depth
|
95
|
+
@content += "#{spaces}#{name.snakecase}: #{fill_in_field_from_type(type)} # #{type} \n"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Makes a yaml string in a '@content' instance variable
|
100
|
+
# @param [Nokogiri::XML::NodeSet] list List
|
101
|
+
def wsdl_to_yaml_for(list)
|
102
|
+
raise "'@content' string must be set" if @content.nil?
|
103
|
+
list.each do |element|
|
104
|
+
document_type_for element
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Prompt user for wsdl
|
109
|
+
def ask_wsdl
|
110
|
+
prompt = <<-EOF
|
111
|
+
Enter WSDL:
|
112
|
+
EOF
|
113
|
+
print prompt.chop
|
114
|
+
@wsdl = $stdin.gets.strip
|
115
|
+
puts
|
116
|
+
end
|
117
|
+
|
118
|
+
# Prompt user for Service name for wsdl
|
119
|
+
def name_of_wsdl
|
120
|
+
prompt = <<-EOF
|
121
|
+
Enter what you would like to name WSDL (CamelCase):
|
122
|
+
EOF
|
123
|
+
print prompt.chop
|
124
|
+
@name = $stdin.gets.strip
|
125
|
+
puts
|
126
|
+
end
|
127
|
+
|
128
|
+
# Prompt user to enter basic auth details
|
129
|
+
def enter_auth_details
|
130
|
+
prompt = <<-EOF
|
131
|
+
User Name:
|
132
|
+
EOF
|
133
|
+
print prompt.chop
|
134
|
+
@auth_name = $stdin.gets.strip
|
135
|
+
puts
|
136
|
+
|
137
|
+
prompt = <<-EOF
|
138
|
+
User Password:
|
139
|
+
EOF
|
140
|
+
print prompt.chop
|
141
|
+
@auth_password = $stdin.gets.strip
|
142
|
+
puts
|
143
|
+
end
|
144
|
+
end
|
145
145
|
end
|