Skip to content

Commit fe3ec15

Browse files
authored
Merge pull request #83 from svandriel/bugfix/fix-output-response
Fixed: Output message without nested element defaulted to request type
2 parents 70cacd2 + e625808 commit fe3ec15

File tree

4 files changed

+100
-17
lines changed

4 files changed

+100
-17
lines changed

src/parser.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ export async function parseWsdl(wsdlPath: string, options: Partial<ParserOptions
287287
Logger.debug(`Parsing Method ${methodName}`);
288288

289289
// TODO: Deduplicate code below by refactoring it to external function. Is it even possible ?
290-
let paramName = "request";
290+
let requestParamName = "request";
291291
let inputDefinition: Definition = null; // default type
292292
if (method.input) {
293293
if (method.input.$name) {
294-
paramName = method.input.$name;
294+
requestParamName = method.input.$name;
295295
}
296296
const inputMessage = wsdl.definitions.messages[method.input.$name];
297297
if (inputMessage.element) {
@@ -311,15 +311,15 @@ export async function parseWsdl(wsdlPath: string, options: Partial<ParserOptions
311311
visitedDefinitions
312312
);
313313
} else if (inputMessage.parts) {
314-
const type = parsedWsdl.findDefinition(paramName);
314+
const type = parsedWsdl.findDefinition(requestParamName);
315315
inputDefinition =
316316
type ??
317317
parseDefinition(
318318
parsedWsdl,
319319
mergedOptions,
320-
paramName,
320+
requestParamName,
321321
inputMessage.parts,
322-
[paramName],
322+
[requestParamName],
323323
visitedDefinitions
324324
);
325325
} else {
@@ -329,8 +329,12 @@ export async function parseWsdl(wsdlPath: string, options: Partial<ParserOptions
329329
}
330330
}
331331

332+
let responseParamName = "response";
332333
let outputDefinition: Definition = null; // default type, `{}` or `unknown` ?
333334
if (method.output) {
335+
if (method.output.$name) {
336+
responseParamName = method.output.$name;
337+
}
334338
const outputMessage = wsdl.definitions.messages[method.output.$name];
335339
if (outputMessage.element) {
336340
// TODO: if `$type` not defined, inline type into function declartion (do not create definition file) - wsimport
@@ -347,21 +351,21 @@ export async function parseWsdl(wsdlPath: string, options: Partial<ParserOptions
347351
visitedDefinitions
348352
);
349353
} else {
350-
const type = parsedWsdl.findDefinition(paramName);
354+
const type = parsedWsdl.findDefinition(responseParamName);
351355
outputDefinition =
352356
type ??
353357
parseDefinition(
354358
parsedWsdl,
355359
mergedOptions,
356-
paramName,
360+
responseParamName,
357361
outputMessage.parts,
358-
[paramName],
362+
[responseParamName],
359363
visitedDefinitions
360364
);
361365
}
362366
}
363367

364-
const camelParamName = changeCase(paramName);
368+
const camelParamName = changeCase(requestParamName);
365369
const portMethod: Method = {
366370
name: methodName,
367371
paramName: reservedKeywords.includes(camelParamName)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import test from "tape";
2+
import { existsSync } from "fs";
3+
import { parseAndGenerate } from "../../src";
4+
import { Logger } from "../../src/utils/logger";
5+
import { typecheck } from "../utils/tsc";
6+
7+
const target = "hello_service";
8+
9+
test(target, async (t) => {
10+
Logger.disabled();
11+
12+
const input = `./test/resources/${target}.wsdl`;
13+
const outdir = "./test/generated";
14+
15+
const expectedFiles = [
16+
"client.ts",
17+
"index.ts",
18+
"definitions/SayHelloRequest.ts",
19+
"definitions/SayHelloResponse.ts",
20+
"ports/HelloPort.ts",
21+
"services/HelloService.ts",
22+
];
23+
24+
t.test(`${target} - generate wsdl client`, async (t) => {
25+
await parseAndGenerate(input, outdir);
26+
t.end();
27+
});
28+
29+
expectedFiles.forEach((file) => {
30+
t.test(`${target} - ${file} exists`, async (t) => {
31+
t.equal(existsSync(`${outdir}/helloservice/${file}`), true);
32+
t.end();
33+
});
34+
});
35+
36+
t.test(`${target} - compile`, async (t) => {
37+
await typecheck(`${outdir}/helloservice/index.ts`);
38+
t.end();
39+
});
40+
});

test/node-soap/ref_element_same_as_type.test.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@ import { typecheck } from "../utils/tsc";
66

77
const target = "ref_element_same_as_type";
88

9-
test(target, async t => {
9+
test(target, async (t) => {
1010
Logger.disabled();
1111

1212
const input = `./test/resources/${target}.wsdl`;
1313
const outdir = "./test/generated";
1414

15-
t.test(`${target} - generate wsdl client`, async t => {
15+
t.test(`${target} - generate wsdl client`, async (t) => {
1616
await parseAndGenerate(input, outdir);
1717
t.end();
1818
});
1919

20-
t.test(`${target} - check definitions`, async t => {
20+
t.test(`${target} - check definitions`, async (t) => {
2121
t.equal(existsSync(`${outdir}/refelementsameastype/definitions/ExampleContent.ts`), true);
22-
t.equal(existsSync(`${outdir}/refelementsameastype/definitions/ExampleRequest.ts`), true);
22+
t.equal(existsSync(`${outdir}/refelementsameastype/definitions/OutMessage.ts`), true);
2323
t.equal(existsSync(`${outdir}/refelementsameastype/definitions/V1ExampleRequestType.ts`), true);
2424
t.end();
2525
});
2626

27-
t.test(`${target} - compile`, async t => {
27+
t.test(`${target} - compile`, async (t) => {
2828
await typecheck(`${outdir}/refelementsameastype/index.ts`);
29-
t.end();
29+
t.end();
3030
});
31-
32-
});
31+
});

test/resources/hello_service.wsdl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<definitions name="HelloService"
3+
targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
4+
xmlns="http://schemas.xmlsoap.org/wsdl/"
5+
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
6+
xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
7+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
8+
<message name="SayHelloRequest">
9+
<part name="firstName" type="xsd:string" />
10+
</message>
11+
<message name="SayHelloResponse">
12+
<part name="greeting" type="xsd:string" />
13+
</message>
14+
<portType name="Hello_PortType">
15+
<operation name="sayHello">
16+
<input message="tns:SayHelloRequest" />
17+
<output message="tns:SayHelloResponse" />
18+
</operation>
19+
</portType>
20+
<binding name="Hello_Binding" type="tns:Hello_PortType">
21+
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
22+
<operation name="sayHello">
23+
<soap:operation soapAction="sayHello" />
24+
<input>
25+
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
26+
namespace="urn:examples:helloservice" use="encoded" />
27+
</input>
28+
<output>
29+
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
30+
namespace="urn:examples:helloservice" use="encoded" />
31+
</output>
32+
</operation>
33+
</binding>
34+
<service name="Hello_Service">
35+
<documentation>WSDL File for HelloService</documentation>
36+
<port binding="tns:Hello_Binding" name="Hello_Port">
37+
<soap:address location="http://localhost:51515/SayHello/" />
38+
</port>
39+
</service>
40+
</definitions>

0 commit comments

Comments
 (0)