Skip to content

Commit 6c53baa

Browse files
committed
Merge pull request vpulim#493 from dun4n/master
`wsdl.extend()` Copy properties from one object to another without overriding already existing properties.
2 parents 3be4afa + 19e303a commit 6c53baa

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

lib/wsdl.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,21 @@ function trim(text) {
7373
return text.replace(trimLeft, '').replace(trimRight, '');
7474
}
7575

76+
/**
77+
* What we want is to copy properties from one object to another one and avoid
78+
* properties overriding. This way we ensure the 'inheritance' of
79+
* <xsd:extension base=...> usage.
80+
*
81+
* NB: 'Element' (and subtypes) don't have any prototyped properties: there's
82+
* no need to process a 'hasOwnProperties' call, we should just iterate over the
83+
* keys.
84+
*/
7685
function extend(base, obj) {
77-
for (var key in obj) {
78-
if (!obj.hasOwnProperty(key)) {
86+
Object.keys(obj).forEach(function(key) {
87+
if(!base.hasOwnProperty(key))
7988
base[key] = obj[key];
80-
}
81-
}
89+
});
90+
8291
return base;
8392
}
8493

test/wsdl/extended_element.wsdl

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
3+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
4+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
5+
xmlns:tns="http://www.Dummy.com" xmlns:n="http://www.Dummy.com/Name/Types" xmlns:ns="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://www.Dummy.com">
6+
<wsdl:types>
7+
<xs:schema>
8+
<xs:import namespace="http://www.Dummy.com/Common/Types" schemaLocation="./Common.xsd"/>
9+
<xs:import namespace="http://www.Dummy.com/Name/Types" schemaLocation="./Name.xsd"/>
10+
</xs:schema>
11+
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.example.com/v1" xmlns:e="http://www.example.com/v1">
12+
<xs:element name="ExtendedDummyRequest">
13+
<xs:complexType>
14+
<xs:complexContent>
15+
<xs:extension base="n:DummyRequest">
16+
<xs:sequence>
17+
<xs:element name="ExtendedDummyField" type="xs:string" minOccurs="0"/>
18+
</xs:sequence>
19+
</xs:extension>
20+
</xs:complexContent>
21+
</xs:complexType>
22+
</xs:element>
23+
</xs:schema>
24+
</wsdl:types>
25+
<wsdl:message name="DummyRequest">
26+
<wsdl:part name="DummyRequest" element="e:ExtendedDummyRequest"/>
27+
</wsdl:message>
28+
<wsdl:message name="DummyResponse">
29+
<wsdl:part name="DummyResponse" element="n:DummyResponse"/>
30+
</wsdl:message>
31+
<wsdl:portType name="DummyPortType">
32+
<wsdl:operation name="Dummy">
33+
<wsdl:input message="tns:DummyRequest"/>
34+
<wsdl:output message="tns:DummyResponse"/>
35+
</wsdl:operation>
36+
</wsdl:portType>
37+
<wsdl:binding name="DummyBinding" type="tns:DummyPortType">
38+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
39+
<wsdl:operation name="Dummy">
40+
<soap:operation soapAction="http://www.Dummy.com#Dummy" style="document"/>
41+
<wsdl:input>
42+
<soap:body use="literal"/>
43+
</wsdl:input>
44+
<wsdl:output>
45+
<soap:body use="literal"/>
46+
</wsdl:output>
47+
</wsdl:operation>
48+
<wsdl:operation name="DummySave">
49+
<soap:operation soapAction="http://www.Dummy.com#DummySave" style="document"/>
50+
<wsdl:input>
51+
<soap:body use="literal"/>
52+
</wsdl:input>
53+
<wsdl:output>
54+
<soap:body use="literal"/>
55+
</wsdl:output>
56+
</wsdl:operation>
57+
</wsdl:binding>
58+
<wsdl:service name="DummyService">
59+
<wsdl:port name="DummyPortType" binding="tns:DummyBinding">
60+
<soap:address location="http://www.Dummy.com/"/>
61+
</wsdl:port>
62+
</wsdl:service>
63+
</wsdl:definitions>

0 commit comments

Comments
 (0)