dderevjanik / wsdl-tsclient

:page_facing_up: Generate typescript client from WSDL
https://npm.im/wsdl-tsclient
MIT License
97 stars 71 forks source link

node-soap parsed primitive types do not match #48

Open nahidakbar opened 1 year ago

nahidakbar commented 1 year ago

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

cheindl commented 1 year ago

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

nahidakbar commented 1 year ago

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