From c515f9ff0b9543d725c3e26b8a653d145326d2d7 Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Thu, 13 Sep 2018 20:05:49 +0700 Subject: [PATCH] WSDL: make merging external schema works correctly - Remove $targetNamespace check, as the key in definitions.schemas already guarantee this. Fix importing schema with where namespace == schema's targetNamespace. - Also merge attributes from source schema. Otherwise, attributes such as elementFormDefault="qualified" specified in included schema will not work properly. --- lib/wsdl.js | 19 ++++++---- test/wsdl-test.js | 30 ++++++++++++++++ test/wsdl/mergeWithAttributes/def.xsd | 27 ++++++++++++++ test/wsdl/mergeWithAttributes/main.wsdl | 47 +++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 test/wsdl/mergeWithAttributes/def.xsd create mode 100644 test/wsdl/mergeWithAttributes/main.wsdl diff --git a/lib/wsdl.js b/lib/wsdl.js index af1574ad2..c074f6234 100644 --- a/lib/wsdl.js +++ b/lib/wsdl.js @@ -349,12 +349,19 @@ DocumentationElement.prototype.init = function() { SchemaElement.prototype.merge = function(source) { assert(source instanceof SchemaElement); - if (this.$targetNamespace === source.$targetNamespace) { - _.merge(this.complexTypes, source.complexTypes); - _.merge(this.types, source.types); - _.merge(this.elements, source.elements); - _.merge(this.xmlns, source.xmlns); - } + + var self = this; + + _.merge(this.complexTypes, source.complexTypes); + _.merge(this.types, source.types); + _.merge(this.elements, source.elements); + _.merge(this.xmlns, source.xmlns); + + // Merge attributes from source without overwriting our's + _.merge(this, _.pickBy(source, function(value, key) { + return key.startsWith('$') && !self.hasOwnProperty(key); + })); + return this; }; diff --git a/test/wsdl-test.js b/test/wsdl-test.js index a4e949353..7ed97ef5a 100644 --- a/test/wsdl-test.js +++ b/test/wsdl-test.js @@ -186,6 +186,36 @@ wsdlNonStrictTests['should all attributes to root elements'] = function(done) { }); }; +wsdlNonStrictTests['should merge schema with attributes'] = function(done) { + var expectedMsg = + '' + + 'How are you?' + + ''; + + soap.createClient(__dirname + '/wsdl/mergeWithAttributes/main.wsdl', {}, function(err, client) { + assert.ok(!err); + client.AskPeat({ Question: 'How are you?' }, function(err, result) { + assert.equal(client.lastMessage, expectedMsg); + done(); + }); + }); +}; + +wsdlStrictTests['should merge schema with attributes'] = function(done) { + var expectedMsg = + '' + + 'How are you?' + + ''; + + soap.createClient(__dirname + '/wsdl/mergeWithAttributes/main.wsdl', {}, function(err, client) { + assert.ok(!err); + client.AskPeat({ Question: 'How are you?' }, function(err, result) { + assert.equal(client.lastMessage, expectedMsg); + done(); + }); + }); +}; + module.exports = { 'WSDL Parser (strict)': wsdlStrictTests, 'WSDL Parser (non-strict)': wsdlNonStrictTests diff --git a/test/wsdl/mergeWithAttributes/def.xsd b/test/wsdl/mergeWithAttributes/def.xsd new file mode 100644 index 000000000..272a47b01 --- /dev/null +++ b/test/wsdl/mergeWithAttributes/def.xsd @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/wsdl/mergeWithAttributes/main.wsdl b/test/wsdl/mergeWithAttributes/main.wsdl new file mode 100644 index 000000000..d0a1f2f17 --- /dev/null +++ b/test/wsdl/mergeWithAttributes/main.wsdl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file