Skip to content

Commit

Permalink
do not ignore complex types with xsd:all elements
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiii committed May 1, 2013
1 parent d2c3506 commit 2cb4206
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
22 changes: 15 additions & 7 deletions lib/wasabi/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,43 @@ def initialize(parser, namespace, node)

attr_reader :namespace

def type
@node.name
end

def children
return @children if @children

case @node.name
case type
when 'element'
first_child = @node.element_children.first

if first_child && first_child.name == 'complexType'
children = process_type first_child, @node['name'].to_s
children = parse_complex_type first_child, @node['name'].to_s
end
when 'complexType'
children = process_type @node, @node['name'].to_s
children = parse_complex_type @node, @node['name'].to_s
end

@children = children || []
end

def process_type(type, name)
def parse_complex_type(complex_type, name)
children = []

type.xpath("./xs:sequence/xs:element", 'xs' => Parser::XSD).each do |element|
complex_type.xpath("./xs:all/xs:element", 'xs' => Parser::XSD).each do |element|
children << { :name => element["name"].to_s, :type => element["type"].to_s }
end

complex_type.xpath("./xs:sequence/xs:element", 'xs' => Parser::XSD).each do |element|
children << { :name => element["name"].to_s, :type => element["type"].to_s }
end

type.xpath("./xs:complexContent/xs:extension/xs:sequence/xs:element", 'xs' => Parser::XSD).each do |element|
complex_type.xpath("./xs:complexContent/xs:extension/xs:sequence/xs:element", 'xs' => Parser::XSD).each do |element|
children << { :name => element["name"].to_s, :type => element["type"].to_s }
end

type.xpath('./xs:complexContent/xs:extension[@base]', 'xs' => Parser::XSD).each do |extension|
complex_type.xpath('./xs:complexContent/xs:extension[@base]', 'xs' => Parser::XSD).each do |extension|
base = extension.attribute('base').value.match(/\w+$/).to_s
base_type = @parser.types.fetch(base) { raise "expected to find extension base #{base} in types" }

Expand Down
5 changes: 0 additions & 5 deletions spec/wasabi/parser/no_namespace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,5 @@
subject.complex_types.keys.sort.should == ["McContact", "McContactArray", "MpUser", "MpUserArray"]
end

# TODO: this seems to document a lacking feature.
it "ignores xsd:all types" do
subject.types["MpUser"].children.should be_empty
end

end
end
51 changes: 51 additions & 0 deletions spec/wasabi/types_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe Wasabi::Parser do

it 'knows xs:all types' do
parser = parse('
<definitions name="Api" targetNamespace="urn:ActionWebService"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ActionWebService">
<xsd:complexType name="MpUser">
<xsd:all>
<xsd:element name="avatar_thumb_url" type="xsd:string"/>
<xsd:element name="speciality" type="xsd:string"/>
<xsd:element name="avatar_icon_url" type="xsd:string"/>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="mp_id" type="xsd:int"/>
<xsd:element name="lastname" type="xsd:string"/>
<xsd:element name="login" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
</definitions>
')

expect(parser.complex_types).to include('MpUser')
mp_user = parser.complex_types['MpUser']

expect(mp_user).to be_a(Wasabi::Type)
expect(mp_user.children).to eq([
{ :name => 'avatar_thumb_url', :type => 'xsd:string' },
{ :name => 'speciality', :type => 'xsd:string' },
{ :name => 'avatar_icon_url', :type => 'xsd:string' },
{ :name => 'firstname', :type => 'xsd:string' },
{ :name => 'city', :type => 'xsd:string' },
{ :name => 'mp_id', :type => 'xsd:int' },
{ :name => 'lastname', :type => 'xsd:string' },
{ :name => 'login', :type => 'xsd:string' }
])
end

def parse(xml)
parser = Wasabi::Parser.new Nokogiri.XML(xml)
parser.parse
parser
end

end

0 comments on commit 2cb4206

Please sign in to comment.