Skip to content

Commit

Permalink
Arrays with proper prefix and namespace (#1137)
Browse files Browse the repository at this point in the history
* Arrays with proper prefix and namespace

When Array has specific prefix and namespace as per the WSDL, the namespace reference is ignored completely. 

The current fix makes the array elements with prefix and namespace when available. (Not only during the first element and don't conflict with overrideRootElement option)

* added test cases for Arrays with proper prefix and namespace

* Removed unnecessary comments

* fixed lint errors

* Removed duplicate implementation

* fixed test failure and lint errors

Co-authored-by: Vimalraj <vimalraj.a@gaeaglobal.com>
  • Loading branch information
vimalraj-a and gaea-vimal committed Apr 8, 2021
1 parent 0ef3c0e commit 272a7da
Show file tree
Hide file tree
Showing 13 changed files with 1,332 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ export class WSDL {
}
}
} else if (typeof obj === 'object') {
let currentChildXmlnsAttrib = '';
for (name in obj) {
// Happens when Object.create(null) is used, it will not inherit the Object prototype
if (!obj.hasOwnProperty) {
Expand Down Expand Up @@ -834,7 +835,10 @@ export class WSDL {
if (childNsURI && childNsPrefix) {
if (nsContext.declareNamespace(childNsPrefix, childNsURI)) {
childXmlnsAttrib = ' xmlns:' + childNsPrefix + '="' + childNsURI + '"';
xmlnsAttrib += childXmlnsAttrib;
if (!xmlnsAttrib.includes(childNsPrefix)) {
currentChildXmlnsAttrib = childXmlnsAttrib;
xmlnsAttrib += childXmlnsAttrib;
}
}
}
}
Expand Down Expand Up @@ -874,6 +878,7 @@ export class WSDL {
current: childNsPrefix,
parent: ns,
};
childXmlnsAttrib = childXmlnsAttrib && childXmlnsAttrib.length ? childXmlnsAttrib : currentChildXmlnsAttrib;
} else {
// parent (array) already got the namespace
childXmlnsAttrib = null;
Expand Down
47 changes: 47 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,53 @@ it('should create async client without options', function (done) {
});
});

it('should add namespace to array of objects', function (done) {
soap.createClientAsync(__dirname + '/wsdl/PurchaseRequestService.wsdl').then(function (client) {
const input = {
errorProcessingLevel: "ALL",
groupBy: "SUPPLIER",
initiateApprovalAfterRequisitionImport: "N",
interfaceSourceCode: "ABC",
purchaseRequestPayload: {
ApproverEmail: "abc@gmail.com",
ApproverId: "idname",
PurchaseRequestInputReqLineInterface:
[
{
Amount: "600.00",
GroupCode: "supplier",
ItemDescription: "test1",
LineTypeId: 6,
ProductType: "SERVICES",
RequestedDeliveryDate: "2021-02-26",

},
{
Amount: "400.00",
GroupCode: "supplier",
ItemDescription: "test2",
LineTypeId: 7,
ProductType: "SERVICES",
RequestedDeliveryDate: "2021-02-28",
},
],
},
RequisitioningBUName: "BU",
requisitioningBUName: "BU",
};
client.setSecurity(new soap.BasicAuthSecurity('username', 'password'));
client.createRequisition(input,function(err, result, rawResponse, soapHeader, rawRequest) {
const match = rawRequest.match(/<ns1:PurchaseRequestInputReqLineInterface xmlns:.{3}="(.*?)">/);
if(match && match.length) {
assert.ok(match[0])
} else {
assert.ok(null, `Array object don't have namesapce`)
}
done();
});
});
});


describe('Client using stream and returnSaxStream', () => {
let server = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"return":"-1",
"bstrError":""
"bstrError":"1"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError></bstrError></snp:Message></soap:Body></soap:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError>1</bstrError></snp:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"return":"-1",
"bstrError":""
"bstrError":"1"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError></bstrError></snp:Message></soap:Body></soap:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError>1</bstrError></snp:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"return":"-1",
"bstrError":""
"bstrError":"1"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError></bstrError></snp:Message></soap:Body></soap:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError>1</bstrError></snp:Message></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"return":"-1",
"bstrError":""
"bstrError":"1"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError></bstrError></snp:Message></soap:Body></soap:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"><soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><snp:Message xmlns:snp="urn:MessageService"><return>-1</return><bstrError>1</bstrError></snp:Message></soap:Body></soap:Envelope>
Loading

0 comments on commit 272a7da

Please sign in to comment.