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