wsdl-tsclient icon indicating copy to clipboard operation
wsdl-tsclient copied to clipboard

node-soap parsed primitive types do not match

Open nahidakbar opened this issue 2 years ago • 2 comments

The code generator is pretty nice. Probably the only well maintained one in the typescript ecosystem.

Just noticed some type mismatch between generated typescript types and what we get as request out of the node-soap library.

I don't know why and it does not have a comprehensive coverage of primitive types in any shape or form but here are the primitive types node-soap parses:

https://github.com/vpulim/node-soap/blob/master/src/wsdl/index.ts#L439

I've fixed up the issues for my personal use with the following diff:

diff --git a/src/parser.ts b/src/parser.ts
index f830cde..e1fc04b 100644
--- a/src/parser.ts
+++ b/src/parser.ts
@@ -29,6 +29,20 @@ function findReferenceDefiniton(visited: Array<VisitedDefinition>, definitionPar
     return visited.find((def) => def.parts === definitionParts);
 }
 
+const NODE_SOAP_PARSED_TYPES: { [type: string]: string } = {
+    int: "number",
+    integer: "number",
+    short: "number",
+    long: "number",
+    double: "number",
+    float: "number",
+    decimal: "number",
+    bool: "boolean",
+    boolean: "boolean",
+    dateTime: "Date",
+    date: "Date",
+};
+
 /**
  * parse definition
  * @param parsedWsdl context of parsed wsdl
@@ -95,7 +109,7 @@ function parseDefinition(
                             name: stripedPropName,
                             sourceName: propName,
                             description: type,
-                            type: "string",
+                            type: NODE_SOAP_PARSED_TYPES[type] || "string",
                             isArray: true,
                         });
                     } else if (type instanceof ComplexTypeElement) {
@@ -155,7 +169,7 @@ function parseDefinition(
                             name: propName,
                             sourceName: propName,
                             description: type,
-                            type: "string",
+                            type: NODE_SOAP_PARSED_TYPES[type] || "string",
                             isArray: false,
                         });
                     } else if (type instanceof ComplexTypeElement) {

Thought I'd let you know

nahidakbar avatar Oct 22 '22 19:10 nahidakbar

Looks good to me! I would appreciate if this could it make into the code base :-)

cheindl avatar Dec 20 '22 15:12 cheindl

@cheindl https://github.com/dderevjanik/wsdl-tsclient/pull/54

nahidakbar avatar Jan 02 '23 22:01 nahidakbar