diff --git a/src/wsdl/elements.ts b/src/wsdl/elements.ts
index 190fd87b6..e4d85de08 100644
--- a/src/wsdl/elements.ts
+++ b/src/wsdl/elements.ts
@@ -903,12 +903,25 @@ export class TypesElement extends Element {
public addChild(child) {
assert(child instanceof SchemaElement);
- const targetNamespace = child.$targetNamespace || child.includes[0]?.namespace;
+ const childInclude = child.includes.find((e: object) => {
+ return e.hasOwnProperty('namespace');
+ });
+ const childIncludeNs: string = (
+ (typeof childInclude !== 'undefined' &&
+ childInclude.hasOwnProperty('namespace') &&
+ child instanceof SchemaElement) ?
+ childInclude.namespace :
+ undefined);
+ const targetNamespace = child.$targetNamespace || child.includes[0]?.namespace || childIncludeNs;
if (!this.schemas.hasOwnProperty(targetNamespace)) {
this.schemas[targetNamespace] = child;
} else {
- console.error('Target-Namespace "' + targetNamespace + '" already in use by another Schema!');
+ if (targetNamespace === child.$targetNamespace) {
+ this.schemas[targetNamespace] = child;
+ } else {
+ console.error('Target-Namespace "' + targetNamespace + '" already in use by another Schema!');
+ }
}
}
}
diff --git a/test/wsdl-test.js b/test/wsdl-test.js
index f76c64013..23a5af486 100644
--- a/test/wsdl-test.js
+++ b/test/wsdl-test.js
@@ -420,4 +420,27 @@ describe('WSDL Parser (non-strict)', () => {
done();
});
});
+
+ it('should return the right amount of schemas with no targetNamespace', (done) => {
+ soap.createClient(__dirname+'/wsdl/schema_with_no_targetnamespace.wsdl', function(err, client) {
+ assert.ifError(err);
+ assert.equal(Object.keys(client.wsdl.definitions.schemas).length, 2);
+ assert.ok(
+ client.wsdl.definitions.schemas.hasOwnProperty('http://www.Dummy.com/Common/Types') &&
+ client.wsdl.definitions.schemas.hasOwnProperty('http://www.Dummy.com/Name/Types')
+ )
+ done();
+ });
+ });
+
+ it('should not return both schemas when targetNamespace is undefined (no imports)', (done) => {
+ soap.createClient(
+ __dirname + "/wsdl/schemas_without_targetnamespace.wsdl",
+ function(err, client) {
+ assert.ifError(err);
+ assert.equal(Object.keys(client.wsdl.definitions.schemas).length, 1);
+ done();
+ }
+ );
+ })
});
diff --git a/test/wsdl/schema_with_no_targetnamespace.wsdl b/test/wsdl/schema_with_no_targetnamespace.wsdl
new file mode 100644
index 000000000..9f107ad1e
--- /dev/null
+++ b/test/wsdl/schema_with_no_targetnamespace.wsdl
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/wsdl/schemas_without_targetnamespace.wsdl b/test/wsdl/schemas_without_targetnamespace.wsdl
new file mode 100644
index 000000000..4867d0acb
--- /dev/null
+++ b/test/wsdl/schemas_without_targetnamespace.wsdl
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file