Skip to content

Commit

Permalink
Circular element references inside wsdl - assistance needed (#1142)
Browse files Browse the repository at this point in the history
* Tests for circular element references inside wsdl

* Fixing mess with type names and element names while parsing wsdl
  • Loading branch information
doubleaxe authored May 14, 2021
1 parent e61aa55 commit d684525
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/wsdl/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,18 @@ export class ElementElement extends Element {
definitions.xmlns[type.prefix];
const schema = definitions.schemas[ns];
const typeElement = schema && ( this.$type ? schema.complexTypes[typeName] || schema.types[typeName] : schema.elements[typeName] );
const typeStorage = this.$type ? definitions.descriptions.types : definitions.descriptions.elements;

if (ns && definitions.schemas[ns]) {
xmlns = definitions.schemas[ns].xmlns;
}

if (typeElement && !(typeName in Primitives)) {

if (!(typeName in definitions.descriptions.types)) {
if (!(typeName in typeStorage)) {

let elem: any = {};
if (!this.$ref) {
definitions.descriptions.types[typeName] = elem;
}
typeStorage[typeName] = elem;

const description = typeElement.description(definitions, xmlns);
if (typeof description === 'string') {
Expand All @@ -265,12 +264,12 @@ export class ElementElement extends Element {
elem.targetNamespace = ns;
}

definitions.descriptions.types[typeName] = elem;
typeStorage[typeName] = elem;
} else {
if (this.$ref) {
element = definitions.descriptions.types[typeName];
element = typeStorage[typeName];
} else {
element[name] = definitions.descriptions.types[typeName];
element[name] = typeStorage[typeName];
}
}

Expand Down Expand Up @@ -1082,8 +1081,12 @@ export class DefinitionsElement extends Element {
types: {
[key: string]: Element;
},
elements: {
[key: string]: Element;
},
} = {
types: {},
elements: {},
};

public init() {
Expand Down
1 change: 1 addition & 0 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ export class WSDL {
this.definitions = this._parse(xml);
this.definitions.descriptions = {
types: {},
elements: {},
};
this.xml = xml;
}
Expand Down
18 changes: 18 additions & 0 deletions test/wsdl-parse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ describe(__filename, function () {
done();
});
});

it('should parse recursive wsdls with element references', function (done) {
open_wsdl(path.resolve(__dirname, 'wsdl/recursive_with_ref.wsdl'), function (err, def) {
assert.ifError(err);
var desc = def.definitions.portTypes.CloudSignService.description(def.definitions);
assert.equal(desc.AddSignature.input.properties.property && desc.AddSignature.input.properties.property.value2, 'string');
done();
});
});

it('should parse recursive wsdls with element references and complex types named same as references', function (done) {
open_wsdl(path.resolve(__dirname, 'wsdl/recursive_with_ref2.wsdl'), function (err, def) {
assert.ifError(err);
var desc = def.definitions.portTypes.CloudSignService.description(def.definitions);
assert.equal(desc.AddSignature.input.properties.property && desc.AddSignature.input.properties.property.value2, 'string');
done();
});
});
});
72 changes: 72 additions & 0 deletions test/wsdl/recursive_with_ref.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.comped.it/CloudSignService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
name="CloudSignService" targetNamespace="http://www.comped.it/CloudSignService"
xmlns:fault="http://www.comped.it/te/serviceFault" xmlns:p="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.comped.it/CloudSignService">
<element name="property">
<complexType>
<sequence>
<element name="value2" type="string" minOccurs="0"/>
<element ref="tns:property" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>

<complexType name="properties">
<sequence>
<element ref="tns:property" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>

<element name="AddSignature">
<complexType>
<sequence>
<element name="properties" type="tns:properties"/>
</sequence>
</complexType>
</element>

<element name="AddSignatureResponse">
<complexType>
<sequence>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>

<wsdl:message name="AddSignatureRequest">
<wsdl:part element="tns:AddSignature" name="parameters" />
</wsdl:message>
<wsdl:message name="AddSignatureResponse">
<wsdl:part element="tns:AddSignatureResponse" name="parameters" />
</wsdl:message>
<wsdl:portType name="CloudSignService">
<wsdl:operation name="AddSignature">
<wsdl:input message="tns:AddSignatureRequest" />
<wsdl:output message="tns:AddSignatureResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CloudSignServiceSOAP" type="tns:CloudSignService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="AddSignature">
<soap:operation soapAction="http://www.comped.it/CloudSignService/AddSignature" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CloudSignService">
<wsdl:port binding="tns:CloudSignServiceSOAP" name="CloudSignServiceSOAP">
<soap:address location="http://www.example.org/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
72 changes: 72 additions & 0 deletions test/wsdl/recursive_with_ref2.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.comped.it/CloudSignService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
name="CloudSignService" targetNamespace="http://www.comped.it/CloudSignService"
xmlns:fault="http://www.comped.it/te/serviceFault" xmlns:p="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.comped.it/CloudSignService">
<element name="property">
<complexType>
<sequence>
<element name="value2" type="string" minOccurs="0"/>
<element ref="tns:property" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>

<complexType name="property">
<sequence>
<element ref="tns:property" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>

<element name="AddSignature">
<complexType>
<sequence>
<element name="properties" type="tns:property"/>
</sequence>
</complexType>
</element>

<element name="AddSignatureResponse">
<complexType>
<sequence>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>

<wsdl:message name="AddSignatureRequest">
<wsdl:part element="tns:AddSignature" name="parameters" />
</wsdl:message>
<wsdl:message name="AddSignatureResponse">
<wsdl:part element="tns:AddSignatureResponse" name="parameters" />
</wsdl:message>
<wsdl:portType name="CloudSignService">
<wsdl:operation name="AddSignature">
<wsdl:input message="tns:AddSignatureRequest" />
<wsdl:output message="tns:AddSignatureResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CloudSignServiceSOAP" type="tns:CloudSignService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="AddSignature">
<soap:operation soapAction="http://www.comped.it/CloudSignService/AddSignature" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CloudSignService">
<wsdl:port binding="tns:CloudSignServiceSOAP" name="CloudSignServiceSOAP">
<soap:address location="http://www.example.org/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

0 comments on commit d684525

Please sign in to comment.