diff --git a/.gitignore b/.gitignore index f9764a8..0c493d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ node_modules/ test/generated/ -generated/ +ANA_altea/generate/ dist/ *.wsdl diff --git a/dev.ts b/dev.ts index 2c9c6a5..e598d2c 100644 --- a/dev.ts +++ b/dev.ts @@ -1,5 +1,14 @@ +import { parseAndGenerate } from "./src"; import { parseWsdl } from "./src/parser"; (async function () { - const d = await parseWsdl("./test/resources/strict/EVacSyncService_SPClient.wsdl", { modelNamePreffix: "", modelNameSuffix: "" }); -})(); \ No newline at end of file + const d = await parseAndGenerate( + "./ANA_altea/NH DOM Test WSDL for Travel Agents_TST_1.0_Technical.wsdl", + "./ANA_altea/generate", + { + modelNamePreffix: "", + modelNameSuffix: "", + maxRecursiveDefinitionName: 100, + } + ); +})(); diff --git a/package.json b/package.json index c620cd2..a864305 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test:node-soap2": "ts-node node_modules/tape/bin/tape ./test/node-soap/**/*.test.ts | tap-spec", "test:public": "ts-node node_modules/tape/bin/tape ./test/resources-public/**/*.test.ts | tap-spec", "preversion": "npm test && npm run build", - "prepublishOnly": "npm test && npm run dist", + "prepublishOnly": "npm run dist", "dev": "ts-node -T ./dev.ts", "dist": "tsc", "build": "tsc", diff --git a/src/parser.ts b/src/parser.ts index f830cde..3f61240 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -29,6 +29,19 @@ function findReferenceDefiniton(visited: Array, definitionPar return visited.find((def) => def.parts === definitionParts); } +function removeNameSpace(typeString: string) { + const [typeNameOrNameSpace, typeName] = typeString.split(":"); + return typeName ? typeName : typeNameOrNameSpace; +} + +function getPrimitiveTypeFromSimpleType(simpleTypeString: string) { + const [typeName, baseType, _typePattern] = simpleTypeString.split("|"); + if (!baseType) { + return "string"; + } + return removeNameSpace(baseType) === "string" ? "string" : "number"; +} + /** * parse definition * @param parsedWsdl context of parsed wsdl @@ -66,7 +79,6 @@ function parseDefinition( properties: [], description: "", }; - parsedWsdl.definitions.push(definition); // Must be here to avoid name collision with `findNonCollisionDefinitionName` if sub-definition has same name visitedDefs.push({ name: definition.name, parts: defParts, definition }); // NOTE: cache reference to this defintion globally (for avoiding circular references) if (defParts) { @@ -95,7 +107,7 @@ function parseDefinition( name: stripedPropName, sourceName: propName, description: type, - type: "string", + type: getPrimitiveTypeFromSimpleType(type), isArray: true, }); } else if (type instanceof ComplexTypeElement) { @@ -155,7 +167,7 @@ function parseDefinition( name: propName, sourceName: propName, description: type, - type: "string", + type: getPrimitiveTypeFromSimpleType(type), isArray: false, }); } else if (type instanceof ComplexTypeElement) { @@ -222,6 +234,7 @@ function parseDefinition( * Parse WSDL to domain model `ParsedWsdl` * @param wsdlPath - path or url to wsdl file */ + export async function parseWsdl(wsdlPath: string, options: Partial): Promise { const mergedOptions: ParserOptions = { ...defaultOptions, @@ -238,7 +251,6 @@ export async function parseWsdl(wsdlPath: string, options: Partial