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

soap client describe() resolves namespace cross references between schema #1014

Merged
merged 7 commits into from
Jul 23, 2018
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
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ Server.prototype._envelope = function (body, headers, includeTimestamp) {

var envelopeDefinition = this.wsdl.options.forceSoap12Headers
? "http://www.w3.org/2003/05/soap-envelope"
: "http://schemas.xmlsoap.org/soap/envelope/"
: "http://schemas.xmlsoap.org/soap/envelope/";

var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"" + envelopeDefinition + "\" " +
Expand Down
41 changes: 27 additions & 14 deletions lib/wsdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ function deepMerge(destination, source) {
});
}

var Element = function(nsName, attrs, options) {
var Element = function(nsName, attrs, options, schemaAttrs) {
var parts = splitQName(nsName);

this.nsName = nsName;
this.prefix = parts.prefix;
this.name = parts.name;
this.children = [];
this.xmlns = {};
this.schemaXmlns = {};

this._initializeOptions(options);

Expand All @@ -116,6 +117,12 @@ var Element = function(nsName, attrs, options) {
}
}
}
for (var schemaKey in schemaAttrs) {
var schemaMatch = /^xmlns:?(.*)$/.exec(schemaKey);
if (schemaMatch && schemaMatch[1]) {
this.schemaXmlns[schemaMatch[1]] = schemaAttrs[schemaKey];
}
}
if (this.$targetNamespace !== undefined) {
// Add targetNamespace to the mapping
this.xmlns[TNS_PREFIX] = this.$targetNamespace;
Expand Down Expand Up @@ -144,7 +151,7 @@ Element.prototype.deleteFixedAttrs = function() {

Element.prototype.allowedChildren = [];

Element.prototype.startElement = function(stack, nsName, attrs, options) {
Element.prototype.startElement = function(stack, nsName, attrs, options, schemaXmlns) {
if (!this.allowedChildren) {
return;
}
Expand All @@ -153,7 +160,7 @@ Element.prototype.startElement = function(stack, nsName, attrs, options) {
element = null;

if (ChildClass) {
stack.push(new ChildClass(nsName, attrs, options));
stack.push(new ChildClass(nsName, attrs, options, schemaXmlns));
}
else {
this.unexpected(nsName);
Expand Down Expand Up @@ -501,11 +508,11 @@ MessageElement.prototype.postProcess = function(definitions) {
// if nested lookup types where found, prepare them for furter usage
if (lookupTypes.length > 0) {
lookupTypes = lookupTypes.
join('_').
split('_').
filter(function removeEmptyLookupTypes (type) {
return type !== '^';
});
join('_').
split('_').
filter(function removeEmptyLookupTypes (type) {
return type !== '^';
});

var schemaXmlns = definitions.schemas[this.element.targetNamespace].xmlns;

Expand Down Expand Up @@ -855,7 +862,9 @@ ElementElement.prototype.description = function(definitions, xmlns) {
if (type) {
type = splitQName(type);
var typeName = type.name,
ns = xmlns && xmlns[type.prefix] || definitions.xmlns[type.prefix],
ns = xmlns && xmlns[type.prefix] ||
(definitions.xmlns[type.prefix] !== undefined && this.schemaXmlns[type.prefix]) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when checking for !== undefined explicitly, we are aware that null would pass - is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I checked the presence or absence of the property, not its value. So yes, it was intentional to check only for undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I could change definitions.xmlns[type.prefix] !== undefined into definitions.xmlns[type.prefix]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the presence or absence of the property

good catch, I didn' t think of that... 👍

definitions.xmlns[type.prefix],
schema = definitions.schemas[ns],
typeElement = schema && ( this.$type? schema.complexTypes[typeName] || schema.types[typeName] : schema.elements[typeName] );

Expand Down Expand Up @@ -2104,26 +2113,30 @@ WSDL.prototype._parse = function(xml) {
root = null,
types = null,
schema = null,
options = self.options;
schemaAttrs = null,
options = self.options;

p.onopentag = function(node) {
var nsName = node.name;
var attrs = node.attributes;

var top = stack[stack.length - 1];
var name;
var name = splitQName(nsName).name;

if (name === 'schema') {
schemaAttrs = attrs;
}
if (top) {
try {
top.startElement(stack, nsName, attrs, options);
top.startElement(stack, nsName, attrs, options, schemaAttrs);
} catch (e) {
if (self.options.strict) {
throw e;
} else {
stack.push(new Element(nsName, attrs, options));
stack.push(new Element(nsName, attrs, options, schemaAttrs));
}
}
} else {
name = splitQName(nsName).name;
if (name === 'definitions') {
root = new DefinitionsElement(nsName, attrs, options);
stack.push(root);
Expand Down
Loading