Skip to content

Commit

Permalink
Issue 537: Take namespaces that are configured to be ignored into acc…
Browse files Browse the repository at this point in the history
…ount

Although one can provide an array of namespaces that shall be ignored to createClient(), they are not used in objectToXml(). This commit fixes that.

Moreover it removes the shouldIgnoreNamespace() method because it makes no sense to explicitly configure namespaces to be ignored and than let some weird logic calculate if a given namespace is going to be ignored.
  • Loading branch information
tobias-neubert committed May 26, 2015
1 parent fb40288 commit 8f453e5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
37 changes: 2 additions & 35 deletions lib/wsdl.js
Expand Up @@ -1063,7 +1063,6 @@ var WSDL = function(definition, uri, options) {
};

WSDL.prototype.ignoredNamespaces = ['tns', 'targetNamespace', 'typedNamespace'];
WSDL.prototype._ignoredSchemaNamespaces = ['tns', 'xs', 'xsd'];

WSDL.prototype.valueKey = '$value';
WSDL.prototype.xmlKey = '$xml';
Expand Down Expand Up @@ -1147,37 +1146,6 @@ WSDL.prototype.describeServices = function() {
return services;
};

/**
* Returns true if a schema namespace needs to be ignored.
*
* @method shouldIgnoreNamespace
* @param {Object} schema The parsed WSDL Schema object.
*/
WSDL.prototype.shouldIgnoreNamespace = function(schema) {
if (schema && typeof schema.xmlns === 'object') {
// get the keys from schema.xmlns object (something like xs, xsd or custom)
var schemaXmlns = Object.keys(schema.xmlns);
var schemaXmlnsLength = schemaXmlns.length;
if (schemaXmlnsLength > 0) {
var count = 0;
// loop through the keys
for (var key in schemaXmlns) {
var xmlns = schemaXmlns[key];
// if the key exists in the default ignoredSchemaNamespaces, add it to the count
if (this._ignoredSchemaNamespaces.indexOf(xmlns) > -1) {
count++;
}
}
// if the count is equal to the length, don't add the namespace
if(count === schemaXmlnsLength) {
return true;
}
}
}

return false;
};

WSDL.prototype.toXML = function() {
return this.xml || '';
};
Expand Down Expand Up @@ -1490,12 +1458,11 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
var qualified = schema && schema.$elementFormDefault === 'qualified';
var parts = [];
var prefixNamespace = (namespace || qualified) && namespace !== 'xmlns';
var isNamespaceIgnored = this.shouldIgnoreNamespace(schema);

var xmlnsAttrib = '';
if (xmlns && first) {

if (prefixNamespace && (!isNamespaceIgnored || this.ignoredNamespaces.indexOf(namespace) === -1)) {
if (prefixNamespace && this.options.ignoredNamespaces.indexOf(namespace) === -1) {
// resolve the prefix namespace
xmlnsAttrib += ' xmlns:' + namespace + '="' + xmlns + '"';
}
Expand All @@ -1511,7 +1478,7 @@ WSDL.prototype.objectToXML = function(obj, name, namespace, xmlns, first, xmlnsA
}

var ns = '';
if (prefixNamespace && ((qualified || first) || soapHeader) && (!isNamespaceIgnored || this.ignoredNamespaces.indexOf(namespace) === -1)) {
if (prefixNamespace && ((qualified || first) || soapHeader) && this.options.ignoredNamespaces.indexOf(namespace) === -1) {
// prefix element
ns = namespace.indexOf(":") === -1 ? namespace + ':' : namespace;
}
Expand Down
@@ -0,0 +1,6 @@
{
"ignoredNamespaces": {
"namespaces": ["targetNamespace", "typedNamespace"],
"override": "true"
}
}
@@ -0,0 +1,6 @@
{
"ignoredNamespaces": {
"namespaces": ["targetNamespace", "typedNamespace"],
"override": "true"
}
}
@@ -0,0 +1,6 @@
{
"ignoredNamespaces": {
"namespaces": ["targetNamespace", "typedNamespace"],
"override": "true"
}
}

0 comments on commit 8f453e5

Please sign in to comment.