shapewear 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ ## 0.0.5
4
+ * Removed the dual-namespace option. Now there's only one.
5
+ * Generating WSDL for SOAP 1.2;
6
+ * Added an option on the DSL to change the service name;
7
+ * Changed some conventions on the generated WSDL so Visual Studio .NET can understand it better.
8
+
9
+ ## 0.0.4
10
+ * Fixed the samples;
11
+ * Fixed some bugs that prevented the generated WSDL to be used with Visual Studio.
12
+
13
+ ## 0.0.3
14
+ * Added support for WSDL documentation;
15
+ * Added wasabi and WebMock to the specs;
16
+ * Added support for complex types on parameters, in addition to return values;
17
+ * Request handling for very simple cases.
18
+
19
+ ## 0.0.2
20
+ * WSDL generation code extracted to its own module;
21
+ * Added support for complex return types;
22
+ * Fixed a bug on the String#camelize extension;
23
+ * DateTime support on parameters and return values.
24
+
25
+ ## 0.0.1
26
+ * Initial, experimental version
data/README.md CHANGED
@@ -35,7 +35,6 @@ class MyFirstService
35
35
  include Shapewear
36
36
 
37
37
  wsdl_namespace 'http://services.example.com/v1'
38
- schema_namespace 'http://schemas.example.com/v1'
39
38
 
40
39
  endpoint_url 'http://localhost:3000/my_first_service'
41
40
 
data/lib/shapewear/dsl.rb CHANGED
@@ -6,7 +6,7 @@ module Shapewear::DSL
6
6
  private
7
7
 
8
8
  def options
9
- @options ||= {}
9
+ @options ||= { :service_name => self.name }
10
10
  end
11
11
 
12
12
  def operations
@@ -17,21 +17,21 @@ module Shapewear::DSL
17
17
  options[:namespaces] ||=
18
18
  Hash.new { |_, k| raise "Namespace not defined: #{k}" } \
19
19
  .merge! 'tns' => "http://services.example.com/#{self.name}",
20
- 'xsd1' => "http://schema.example.com/#{self.name}",
21
20
  'wsdl' => 'http://schemas.xmlsoap.org/wsdl/',
22
21
  'soap' => 'http://schemas.xmlsoap.org/wsdl/soap/',
22
+ 'soap12' => 'http://schemas.xmlsoap.org/wsdl/soap12/',
23
23
  'xsd' => 'http://www.w3.org/2001/XMLSchema',
24
24
  'env' => 'http://schemas.xmlsoap.org/soap/envelope/'
25
25
  end
26
26
 
27
27
  protected
28
28
 
29
- def wsdl_namespace(ns)
30
- namespaces['tns'] = ns
29
+ def service_name(sn)
30
+ options[:service_name] = sn
31
31
  end
32
32
 
33
- def schema_namespace(ns)
34
- namespaces['xsd1'] = ns
33
+ def wsdl_namespace(ns)
34
+ namespaces['tns'] = ns
35
35
  end
36
36
 
37
37
  def endpoint_url(url)
@@ -55,7 +55,7 @@ module Shapewear::Request
55
55
 
56
56
  xb.Envelope :xmlns => namespaces['env'] do |xenv|
57
57
  xenv.Body do |xbody|
58
- xbody.tag! "#{op_options[:public_name]}Response", :xmlns => namespaces['xsd1'] do |xres|
58
+ xbody.tag! "#{op_options[:public_name]}Response", :xmlns => namespaces['tns'] do |xres|
59
59
  xres.body r
60
60
  end
61
61
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Shapewear
4
4
 
5
- Version = "0.0.4"
5
+ Version = "0.0.5"
6
6
 
7
7
  end
@@ -12,12 +12,12 @@ module Shapewear::WSDL
12
12
  xm.definitions :name => self.name, 'targetNamespace' => namespaces['tns'],
13
13
  'xmlns' => namespaces['wsdl'],
14
14
  'xmlns:soap' => namespaces['soap'],
15
+ 'xmlns:soap12' => namespaces['soap12'],
15
16
  'xmlns:xsd' => namespaces['xsd'],
16
- 'xmlns:xsd1' => namespaces['xsd1'],
17
17
  'xmlns:tns' => namespaces['tns'] do |xdef|
18
18
 
19
19
  xdef.types do |xtypes|
20
- xtypes.schema 'xmlns' => namespaces['xsd'], 'targetNamespace' => namespaces['xsd1'] do |xschema|
20
+ xtypes.schema 'xmlns' => namespaces['xsd'], :elementFormDefault => 'qualified', 'targetNamespace' => namespaces['tns'] do |xschema|
21
21
 
22
22
  # define elements for each defined method
23
23
  operations.each do |m, op_opts|
@@ -26,41 +26,47 @@ module Shapewear::WSDL
26
26
  end
27
27
  end
28
28
 
29
- operations.each do |m, op_opts|
30
- xdef.message :name => "#{op_opts[:public_name]}Input" do |xmsg|
31
- xmsg.part :name => :body, :element => "xsd1:#{op_opts[:public_name]}Request"
32
- end unless instance_method(m).arity == 0
33
- xdef.message :name => "#{op_opts[:public_name]}Output" do |xmsg|
34
- xmsg.part :name => :body, :element => "xsd1:#{op_opts[:public_name]}Response"
29
+ operations.each do |_, op_opts|
30
+ xdef.message :name => "#{op_opts[:public_name]}SoapIn" do |xmsg|
31
+ xmsg.part :name => :parameters, :element => "tns:#{op_opts[:public_name]}"
32
+ end
33
+ xdef.message :name => "#{op_opts[:public_name]}SoapOut" do |xmsg|
34
+ xmsg.part :name => :parameters, :element => "tns:#{op_opts[:public_name]}Response"
35
35
  end
36
36
  end
37
37
 
38
- xdef.portType :name => "#{self.name}PortType" do |xpt|
39
- operations.each do |m, op_opts|
38
+ xdef.portType :name => "#{options[:service_name]}Soap" do |xpt|
39
+ operations.each do |_, op_opts|
40
40
  xpt.operation :name => op_opts[:public_name] do |xop|
41
- xop.input :message => "tns:#{op_opts[:public_name]}Input" unless instance_method(m).arity == 0
42
- xop.output :message => "tns:#{op_opts[:public_name]}Output"
41
+ xop.input :message => "tns:#{op_opts[:public_name]}SoapIn"
42
+ xop.output :message => "tns:#{op_opts[:public_name]}SoapOut"
43
43
  end
44
44
  end
45
45
  end
46
46
 
47
- xdef.binding :name => "#{self.name}Binding", :type => "tns:#{self.name}PortType" do |xbind|
48
- xbind.tag! 'soap:binding', :style => 'rpc', :transport => 'http://schemas.xmlsoap.org/soap/http'
49
- operations.each do |op, op_opts|
50
- xbind.operation :name => op_opts[:public_name] do |xop|
51
- doc = op_opts[:documentation] rescue nil
52
- xop.documentation doc unless doc.nil?
53
- xop.tag! 'soap:operation', :soapAction => "#{namespaces['tns']}/#{op_opts[:public_name]}"
54
- xop.input { |xin| xin.tag! 'soap:body', :use => 'literal', :namespace => namespaces['tns'] } unless instance_method(op).arity == 0
55
- xop.output { |xin| xin.tag! 'soap:body', :use => 'literal', :namespace => namespaces['tns'] }
47
+ # bindings for soap 1.1 and 1.2
48
+ ['', '12'].each do |sv|
49
+ xdef.binding :name => "#{options[:service_name]}Soap#{sv}", :type => "tns:#{options[:service_name]}Soap" do |xbind|
50
+ xbind.tag! "soap#{sv}:binding", :transport => 'http://schemas.xmlsoap.org/soap/http'
51
+ operations.each do |_, op_opts|
52
+ xbind.operation :name => op_opts[:public_name] do |xop|
53
+ doc = op_opts[:documentation] rescue nil
54
+ xop.documentation doc unless doc.nil?
55
+ xop.tag! "soap#{sv}:operation", :soapAction => "#{namespaces['tns']}/#{op_opts[:public_name]}", :style => 'document'
56
+ xop.input { |xin| xin.tag! "soap#{sv}:body", :use => 'literal' }
57
+ xop.output { |xin| xin.tag! "soap#{sv}:body", :use => 'literal' }
58
+ end
56
59
  end
57
60
  end
58
61
  end
59
62
 
60
- xdef.service :name => self.name do |xsrv|
61
- xsrv.documentation "WSDL auto-generated by shapewear."
62
- xsrv.port :name => "#{self.name}Port", :binding => "#{self.name}Binding" do |xport|
63
- xport.tag! 'soap:address', :location => options[:endpoint_url]
63
+ # service definition for soap 1.1 and 1.2
64
+ ['', '12'].each do |sv|
65
+ xdef.service :name => "#{options[:service_name]}#{sv}" do |xsrv|
66
+ xsrv.documentation "WSDL auto-generated by shapewear."
67
+ xsrv.port :name => "#{options[:service_name]}Soap#{sv}", :binding => "tns:#{options[:service_name]}Soap#{sv}" do |xport|
68
+ xport.tag! "soap#{sv}:address", :location => options[:endpoint_url]
69
+ end
64
70
  end
65
71
  end
66
72
  end
@@ -70,37 +76,37 @@ module Shapewear::WSDL
70
76
  # element for method arguments
71
77
  um = instance_method(m)
72
78
 
73
- if um.arity > 0
74
- xschema.element :name => "#{op_options[:public_name]}Request" do |xreq|
75
- xreq.complexType do |xct|
76
- xct.all do |xall|
77
- params = op_options[:parameters] rescue nil
78
- if params.nil?
79
- if um.respond_to?(:parameters)
80
- # with Ruby 1.9, we can create the parameters with the correct names
81
- params = um.parameters.select { |p| p.first == :in }.map { |p| [p.first, Object] }
82
- else
83
- params = (0..um.arity).map { |i| ["arg#{i}", Object] }
84
- end
79
+ xschema.element :name => "#{op_options[:public_name]}" do |xreq|
80
+ xreq.complexType do |xct|
81
+ xct.sequence do |xseq|
82
+ params = op_options[:parameters] rescue nil
83
+ if params.nil?
84
+ if um.respond_to?(:parameters)
85
+ # with Ruby 1.9, we can create the parameters with the correct names
86
+ params = um.parameters.select { |p| p.first == :in }.map { |p| [p.first, Object] }
87
+ else
88
+ params = (0..um.arity).map { |i| ["arg#{i}", Object] }
85
89
  end
90
+ end
86
91
 
87
- params.each do |p|
88
- t = p.last
89
- if t.nil?
90
- xall.element :name => p.first, :type => 'xsd:any'
91
- elsif t.is_a?(Class)
92
- xall.element :name => p.first, :type => to_xsd_type(t)
93
- elsif t.is_a?(Hash)
94
- xall.complexType do |xct2|
95
- xct2.all do |xall2|
96
- t.each do |name, type|
97
- xall2.element :name => name, :type => to_xsd_type(type)
98
- end
92
+ params.each do |p|
93
+ t = p.last
94
+ param_name = p.first
95
+ param_name = param_name.to_s.camelize if param_name.is_a?(Symbol)
96
+ if t.nil?
97
+ xseq.element :name => param_name, :minOccurs => 0, :maxOccurs => 1, :type => 'xsd:any'
98
+ elsif t.is_a?(Class)
99
+ xseq.element :name => param_name, :minOccurs => 0, :maxOccurs => 1, :type => to_xsd_type(t)
100
+ elsif t.is_a?(Hash)
101
+ xseq.complexType do |xct2|
102
+ xct2.sequence do |xseq2|
103
+ t.each do |name, type|
104
+ xseq2.element :name => name, :minOccurs => 0, :maxOccurs => 1, :type => to_xsd_type(type)
99
105
  end
100
106
  end
101
- else
102
- raise "Could not interpret #{t.inspect} as a return type definition"
103
107
  end
108
+ else
109
+ raise "Could not interpret #{t.inspect} as a return type definition"
104
110
  end
105
111
  end
106
112
  end
@@ -108,24 +114,34 @@ module Shapewear::WSDL
108
114
  end
109
115
 
110
116
  # element for method result
117
+ ret = op_options[:returns] rescue nil
118
+
111
119
  xschema.element :name => "#{op_options[:public_name]}Response" do |xreq|
112
120
  xreq.complexType do |xct|
113
- xct.all do |xall|
114
- ret = op_options[:returns] rescue nil
121
+ xct.sequence do |xseq|
115
122
  if ret.nil?
116
- xall.element :name => 'result', :type => 'xsd:any'
123
+ xseq.element :name => "#{op_options[:public_name]}Result", :minOccurs => 0, :maxOccurs => 1, :type => 'xsd:any'
117
124
  elsif ret.is_a?(Class)
118
- xall.element :name => 'result', :type => to_xsd_type(ret)
125
+ xseq.element :name => "#{op_options[:public_name]}Result", :minOccurs => 0, :maxOccurs => 1, :type => to_xsd_type(ret)
119
126
  elsif ret.is_a?(Hash)
120
- ret.each do |name, type|
121
- xall.element :name => name, :type => to_xsd_type(type)
122
- end
127
+ xseq.element :name => "#{op_options[:public_name]}Result", :minOccurs => 0, :maxOccurs => 1, :type => "tns:#{op_options[:public_name]}Struct"
123
128
  else
124
129
  raise "Could not interpret #{ret.inspect} as a return type definition"
125
130
  end
126
131
  end
127
132
  end
128
133
  end
134
+
135
+ if ret.is_a?(Hash)
136
+ xschema.complexType :name => "#{op_options[:public_name]}Struct" do |xctr|
137
+ xctr.sequence do |xseqr|
138
+ ret.each do |name, type|
139
+ name = name.to_s.camelize if name.is_a?(Symbol)
140
+ xseqr.element :name => name, :minOccurs => 0, :maxOccurs => 1, :type => to_xsd_type(type)
141
+ end
142
+ end
143
+ end
144
+ end
129
145
  end
130
146
 
131
147
  # @param t [Class]
@@ -6,7 +6,6 @@ class CompleteService
6
6
  include Shapewear
7
7
 
8
8
  wsdl_namespace 'http://services.example.com/v1'
9
- schema_namespace 'http://schemas.example.com/v1'
10
9
 
11
10
  endpoint_url 'http://services.example.com/complete/soap'
12
11
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shapewear
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - "F\xC3\xA1bio Batista"
@@ -150,6 +150,7 @@ files:
150
150
  - .rspec
151
151
  - .rvmrc
152
152
  - .travis.yml
153
+ - CHANGELOG.md
153
154
  - Gemfile
154
155
  - Gemfile.lock
155
156
  - LICENSE