Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 537: Take namespaces configured to be ignored into account #662

Merged
merged 1 commit into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 2 additions & 35 deletions lib/wsdl.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignoredNamespaces": {
"namespaces": ["targetNamespace", "typedNamespace"],
"override": "true"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignoredNamespaces": {
"namespaces": ["targetNamespace", "typedNamespace"],
"override": "true"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ignoredNamespaces": {
"namespaces": ["targetNamespace", "typedNamespace"],
"override": "true"
}
}