diff --git a/lib/wsdl.js b/lib/wsdl.js index 5119580fb..48a03d5a5 100644 --- a/lib/wsdl.js +++ b/lib/wsdl.js @@ -1756,10 +1756,14 @@ WSDL.prototype.objectToXML = function(obj, name, nsPrefix, nsURI, isFirst, xmlns // start building out XML string. if (Array.isArray(obj)) { var nonSubNameSpace = ''; + var emptyNonSubNameSpaceForArray = false; var nameWithNsRegex = /^([^:]+):([^:]+)$/.exec(name); if (nameWithNsRegex) { nonSubNameSpace = nameWithNsRegex[1]; name = nameWithNsRegex[2]; + } else if(name[0] === ':'){ + emptyNonSubNameSpaceForArray = true; + name = name.substr(1); } for (i = 0, n = obj.length; i < n; i++) { @@ -1769,7 +1773,10 @@ WSDL.prototype.objectToXML = function(obj, name, nsPrefix, nsURI, isFirst, xmlns var body = self.objectToXML(item, name, nsPrefix, nsURI, false, null, schemaObject, nsContext); - var openingTagParts = ['<', appendColon(correctOuterNsPrefix), name, arrayAttr, xmlnsAttrib]; + var openingTagParts = ['<', name, arrayAttr, xmlnsAttrib]; + if(!emptyNonSubNameSpaceForArray) { + openingTagParts = ['<', appendColon(correctOuterNsPrefix), name, arrayAttr, xmlnsAttrib]; + } if (body === '' && self.options.useEmptyTag) { // Use empty (self-closing) tags if no contents @@ -1782,7 +1789,11 @@ WSDL.prototype.objectToXML = function(obj, name, nsPrefix, nsURI, isFirst, xmlns } parts.push(body); if(self.options.namespaceArrayElements || i === n-1) { - parts.push([''].join('')); + if(emptyNonSubNameSpaceForArray) { + parts.push([''].join('')); + } else { + parts.push([''].join('')); + } } } } @@ -1941,7 +1952,12 @@ WSDL.prototype.objectToXML = function(obj, name, nsPrefix, nsURI, isFirst, xmlns obj[self.options.attributesKey].xsi_type.xmlns, false, null, null, nsContext); } else { if(Array.isArray(child)) { - name = nonSubNameSpace + name; + // Lets keep the same option as other attributes to array as well + if(emptyNonSubNameSpace) { + name = ':' + name; + } else { + name = nonSubNameSpace + name; + } } value = self.objectToXML(child, name, nsPrefix, nsURI, false, null, null, nsContext); diff --git a/package-lock.json b/package-lock.json index 3308de4a8..2f5dbe0ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "soap", - "version": "0.25.0", + "version": "0.26.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index c5f4951a2..f52b09518 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "scripts": { "toc": "./node_modules/.bin/doctoc Readme.md --github --maxlevel 3", - "cover": "nyc --reporter=lcov --reporter=html --reporter=text mocha --exit test/*-test.js test/security/*.js", + "cover": "nyc --reporter=lcov --reporter=html --reporter=text mocha --timeout 10000 --exit test/*-test.js test/security/*.js", "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js -v", "test": "mocha --timeout 10000 --bail --exit test/*-test.js test/security/*.js" }, diff --git a/test/client-test.js b/test/client-test.js index 2d5a22575..609e99e0d 100644 --- a/test/client-test.js +++ b/test/client-test.js @@ -94,12 +94,12 @@ var fs = require('fs'), }); }); - + it('should allow passing in XML strings', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', _.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) { assert.ok(client); assert.ifError(err); - + var xmlStr = '\n\t\n\t\t404 - Not Found\n\t\n\t\n\t\t

404 - Not Found

\n\t\t\n\t\n'; client.MyOperation({_xml: xmlStr}, function (err, result, raw, soapHeader) { assert.ok(err); @@ -210,7 +210,7 @@ var fs = require('fs'), }, 'https://127.0.0.1:443'); }); - + it('should have xml request modified', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function(err, client) { assert.ok(client); @@ -230,7 +230,7 @@ var fs = require('fs'), ); }, baseUrl); }); - + it('should have the correct extra header in the request', function (done) { soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) { assert.ok(client); @@ -905,6 +905,52 @@ var fs = require('fs'), }); }); + it('shall generate correct payload for methods with array parameter with colon override', function (done) { + soap.createClient(__dirname + '/wsdl/array_namespace_override.wsdl', function(err, client) { + assert.ok(client); + var pathToArrayContainer = 'SampleArrayServiceImplService.SampleArrayServiceImplPort.createWebOrder.input.order'; + var arrayParameter = _.get(client.describe(), pathToArrayContainer)['orderDetails[]']; + assert.ok(arrayParameter); + const input = { + ':clientId': 'test', + ':order': { + ':orderDetails': { + ':unitNo': 1234, + ':items':[{ ':itemDesc': 'item1'}, { ':itemDesc': 'item2'}] + }, + }, + }; + client.createWebOrder(input, function() { + var sentInputContent = client.lastRequest.substring(client.lastRequest.indexOf(''), client.lastRequest.lastIndexOf('') + ''.length); + assert.equal(sentInputContent, 'item1item2'); + done(); + }); + }); + }); + + it('shall generate correct payload for methods with array parameter with parent namespace', function (done) { + soap.createClient(__dirname + '/wsdl/array_namespace_override.wsdl', function(err, client) { + assert.ok(client); + var pathToArrayContainer = 'SampleArrayServiceImplService.SampleArrayServiceImplPort.createWebOrder.input.order'; + var arrayParameter = _.get(client.describe(), pathToArrayContainer)['orderDetails[]']; + assert.ok(arrayParameter); + const input = { + ':clientId': 'test', + ':order': { + 'orderDetails': { + ':unitNo': 1234, + 'items':[{ ':itemDesc': 'item1'}, { ':itemDesc': 'item2'}] + }, + }, + }; + client.createWebOrder(input, function() { + var sentInputContent = client.lastRequest.substring(client.lastRequest.indexOf(''), client.lastRequest.lastIndexOf('') + ''.length); + assert.equal(sentInputContent, 'item1item2'); + done(); + }); + }); + }); + it('shall generate correct payload for methods with array parameter when individual array elements are not namespaced', function (done) { // used for servers that cannot aggregate individually namespaced array elements soap.createClient(__dirname + '/wsdl/list_parameter.wsdl', {disableCache: true, namespaceArrayElements: false}, function(err, client) { @@ -1001,7 +1047,7 @@ var fs = require('fs'), }); }); - + describe('Client created with createClientAsync', function () { it('should error on invalid host', function (done) { soap.createClientAsync('http://localhost:1', meta.options) @@ -1057,7 +1103,7 @@ var fs = require('fs'), done(); }); }); - + it('should allow customization of request for http client', function (done) { var myRequest = function () { }; diff --git a/test/wsdl/array_namespace_override.wsdl b/test/wsdl/array_namespace_override.wsdl new file mode 100644 index 000000000..c986a9baa --- /dev/null +++ b/test/wsdl/array_namespace_override.wsdl @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +