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

Adding attributes parsing #1251

Merged
merged 1 commit into from
Aug 21, 2024
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
43 changes: 38 additions & 5 deletions src/wsdl/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ export class ElementElement extends Element {
Object.keys(description).forEach((key) => {
elem[key] = description[key];
});

const $attributes = description[AttributeElement.Symbol];
if ($attributes) {
elem[AttributeElement.Symbol] = $attributes;
}
}

if (this.$ref) {
Expand Down Expand Up @@ -486,20 +491,34 @@ export class ComplexTypeElement extends Element {
'complexContent',
'sequence',
'simpleContent',
'attribute',
]);
public description(definitions: DefinitionsElement, xmlns: IXmlNs) {
let ret = {};
let isFirstChild = false;
const $attributes = {};
const children = this.children || [];
for (const child of children) {
if (child instanceof ChoiceElement ||
if (child instanceof AttributeElement) {
$attributes[child.$name] = child.description(definitions);
continue;
}

if (!isFirstChild && (child instanceof ChoiceElement ||
child instanceof SequenceElement ||
child instanceof AllElement ||
child instanceof SimpleContentElement ||
child instanceof ComplexContentElement) {

return child.description(definitions, xmlns);
child instanceof ComplexContentElement)) {
isFirstChild = true;
ret = child.description(definitions, xmlns);
}
}
return {};

if (Object.keys($attributes).length > 0) {
ret[AttributeElement.Symbol] = $attributes;
}

return ret;
}
}

Expand Down Expand Up @@ -553,6 +572,19 @@ export class SequenceElement extends Element {
}
}

export class AttributeElement extends Element {
public static Symbol = Symbol('$attributes');
public $type?: string;
public $use?: string;

public description(definitions: DefinitionsElement) {
return {
type: this.$type,
required: this.$use === 'required',
};
}
}

export class AllElement extends Element {
public readonly allowedChildren = buildAllowedChildren([
'choice',
Expand Down Expand Up @@ -1187,6 +1219,7 @@ const ElementTypeMap: {
simpleContent: SimpleContentElement,
simpleType: SimpleTypeElement,
types: TypesElement,
attribute: AttributeElement,
};

function buildAllowedChildren(elementList: string[]): { [k: string]: typeof Element } {
Expand Down
22 changes: 21 additions & 1 deletion test/wsdl-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var fs = require('fs'),
soap = require('..'),
WSDL = require('../lib/wsdl').WSDL,
assert = require('assert'),
sinon = require('sinon');
sinon = require('sinon'),
elements = require('../lib/wsdl/elements');

describe('WSDL Parser (strict)', () => {

Expand Down Expand Up @@ -350,4 +351,23 @@ describe('WSDL Parser (non-strict)', () => {
done();
});
});

it('Should describe return correct result for attributes in complexTypeElement', function(done) {
soap.createClient(__dirname+ '/wsdl/wsdl_with_attributes.wsdl', function(err,client){
assert.ifError(err);
var description = client.describe();

assert.deepEqual(description.StockQuoteService.StockQuotePort.GetLastTradePrice.input[elements.AttributeElement.Symbol], {
AttributeInOne: { type: "s:boolean", required: false },
AttributeInTwo: { type: "s:boolean", required: true },
});
assert.deepEqual(description.StockQuoteService.StockQuotePort.GetLastTradePrice.output[elements.AttributeElement.Symbol], {
AttributeOut: { type: "s:boolean", required: true },
});

assert.deepEqual(Object.keys(description.StockQuoteService.StockQuotePort.GetLastTradePrice.input), ['tickerSymbol']);
assert.deepEqual(Object.keys(description.StockQuoteService.StockQuotePort.GetLastTradePrice.output), []);
done();
});
});
});
64 changes: 64 additions & 0 deletions test/wsdl/wsdl_with_attributes.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<definitions name="StockQuote"
targetNamespace="http://example.com/stockquote.wsdl"
xmlns:tns="http://example.com/stockquote.wsdl"
xmlns:xsd1="http://example.com/stockquote.xsd"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="http://example.com/stockquote.xsd"
xmlns="http://www.w3.org/2000/10/XMLSchema">
<element name="TradePriceRequest">
<complexType>
<s:attribute name="AttributeInOne" type="s:boolean" />
<all>
<element name="tickerSymbol" type="string"/>
</all>
<s:attribute name="AttributeInTwo" type="s:boolean" use="required" />
</complexType>
</element>
<element name="TradePrice">
<complexType>
<element name="price" type="float"/>
<s:attribute name="AttributeOut" type="s:boolean" use="required" />
</complexType>
</element>
</schema>
</types>

<message name="GetLastTradePriceInput">
<part name="body" element="xsd1:TradePriceRequest"/>
</message>

<message name="GetLastTradePriceOutput">
<part name="body" element="xsd1:TradePrice"/>
</message>

<portType name="StockQuotePortType">
<operation name="GetLastTradePrice">
<input message="tns:GetLastTradePriceInput"/>
<output message="tns:GetLastTradePriceOutput"/>
</operation>
</portType>

<binding name="StockQuoteSoapBinding" type="tns:StockQuotePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="GetLastTradePrice">
<soap:operation soapAction="http://example.com/GetLastTradePrice"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

<service name="StockQuoteService">
<documentation>My first service</documentation>
<port name="StockQuotePort" binding="tns:StockQuoteSoapBinding">
<soap:address location="http://example.com/stockquote"/>
</port>
</service>

</definitions>
Loading