wasabi 5.2.0 → 5.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fafbc0e7f78682f50c3f1466447f9d724e9cc00fc1dd6b8d7751c6f473c1f297
4
- data.tar.gz: 193032ab7fcc93c7cd4f71bd69ca09e545ce5ede2167efa975fde11ce9c7ceaf
3
+ metadata.gz: 99d4a407d590f06b865b5cb77a20877ff9a89af19499c1c3385345bbe0c5ad7d
4
+ data.tar.gz: 73cf29707f60689e55ff68bd4e69170159cf176f3ef3e516a9a82318caf91f8e
5
5
  SHA512:
6
- metadata.gz: 992ad19eb27a2e31594698517147b412dc05f9aab8825009325835276fbb97a1cffac5abc10d2fea3f103a9a4cfe8ed86e56df6806e3a45b8499a0ec581414e2
7
- data.tar.gz: bd5a22e85ebbcc5273c276dd887268edf6c6a94387663f6f12d48c00e72646e2ea680f7a3a80a363635c7f5d70f2b4a033d8939c2474d8d2b67dc8bef209adee
6
+ metadata.gz: 4be6675abc9d227874b599a466fb5b090266bb756cbea3990bff27c15f1fabbf708260ad79ebbb6201c14f9e6dbb075d77e04123e5d060669aa7863cf62c449f
7
+ data.tar.gz: 9cacabcf37ff137c1745a61dbcb57635152bbc4306ed4a5649728fe93449042ca5ecd804ae3f6bf4ccf3098abdb75a7dc4e72bee30bb3b2e872e121818db7c02
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG for Wasabi
2
2
 
3
+ ## 5.3.0 (2026-11-11)
4
+
5
+ - Parse `nillable`, `minOccurs` and `maxOccurs` for elements declared in a `complexContent` extension, matching elements declared in a plain sequence. Based on [#43](https://github.com/savonrb/wasabi/pull/43) by @se6wagner.
6
+ - Describe elements declared with an inline complexType inside another type's sequence (directly or in an extension), so their children keep their schema namespace and sequence order. `Parser#types` describes them inside the element's own definition (`types[ns]["CreateOrder"]["customer"]["lastName"]`), and `Document#type_namespaces` lists them under their full path (`["CreateOrder", "customer", "lastName"]`).
7
+ - Raise a dedicated `Wasabi::InvalidDocumentError` (a `StandardError` subclass) when the document is not a WSDL, instead of crashing later with `NoMethodError` or silently returning no operations ([#152](https://github.com/savonrb/wasabi/pull/152)).
8
+
3
9
  ## 5.2.0 (2026-09-18)
4
10
 
5
11
  - Resolve each operation to its WSDL port's SOAP endpoint via `Wasabi::ServicePorts` and `Document#endpoint_for_operation` ([#138](https://github.com/savonrb/wasabi/pull/138)). `Document#endpoint` keeps its legacy first-port behavior. Known limitation: the lookup walks operation -> portType -> binding -> port and takes the first matching portType, while Savon's operation map is built from bindings (last binding wins). If the same operation name appears in two portTypes, the SOAP action may come from a different binding than the endpoint's port; a future pass could walk operation -> binding -> port for consistency.
@@ -5,6 +5,10 @@ require "wasabi/resolver"
5
5
  require "wasabi/parser"
6
6
 
7
7
  module Wasabi
8
+ # Raised when the document to parse is not a WSDL, like an HTML page or an empty body.
9
+ class InvalidDocumentError < StandardError
10
+ end
11
+
8
12
  # = Wasabi::Document
9
13
  #
10
14
  # Represents a WSDL document.
@@ -119,8 +123,8 @@ module Wasabi
119
123
  types.each do |type, info|
120
124
  namespaces << [[type], info[:namespace]]
121
125
 
122
- element_keys(info).each do |field|
123
- namespaces << [[type, field], info[:namespace]]
126
+ each_element([type], info) do |path, _definition|
127
+ namespaces << [path, info[:namespace]]
124
128
  end
125
129
  end
126
130
  end
@@ -137,11 +141,10 @@ module Wasabi
137
141
  if document
138
142
  parser.types.each do |ns, types|
139
143
  types.each do |type, info|
140
- element_keys(info).each do |field|
141
- field_type = info[field][:type]
142
- tag, namespace = field_type.split(":").reverse
144
+ each_element([type], info) do |path, definition|
145
+ tag, namespace = definition[:type].split(":").reverse
143
146
 
144
- result << [[type, field], tag] if user_defined(namespace)
147
+ result << [path, tag] if user_defined(namespace)
145
148
  end
146
149
  end
147
150
  end
@@ -183,13 +186,30 @@ module Wasabi
183
186
 
184
187
  # Parses the WSDL document and returns <tt>Wasabi::Parser</tt>.
185
188
  def parse
186
- parser = Parser.new Nokogiri::XML(xml)
189
+ xml_document = Nokogiri::XML(xml)
190
+ unless xml_document.root&.name == "definitions"
191
+ raise InvalidDocumentError, "Wasabi needs a WSDL document, got: #{xml.to_s[0, 100].inspect}"
192
+ end
193
+
194
+ parser = Parser.new xml_document
187
195
  parser.parse
188
196
  parser
189
197
  end
190
198
 
191
- def element_keys(info)
192
- info.keys - [:namespace, :order!, :base_type]
199
+ # Yields the path and definition of each element of a type, then of the
200
+ # elements of each inline complexType below it. Inline complexTypes that
201
+ # extend each other's types share definitions, so the walk stops at the
202
+ # first definition already on its path.
203
+ def each_element(path, info, ancestors = [info], &block)
204
+ info.each do |key, definition|
205
+ next unless key.is_a?(String)
206
+
207
+ element_path = path + [key]
208
+ yield element_path, definition
209
+ next if ancestors.any? { |ancestor| ancestor.equal?(definition) }
210
+
211
+ each_element(element_path, definition, ancestors + [definition], &block)
212
+ end
193
213
  end
194
214
  end
195
215
  end
data/lib/wasabi/parser.rb CHANGED
@@ -193,48 +193,50 @@ module Wasabi
193
193
  def process_type(namespace, type, name)
194
194
  @types[namespace] ||= {}
195
195
  @types[namespace][name] ||= {namespace: namespace}
196
- @types[namespace][name][:order!] = []
197
-
198
- type.xpath("./xs:sequence/xs:element", "xs" => XSD).each do |inner|
199
- element_name = inner.attribute("name").to_s
200
- @types[namespace][name][element_name] = {type: inner.attribute("type").to_s}
201
-
202
- [:nillable, :minOccurs, :maxOccurs].each do |attr|
203
- if (v = inner.attribute(attr.to_s))
204
- @types[namespace][name][element_name][attr] = v.to_s
205
- end
206
- end
207
-
208
- @types[namespace][name][:order!] << element_name
209
- end
196
+ add_sequence_elements @types[namespace][name], type, namespace
197
+ end
210
198
 
211
- type.xpath("./xs:complexContent/xs:extension/xs:sequence/xs:element", "xs" => XSD).each do |inner_element|
212
- element_name = inner_element.attribute("name").to_s
213
- @types[namespace][name][element_name] = {type: inner_element.attribute("type").to_s}
199
+ # Adds the elements of a type's sequence, or of its extension's, to +definition+
200
+ # under their names, in schema order, after those it inherits from its base type.
201
+ def add_sequence_elements(definition, type, namespace)
202
+ definition[:order!] = []
214
203
 
215
- @types[namespace][name][:order!] << element_name
204
+ type.xpath("./xs:sequence/xs:element | ./xs:complexContent/xs:extension/xs:sequence/xs:element", "xs" => XSD).each do |element|
205
+ element_name = element.attribute("name").to_s
206
+ definition[element_name] = element_definition(element, namespace)
207
+ definition[:order!] << element_name
216
208
  end
217
209
 
218
210
  type.xpath("./xs:complexContent/xs:extension[@base]", "xs" => XSD).each do |inherits|
219
211
  base = inherits.attribute("base").value.match(/\w+$/).to_s
212
+ inherit = proc { inherit_base definition, @types[namespace][base], base if @types[namespace][base] }
213
+ @types[namespace][base] ? inherit.call : deferred_types << inherit
214
+ end
215
+ end
220
216
 
221
- if @types[namespace][base]
222
- # Reverse merge because we don't want subclass attributes to be overriden by base class
223
- @types[namespace][name] = types[namespace][base].merge(types[namespace][name])
224
- @types[namespace][name][:order!] = @types[namespace][base][:order!] | @types[namespace][name][:order!]
225
- @types[namespace][name][:base_type] = base
226
- else
227
- p = proc do
228
- if @types[namespace][base]
229
- # Reverse merge because we don't want subclass attributes to be overriden by base class
230
- @types[namespace][name] = @types[namespace][base].merge(@types[namespace][name])
231
- @types[namespace][name][:order!] = @types[namespace][base][:order!] | @types[namespace][name][:order!]
232
- @types[namespace][name][:base_type] = base
233
- end
234
- end
235
- deferred_types << p
217
+ def inherit_base(definition, base_definition, base)
218
+ # Reverse merge because we don't want subclass attributes to be overriden by base class
219
+ definition.replace base_definition.except(:namespace).merge(definition)
220
+ definition[:order!] = base_definition[:order!] | definition[:order!]
221
+ definition[:base_type] = base
222
+ end
223
+
224
+ # Returns the type and occurrence indicators (nillable, minOccurs, maxOccurs)
225
+ # declared on an xs:element. An inline complexType has no name to point at,
226
+ # so its elements are described inside the element's own definition.
227
+ def element_definition(element, namespace)
228
+ definition = {type: element.attribute("type").to_s}
229
+
230
+ [:nillable, :minOccurs, :maxOccurs].each do |attr|
231
+ if (v = element.attribute(attr.to_s))
232
+ definition[attr] = v.to_s
236
233
  end
237
234
  end
235
+
236
+ complex_type = element.at_xpath("./xs:complexType", "xs" => XSD)
237
+ add_sequence_elements definition, complex_type, namespace if complex_type
238
+
239
+ definition
238
240
  end
239
241
 
240
242
  def parse_deferred_types
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wasabi
4
- VERSION = "5.2.0"
4
+ VERSION = "5.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wasabi
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Harrington
@@ -79,7 +79,7 @@ licenses:
79
79
  - MIT
80
80
  metadata:
81
81
  changelog_uri: https://github.com/savonrb/wasabi/blob/main/CHANGELOG.md
82
- documentation_uri: https://www.rubydoc.info/gems/wasabi/5.2.0
82
+ documentation_uri: https://www.rubydoc.info/gems/wasabi/5.3.0
83
83
  source_code_uri: https://github.com/savonrb/wasabi
84
84
  bug_tracker_uri: https://github.com/savonrb/wasabi/issues
85
85
  rubygems_mfa_required: 'true'