Skip to content

Commit cb1de16

Browse files
Nichew666
authored andcommitted
Allow options in objectToDocumentXML when calling a method
* Options is optional field for objectToDocumentXML function * Replicates `_xml` parameter functionality (sending a custom XML structure as a literal) with JSON arguments.
1 parent 44f304a commit cb1de16

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export class Client extends EventEmitter {
413413
} else {
414414
assert.ok(!style || style === 'document', 'invalid message definition for rpc style binding');
415415
// pass `input.$lookupType` if `input.$type` could not be found
416-
message = this.wsdl.objectToDocumentXML(input.$name, args, input.targetNSAlias, input.targetNamespace, (input.$type || input.$lookupType));
416+
message = this.wsdl.objectToDocumentXML(input.$name, args, input.targetNSAlias, input.targetNamespace, (input.$type || input.$lookupType), options);
417417
}
418418

419419
let decodedHeaders;

src/wsdl/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,13 +567,20 @@ export class WSDL {
567567
* @param {String} nsURI
568568
* @param {String} type
569569
*/
570-
public objectToDocumentXML(name: string, params, nsPrefix: string, nsURI?: string, type?: string) {
570+
public objectToDocumentXML(name: string, params, nsPrefix: string, nsURI?: string, type?: string, options?: any) {
571571
// If user supplies XML already, just use that. XML Declaration should not be present.
572572
if (params && params._xml) {
573573
return params._xml;
574574
}
575575
const args = {};
576-
args[name] = params;
576+
const opts = options || {};
577+
if (opts.overrideBaseElement) {
578+
Object.keys(params).forEach((k: string) => {
579+
args[k] = params[k];
580+
});
581+
} else {
582+
args[name] = params;
583+
}
577584
const parameterTypeObj = type ? this.findSchemaObject(nsURI, type) : null;
578585
return this.objectToXML(args, null, nsPrefix, nsURI, true, null, parameterTypeObj);
579586
}

test/client-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,3 +1833,41 @@ describe('Client posting complex body', () => {
18331833
}, baseUrl);
18341834
});
18351835
});
1836+
1837+
it('should replace the InputMessage "Request" element for arg elements', function (done) {
1838+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', {
1839+
ignoredNamespaces: true,
1840+
ignoreBaseNameSpaces: true
1841+
}, function(err, client) {
1842+
assert.ok(client);
1843+
client.MyService.MyServicePort.MyOperation(
1844+
{ parameter: 'dummy' },
1845+
function(err, result, resp, soap, req) {
1846+
assert.equal(req.indexOf('</Request>'), -1);
1847+
},
1848+
{
1849+
overrideBaseElement: true
1850+
}
1851+
);
1852+
done();
1853+
});
1854+
});
1855+
1856+
it('should replace the InputMessage "Request" element for arg elements', function (done) {
1857+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', {
1858+
ignoredNamespaces: true,
1859+
ignoreBaseNameSpaces: true
1860+
}, function(err, client) {
1861+
assert.ok(client);
1862+
client.MyService.MyServicePort.MyOperation(
1863+
{ parameter: 'dummy' },
1864+
function(err, result, resp, soap, req) {
1865+
assert.equal(req.indexOf('</Request>'), -1);
1866+
},
1867+
{
1868+
overrideBaseElement: true
1869+
}
1870+
);
1871+
done();
1872+
});
1873+
});

0 commit comments

Comments
 (0)