Generate TypeScript clients and types from WSDL definitions.
npm install @univa.tech/wsdl2tsThis tool generates TypeScript type definitions and SOAP clients from WSDL files. Internally it parses WSDL with fast-xml-parser and constructs/prints TypeScript ASTs using ts-morph.
``bash`
npm i @univa.tech/wsdl2ts
`ts
import { generateFromWsdl } from "wsdl2ts"
await generateFromWsdl({
wsdlPaths: [
"./path/to/foo.wsdl",
"./path/to/bar.wsdl",
],
outDir: "./generated",
esm: true, // defaults to true; set to false to emit CJS-compatible imports without extensions
})
`
- wsdlPaths can mix file and directory paths. Directories are scanned recursively.outDir
- -- The generated files are placed at outDir.esm
- -- defaults to true; set to false to emit CJS-compatible imports without extensions
- types/client.ts`
- Declares the shared factory signature once for the entire output:
ts
import type { Client, IOptions } from "@univa.tech/soap"
export type SoapClientFactory = (
wsdlFileName: string,
options?: IOptions,
) => Promise
`
- ServiceClient
- Emits a single interface that aggregates every operation across all portType definitions in the WSDL.Promise<[result, rawResponse, soapHeader, rawRequest]>
- Each operation produces both callback and Promise-based overloads. Promise variants still resolve to .Void
- Empty request messages reference the shared type and remain required parameters (args: Void).createClientAsync
- Provides a helper that uses the shared SoapClientFactory to create strongly typed clients:`
ts
export interface ServiceClient extends Client {
doSomething(args: FooParam, callback: ..., options?: unknown, extraHeaders?: Record
doSomethingAsync(args: FooParam, options?: unknown, extraHeaders?: Record
}
export function createClientAsync(
factory: SoapClientFactory,
options?: IOptions,
): Promise
return factory("foo", options) as Promise
}
`types/
- interface
- TypeScript definitions for each message and complex typetypes/
- Message request/response shapes (and the elements/types referenced directly from their parts) are emitted under types/
- Shared complex types that are not tied to a specific message remain directly under ExamplePort.ExampleRequest
- Message bound request/response interfaces reuse the referenced complex type name and are wrapped in a namespace matching the port (e.g. )Void
- Multi-part message wrappers keep a port-prefixed alias to avoid collisions
- Empty complex types are replaced with , limited to types directly under messagestypes/index.ts
- re-exports every file within the directory (per WSDL and for shared types) and includes the shared client.ts barrel
- client.ts
- Re-exports the WSDL specific and types/index.tsindex.ts
- export * as Sample from './sample/index.js'
- Re-exports each WSDL namespace (e.g. ) and the shared types/index.ts / types/client.ts`
When processing multiple WSDLs, the generator verifies that types with the same namespace and name share the exact structure. Any differences abort generation and the log states which WSDLs conflicted.