From f631c883451c684eeeb78fc56b54eba5480da09b Mon Sep 17 00:00:00 2001 From: David Sedman Cox Automotive Date: Wed, 19 Oct 2022 13:40:30 +0100 Subject: [PATCH] Fix: null definitions and failing tests --- src/generator.ts | 16 ++++++++++++++-- test/resources-public/products.test.ts | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/generator.ts b/src/generator.ts index 05a1598..d919233 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -126,6 +126,18 @@ function generateDefinitionFile( defFile.saveSync(); } +function checkDefinition(paramDefinition: Definition) { + if (paramDefinition) { + return paramDefinition.name; + } + + if (paramDefinition === null) { + return "null"; + } + + return "{}"; +} + export async function generate( parsedWsdl: ParsedWsdl, outDir: string, @@ -217,7 +229,7 @@ export async function generate( parameters: [ { name: camelcase(method.paramName), - type: method.paramDefinition ? method.paramDefinition.name : "{}", + type: checkDefinition(method.paramDefinition), }, { name: "callback", @@ -297,7 +309,7 @@ export async function generate( parameters: [ { name: camelcase(method.paramName), - type: method.paramDefinition ? method.paramDefinition.name : "{}", + type: checkDefinition(method.paramDefinition), }, ], returnType: `Promise<[result: ${ diff --git a/test/resources-public/products.test.ts b/test/resources-public/products.test.ts index cae4d71..95d072f 100644 --- a/test/resources-public/products.test.ts +++ b/test/resources-public/products.test.ts @@ -18,12 +18,12 @@ test(target, async t => { }); t.test(`${target} - check definitions`, async t => { - t.equal(existsSync(`${outdir}/foo/definitions/BankSvcRq.ts`), true); + t.equal(existsSync(`${outdir}/products/definitions/Discount.ts`), true); t.end(); }); t.test(`${target} - compile`, async t => { - await typecheck(`${outdir}/file/index.ts`); + await typecheck(`${outdir}/products/index.ts`); t.end(); });