@univa.tech/wsdl2ts
v0.1.12
Published
Generate TypeScript clients and types from WSDL definitions.
Readme
wsdl2ts
This 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.
Installation
npm i @univa.tech/wsdl2tsUsage
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
})wsdlPathscan mix file and directory paths. Directories are scanned recursively.outDir-- The generated files are placed atoutDir.esm-- defaults to true; set to false to emit CJS-compatible imports without extensions
Generated Output
types/client.ts- Declares the shared factory signature once for the entire output:
import type { Client, IOptions } from "@univa.tech/soap" export type SoapClientFactory = ( wsdlFileName: string, options?: IOptions, ) => Promise<Client>
- Declares the shared factory signature once for the entire output:
<wsdlFileName>/client.ts- Emits a single
ServiceClientinterface that aggregates every operation across allportTypedefinitions in the WSDL. - Each operation produces both callback and Promise-based overloads. Promise variants still resolve to
Promise<[result, rawResponse, soapHeader, rawRequest]>. - Empty request messages reference the shared
Voidtype and remain required parameters (args: Void). - Provides a
createClientAsynchelper that uses the sharedSoapClientFactoryto create strongly typed clients:export interface ServiceClient extends Client { doSomething(args: FooParam, callback: ..., options?: unknown, extraHeaders?: Record<string, unknown>): void doSomethingAsync(args: FooParam, options?: unknown, extraHeaders?: Record<string, unknown>): Promise<[result: FooResponse, ...]> } export function createClientAsync( factory: SoapClientFactory, options?: IOptions, ): Promise<ServiceClient> { return factory("foo", options) as Promise<ServiceClient> }
- Emits a single
types/- TypeScript
interfacedefinitions for each message and complex type - Message request/response shapes (and the elements/types referenced directly from their parts) are emitted under
types/<wsdlFileName>/ - Shared complex types that are not tied to a specific message remain directly under
types/ - Message bound request/response interfaces reuse the referenced complex type name and are wrapped in a namespace matching the port (e.g.
ExamplePort.ExampleRequest) - Multi-part message wrappers keep a port-prefixed alias to avoid collisions
- Empty complex types are replaced with
Void, limited to types directly under messages types/index.tsre-exports every file within the directory (per WSDL and for shared types) and includes the sharedclient.tsbarrel
- TypeScript
<wsdlFileName>/index.ts- Re-exports the WSDL specific
client.tsandtypes/index.ts
- Re-exports the WSDL specific
index.ts- Re-exports each WSDL namespace (e.g.
export * as Sample from './sample/index.js') and the sharedtypes/index.ts/types/client.ts
- Re-exports each WSDL namespace (e.g.
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.
