From e3ab6ca6d5730da6c5792a13bd1ea4ff00fd78ac Mon Sep 17 00:00:00 2001 From: Niche Date: Wed, 6 Nov 2019 23:13:37 -0600 Subject: [PATCH 1/2] Allows SchemaElement instance to use import namespace as targetNamespace when the attribute is not set. Prevents the following error message when schema elements do not include targetNamespace attribute: > Target-Namespace "undefined" already in use by another Schema! --- src/wsdl/elements.ts | 17 +++++- test/wsdl-test.js | 12 +++++ test/wsdl/schema_with_no_targetnamespace.wsdl | 53 +++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 test/wsdl/schema_with_no_targetnamespace.wsdl 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..9b4650da8 100644 --- a/test/wsdl-test.js +++ b/test/wsdl-test.js @@ -420,4 +420,16 @@ 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(); + }); + }) }); 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From e3690bede9ad0c04eb6bd8cca935034f2c0ad04c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Alberto=20Reyes?= Date: Thu, 7 Nov 2019 10:22:56 -0600 Subject: [PATCH 2/2] Added test for undefined targetNamespaces --- test/wsdl-test.js | 11 ++++ .../wsdl/schemas_without_targetnamespace.wsdl | 51 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 test/wsdl/schemas_without_targetnamespace.wsdl diff --git a/test/wsdl-test.js b/test/wsdl-test.js index 9b4650da8..23a5af486 100644 --- a/test/wsdl-test.js +++ b/test/wsdl-test.js @@ -431,5 +431,16 @@ describe('WSDL Parser (non-strict)', () => { ) 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/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