diff --git a/src/generator.ts b/src/generator.ts index 6019f46..504f2dc 100644 --- a/src/generator.ts +++ b/src/generator.ts @@ -85,7 +85,10 @@ function generateDefinitionFile( // Wasn't generated yet generateDefinitionFile(project, prop.ref, defDir, [...stack, prop.ref.name], generated); } - addSafeImport(definitionImports, `./${prop.ref.name}`, prop.ref.name); + // If a property is of the same type as its parent type, don't add import + if(prop.ref.name !== definition.name) { + addSafeImport(definitionImports, `./${prop.ref.name}`, prop.ref.name); + } definitionProperties.push(createProperty(prop.name, prop.ref.name, prop.sourceName, prop.isArray)); } } diff --git a/test/node-soap/self_recursive.test.ts b/test/node-soap/self_recursive.test.ts new file mode 100644 index 0000000..e058bdb --- /dev/null +++ b/test/node-soap/self_recursive.test.ts @@ -0,0 +1,26 @@ +import test from "tape"; +import { existsSync } from "fs"; +import { parseAndGenerate } from "../../src"; +import { Logger } from "../../src/utils/logger"; + +const target = "self_recursive"; + +test(target, async t => { + Logger.disabled(); + + const input = `./test/resources/${target}.wsdl`; + const outdir = "./test/generated"; + + t.test(`${target} - generate wsdl client`, async t => { + await parseAndGenerate(input, outdir); + t.end(); + }); + + t.test(`${target} - check definitions`, async t => { + t.equal(existsSync(`${outdir}/selfrecursive/definitions/GetPerson.ts`), true); + t.equal(existsSync(`${outdir}/selfrecursive/definitions/GetPersonResponse.ts`), true); + t.equal(existsSync(`${outdir}/selfrecursive/definitions/Person.ts`), true); + t.equal(existsSync(`${outdir}/selfrecursive/definitions/Request.ts`), true); + t.end(); + }); +}); \ No newline at end of file diff --git a/test/resources/self_recursive.wsdl b/test/resources/self_recursive.wsdl new file mode 100644 index 0000000..ea36942 --- /dev/null +++ b/test/resources/self_recursive.wsdl @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +