From ad7b7ad6a8a9b9a6920e267f7a85548001d1fbbf Mon Sep 17 00:00:00 2001 From: Mario Manno Date: Tue, 14 Oct 2014 13:33:57 +0200 Subject: [PATCH 1/6] allow local files in schema importer --- lib/sekken/importer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sekken/importer.rb b/lib/sekken/importer.rb index ae006b9..8417272 100644 --- a/lib/sekken/importer.rb +++ b/lib/sekken/importer.rb @@ -57,7 +57,7 @@ def import_schemas schema.imports.each do |namespace, schema_location| next unless schema_location - unless absolute_url? schema_location + unless absolute_url? schema_location or File.readable? schema_location @logger.warn("Skipping XML Schema import #{schema_location.inspect}.") next end From 2ac10cf28c68791e367d5ade657c8e6536caff96 Mon Sep 17 00:00:00 2001 From: Saul Moncada Date: Thu, 4 Dec 2014 13:17:56 -0430 Subject: [PATCH 2/6] Support for relative paths --- lib/sekken/resolver.rb | 10 ++++++++-- lib/sekken/wsdl.rb | 6 ++++-- spec/fixtures/wsdl/folder/imported.wsdl | 15 +++++++++++++++ spec/fixtures/wsdl/import.wsdl | 7 +++++++ spec/sekken/wsdl_nested_files_spec.rb | 9 +++++++++ 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/wsdl/folder/imported.wsdl create mode 100644 spec/fixtures/wsdl/import.wsdl create mode 100644 spec/sekken/wsdl_nested_files_spec.rb diff --git a/lib/sekken/resolver.rb b/lib/sekken/resolver.rb index 6d01db7..a8233ea 100644 --- a/lib/sekken/resolver.rb +++ b/lib/sekken/resolver.rb @@ -4,15 +4,21 @@ class Resolver URL_PATTERN = /^http[s]?:/ XML_PATTERN = /^ + + + + + + + diff --git a/spec/fixtures/wsdl/import.wsdl b/spec/fixtures/wsdl/import.wsdl new file mode 100644 index 0000000..c831856 --- /dev/null +++ b/spec/fixtures/wsdl/import.wsdl @@ -0,0 +1,7 @@ + + + + diff --git a/spec/sekken/wsdl_nested_files_spec.rb b/spec/sekken/wsdl_nested_files_spec.rb new file mode 100644 index 0000000..07f0679 --- /dev/null +++ b/spec/sekken/wsdl_nested_files_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe Sekken::WSDL do + describe 'with local files and imported wsdl' do + it 'does not fail to create the wsdl' do + expect{Sekken::WSDL.new(fixture('wsdl/import'), http_mock)}.to_not raise_error + end + end +end From f50139e767ff3506e000ef0f0cb1c6d99c5426ce Mon Sep 17 00:00:00 2001 From: Saul Moncada Date: Thu, 4 Dec 2014 16:54:54 -0430 Subject: [PATCH 3/6] Improvements on resolver and importer --- lib/sekken/importer.rb | 6 +----- lib/sekken/resolver.rb | 6 +++++- lib/sekken/wsdl.rb | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/sekken/importer.rb b/lib/sekken/importer.rb index 8417272..38f6ea5 100644 --- a/lib/sekken/importer.rb +++ b/lib/sekken/importer.rb @@ -57,7 +57,7 @@ def import_schemas schema.imports.each do |namespace, schema_location| next unless schema_location - unless absolute_url? schema_location or File.readable? schema_location + unless @resolver.can_resolve? schema_location @logger.warn("Skipping XML Schema import #{schema_location.inspect}.") next end @@ -69,9 +69,5 @@ def import_schemas end end - def absolute_url?(location) - location =~ Resolver::URL_PATTERN - end - end end diff --git a/lib/sekken/resolver.rb b/lib/sekken/resolver.rb index a8233ea..36fcc81 100644 --- a/lib/sekken/resolver.rb +++ b/lib/sekken/resolver.rb @@ -4,7 +4,7 @@ class Resolver URL_PATTERN = /^http[s]?:/ XML_PATTERN = /^ Date: Thu, 4 Dec 2014 22:11:28 -0430 Subject: [PATCH 4/6] Fix error on base_file_path creation --- lib/sekken/wsdl.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sekken/wsdl.rb b/lib/sekken/wsdl.rb index f264b10..3381bdc 100644 --- a/lib/sekken/wsdl.rb +++ b/lib/sekken/wsdl.rb @@ -11,7 +11,8 @@ def initialize(wsdl, http) @documents = WSDL::DocumentCollection.new @schemas = XS::SchemaCollection.new - base_file_path = File.dirname(wsdl) if File.exists?(wsdl)||"" + base_file_path = "" + base_file_path = File.dirname(wsdl) if File.exists?(wsdl) resolver = Resolver.new(http, base_file_path) importer = Importer.new(resolver, @documents, @schemas) From 0393a6869536371650e0c09d7ec2ccf2acfbdcea Mon Sep 17 00:00:00 2001 From: Saul Moncada Date: Fri, 12 Dec 2014 23:02:10 -0430 Subject: [PATCH 5/6] Resolve includes on XSD --- lib/sekken/importer.rb | 31 +++++++++++++++++++++++---- lib/sekken/wsdl/document.rb | 4 ++-- lib/sekken/xml/element_builder.rb | 2 +- lib/sekken/xs/schema.rb | 20 +++++++++++++++-- spec/sekken/wsdl_nested_files_spec.rb | 16 ++++++++++++++ 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/lib/sekken/importer.rb b/lib/sekken/importer.rb index 38f6ea5..9be08af 100644 --- a/lib/sekken/importer.rb +++ b/lib/sekken/importer.rb @@ -24,27 +24,41 @@ def import(location) # resolve xml schema imports import_schemas do |schema_location| @logger.info("Resolving XML schema import #{schema_location.inspect}.") - + import_document(schema_location) do |document| @schemas.push(document.schemas) end end + + import_included_schemas do |schema_location| + @logger.info("Resolving included schema #{schema_location.inspect}.") + + import_document(schema_location) do |document| + document.schemas.each do |schema| + existing = @schemas.find_by_namespace(schema.target_namespace) + existing.merge(schema) + end + end + end end private def import_document(location, &block) + @logger.info("Importing #{location.inspect}.") if @import_locations.include? location - @logger.info("Skipping already imported location #{location.inspect}.") + @logger.warn("Skipping already imported location #{location.inspect}.") return end xml = @resolver.resolve(location) + @import_locations << location document = WSDL::Document.new Nokogiri.XML(xml), @schemas + block.call(document) - + # resolve wsdl imports document.imports.each do |import_location| @logger.info("Resolving WSDL import #{import_location.inspect}.") @@ -63,11 +77,20 @@ def import_schemas end # TODO: also skip if the schema was already imported - yield(schema_location) end end end + def import_included_schemas + @schemas.each do |schema| + schema.includes.each do |include_location| + if @resolver.can_resolve? include_location + yield include_location + end + end + end + end + end end diff --git a/lib/sekken/wsdl/document.rb b/lib/sekken/wsdl/document.rb index c695016..0d38950 100644 --- a/lib/sekken/wsdl/document.rb +++ b/lib/sekken/wsdl/document.rb @@ -38,12 +38,12 @@ def schemas def imports imports = [] - + @document.root.xpath('wsdl:import', 'wsdl' => Sekken::NS_WSDL).each do |node| location = node['location'] imports << location if location end - + imports end diff --git a/lib/sekken/xml/element_builder.rb b/lib/sekken/xml/element_builder.rb index 27bae47..1fc60d6 100644 --- a/lib/sekken/xml/element_builder.rb +++ b/lib/sekken/xml/element_builder.rb @@ -40,7 +40,7 @@ def build_element(part) local, namespace = expand_qname(part[:element], part[:namespaces]) schema = @schemas.find_by_namespace(namespace) raise "Unable to find schema for #{namespace.inspect}" unless schema - + xs_element = schema.elements.fetch(local) type = find_type_for_element(xs_element) diff --git a/lib/sekken/xs/schema.rb b/lib/sekken/xs/schema.rb index 011ba7f..1a0cb7d 100644 --- a/lib/sekken/xs/schema.rb +++ b/lib/sekken/xs/schema.rb @@ -17,13 +17,24 @@ def initialize(schema, schemas) @complex_types = {} @simple_types = {} @imports = {} + @includes = [] parse end - attr_accessor :target_namespace, :element_form_default, :imports, + attr_accessor :target_namespace, :element_form_default, :imports, :includes, :attributes, :attribute_groups, :elements, :complex_types, :simple_types + + def merge schema + @attributes.merge! schema.attributes unless @attributes.nil? + @attributes_groups.merge! schema.attribute_groups unless @attributes_groups.nil? + @elements.merge! schema.elements unless @elements.nil? + @complex_types.merge! schema.complex_types unless @complex_types.nil? + @simple_types.merge! schema.simple_types unless @simple_types.nil? + + end + private def parse @@ -31,7 +42,7 @@ def parse :target_namespace => @target_namespace, :element_form_default => @element_form_default } - + @schema.element_children.each do |node| case node.name when 'attribute' then store_element(@attributes, node, schema) @@ -40,6 +51,7 @@ def parse when 'complexType' then store_element(@complex_types, node, schema) when 'simpleType' then store_element(@simple_types, node, schema) when 'import' then store_import(node) + when 'include' then store_include(node) end end end @@ -52,6 +64,10 @@ def store_import(node) @imports[node['namespace']] = node['schemaLocation'] end + def store_include node + @includes.push node['schemaLocation'] + end + end end end diff --git a/spec/sekken/wsdl_nested_files_spec.rb b/spec/sekken/wsdl_nested_files_spec.rb index 07f0679..6125fff 100644 --- a/spec/sekken/wsdl_nested_files_spec.rb +++ b/spec/sekken/wsdl_nested_files_spec.rb @@ -6,4 +6,20 @@ expect{Sekken::WSDL.new(fixture('wsdl/import'), http_mock)}.to_not raise_error end end + + describe 'with local files and imported wsdl with two levels of import' do + it 'does not fail to create the sample_header' do + client = Sekken.new fixture('wsdl/sabre/SessionCreateRQ.wsdl') + svc = client.operation("SessionCreateRQService","SessionCreatePortType", "SessionCreateRQ"); + expect{svc.example_header}.to_not raise_error + end + end + + describe 'with local files and imported wsdl with two levels of import' do + it 'does not fail to create the sample_body' do + client = Sekken.new fixture('wsdl/sabre/SessionCreateRQ.wsdl') + svc = client.operation("SessionCreateRQService","SessionCreatePortType", "SessionCreateRQ"); + expect{svc.example_body}.to_not raise_error + end + end end From 81900d435b6503c5f70578ae6db4dfb075bcce00 Mon Sep 17 00:00:00 2001 From: Saul Moncada Date: Fri, 12 Dec 2014 23:05:13 -0430 Subject: [PATCH 6/6] Add Sabre wsdl/xsd --- spec/fixtures/wsdl/sabre/SessionCreateRQ.wsdl | 47 ++++ spec/fixtures/wsdl/sabre/SessionCreateRQ.xsd | 21 ++ .../fixtures/wsdl/sabre/SessionCreateRQRS.xsd | 5 + spec/fixtures/wsdl/sabre/SessionCreateRS.xsd | 134 +++++++++ spec/fixtures/wsdl/sabre/msg-header-2_0.xsd | 263 ++++++++++++++++++ spec/fixtures/wsdl/sabre/wsse.xsd | 27 ++ 6 files changed, 497 insertions(+) create mode 100644 spec/fixtures/wsdl/sabre/SessionCreateRQ.wsdl create mode 100644 spec/fixtures/wsdl/sabre/SessionCreateRQ.xsd create mode 100644 spec/fixtures/wsdl/sabre/SessionCreateRQRS.xsd create mode 100644 spec/fixtures/wsdl/sabre/SessionCreateRS.xsd create mode 100644 spec/fixtures/wsdl/sabre/msg-header-2_0.xsd create mode 100644 spec/fixtures/wsdl/sabre/wsse.xsd diff --git a/spec/fixtures/wsdl/sabre/SessionCreateRQ.wsdl b/spec/fixtures/wsdl/sabre/SessionCreateRQ.wsdl new file mode 100644 index 0000000..afa1939 --- /dev/null +++ b/spec/fixtures/wsdl/sabre/SessionCreateRQ.wsdl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/sabre/SessionCreateRQ.xsd b/spec/fixtures/wsdl/sabre/SessionCreateRQ.xsd new file mode 100644 index 0000000..f98de51 --- /dev/null +++ b/spec/fixtures/wsdl/sabre/SessionCreateRQ.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/sabre/SessionCreateRQRS.xsd b/spec/fixtures/wsdl/sabre/SessionCreateRQRS.xsd new file mode 100644 index 0000000..cc3a751 --- /dev/null +++ b/spec/fixtures/wsdl/sabre/SessionCreateRQRS.xsd @@ -0,0 +1,5 @@ + + + + + diff --git a/spec/fixtures/wsdl/sabre/SessionCreateRS.xsd b/spec/fixtures/wsdl/sabre/SessionCreateRS.xsd new file mode 100644 index 0000000..359a574 --- /dev/null +++ b/spec/fixtures/wsdl/sabre/SessionCreateRS.xsd @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + If present, this refers to a table of coded values exchanged between applications to identify errors or warnings. + + + + Used for codes in the OTA code tables. + + + + + + + + + If present, this URL refers to an online description of the error that occurred. + + + + + If present, recommended values are those enumerated in the OTA_ErrorRS, (NotProcessed | Incomplete | Complete | Unknown) however, the data type is designated as string data, recognizing that trading partners may identify additional status conditions not included in the enumeration. + + + + + If present, this attribute may identify an unknown or misspelled tag that caused an error in processing. It is recommended that the Tag attribute use XPath notation to identify the location of a tag in the event that more than one tag of the same name is present in the document. Alternatively, the tag name alone can be used to identify missing data [Type=ReqFieldMissing]. + + + + + If present, this attribute allows for batch processing and the identification of the record that failed amongst a group of records. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A sequence number for additional message identification, assigned by the requesting host system. When a request message includes an echo token the corresponding response message MUST include an echo token with an identical value. + + + + Used for Character Strings, length 1 to 64 + + + + + + + + + + Indicates the creation date and time of the message in UTC using the following format specified by ISO 8601; YYYY- MM- DDThh:mm:ssZ with time values using the 24 hour clock (e.g. 20 November 2003, 1:59:38 pm UTC becomes 2003-11- 20T13:59:38Z). + + + + + Used to indicate whether the request is for the Test or Production system. + + + + + + + + + + + For all OTA versioned messages, the version of the message is indicated by a decimal value. + + + + + Used to identify the sequence number of the transaction as assigned by the sending system; allows for an application to process messages in a certain order or to request a resynchronization of messages in the event that a system has been off-line and needs to retrieve messages that were missed. + + + + + Identifes the primary language preference for the form of travel represented in a collection. + The human language is identified by ISO 639 codes. + + + + + Identifes the primary language preference for the form of travel represented in a collection. + The human language is identified by ISO 639 codes. + + + + + + diff --git a/spec/fixtures/wsdl/sabre/msg-header-2_0.xsd b/spec/fixtures/wsdl/sabre/msg-header-2_0.xsd new file mode 100644 index 0000000..7ad3055 --- /dev/null +++ b/spec/fixtures/wsdl/sabre/msg-header-2_0.xsd @@ -0,0 +1,263 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/wsdl/sabre/wsse.xsd b/spec/fixtures/wsdl/sabre/wsse.xsd new file mode 100644 index 0000000..789603e --- /dev/null +++ b/spec/fixtures/wsdl/sabre/wsse.xsd @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + +