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

feature (xml key): allow in first level for rpc #1219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 13 additions & 9 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,17 +595,21 @@ export class WSDL {
}
if (key !== nsAttrName) {
const value = params[key];
const prefixedKey = (isParts ? '' : nsPrefix) + key;
const attributes = [];
if (typeof value === 'object' && value.hasOwnProperty(this.options.attributesKey)) {
const attrs = value[this.options.attributesKey];
for (const n in attrs) {
attributes.push(' ' + n + '=' + '"' + attrs[n] + '"');
if (key === this.options.xmlKey) {
parts.push(this.objectToXML({[key]: value}, null, nsPrefix, nsURI));
} else {
const prefixedKey = (isParts ? '' : nsPrefix) + key;
const attributes = [];
if (typeof value === 'object' && value.hasOwnProperty(this.options.attributesKey)) {
const attrs = value[this.options.attributesKey];
for (const n in attrs) {
attributes.push(' ' + n + '=' + '"' + attrs[n] + '"');
}
}
parts.push(['<', prefixedKey].concat(attributes).concat('>').join(''));
parts.push((typeof value === 'object') ? this.objectToXML(value, key, nsPrefix, nsURI) : xmlEscape(value));
parts.push(['</', prefixedKey, '>'].join(''));
}
parts.push(['<', prefixedKey].concat(attributes).concat('>').join(''));
parts.push((typeof value === 'object') ? this.objectToXML(value, key, nsPrefix, nsURI) : xmlEscape(value));
parts.push(['</', prefixedKey, '>'].join(''));
}
}
parts.push(['</', nsPrefix, name, '>'].join(''));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:tns="http://www.Dummy.com/Common/Types" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.Dummy.com/Common/Types" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="DummyResult">
<xs:sequence>
<xs:element name="DummyList" type="tns:DummyList" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="code" type="xs:string" use="optional"/>
</xs:complexType>
<xs:complexType name="Dummy">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="language" type="xs:language" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="DummyList">
<xs:sequence>
<xs:element name="DummyElement" type="tns:Dummy" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:tns="http://www.Dummy.com/Name/Types" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.Dummy.com/Name/Types" elementFormDefault="qualified"
attributeFormDefault="unqualified" xmlns:c="http://www.Dummy.com/Common/Types">
<xs:import namespace="common.xsd" schemaLocation="common.xsd"/>
<xs:element name="DummyRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="DummyXML" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DummyResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="DummyResult" type="c:DummyResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"$xml": "<tns:DummyXML><myObject attr='myAttr'></myObject></tns:DummyXML>"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.Dummy.com" xmlns:n="http://www.Dummy.com/Name/Types"><soap:Body><tns:Dummy><tns:DummyXML><myObject attr='myAttr'></myObject></tns:DummyXML></tns:Dummy></soap:Body></soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"DummyResult": {
"DummyList": {
"DummyElement": {
"attributes": {
"language": "en-US"
},
"$value": "Dummy Element Entry"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.Dummy.com" xmlns:n="http://www.Dummy.com/Name/Types">
<soap:Header></soap:Header>
<soap:Body>
<n:DummyResponse>
<n:DummyResult>
<c:DummyList xmlns:c="http://www.Dummy.com/Common/Types">
<c:DummyElement language="en-US">
Dummy Element Entry
</c:DummyElement>
</c:DummyList>
</n:DummyResult>
</n:DummyResponse>
</soap:Body>
</soap:Envelope>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
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">
<wsdl:types>
<xs:schema>
<xs:import namespace="http://www.Dummy.com/Common/Types" schemaLocation="common.xsd"/>
<xs:import namespace="http://www.Dummy.com/Name/Types" schemaLocation="name.xsd"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="DummyRequest">
<wsdl:part name="DummyRequest" element="n:DummyRequest"/>
</wsdl:message>
<wsdl:message name="DummyResponse">
<wsdl:part name="DummyResponse" element="n:DummyResponse"/>
</wsdl:message>
<wsdl:portType name="DummyPortType">
<wsdl:operation name="Dummy">
<soap12:operation soapAction="" style="rpc"/>
<wsdl:input message="tns:DummyRequest"/>
<wsdl:output message="tns:DummyResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="DummyBinding" type="tns:DummyPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Dummy">
<soap:operation soapAction="http://www.Dummy.com#Dummy" style="rpc"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="DummyService">
<wsdl:port name="DummyPortType" binding="tns:DummyBinding">
<soap:address location="http://www.Dummy.com/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>