@techspokes/typescript-wsdl-client 0.6.2 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -166
- package/dist/cli.js +223 -1
- package/dist/compiler/schemaCompiler.d.ts +54 -0
- package/dist/compiler/schemaCompiler.d.ts.map +1 -1
- package/dist/compiler/schemaCompiler.js +74 -7
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/emit/catalogEmitter.d.ts +18 -0
- package/dist/emit/catalogEmitter.d.ts.map +1 -1
- package/dist/emit/catalogEmitter.js +31 -0
- package/dist/emit/clientEmitter.d.ts +17 -0
- package/dist/emit/clientEmitter.d.ts.map +1 -1
- package/dist/emit/clientEmitter.js +33 -3
- package/dist/emit/typesEmitter.d.ts +16 -5
- package/dist/emit/typesEmitter.d.ts.map +1 -1
- package/dist/emit/typesEmitter.js +30 -5
- package/dist/emit/utilsEmitter.d.ts +18 -0
- package/dist/emit/utilsEmitter.d.ts.map +1 -1
- package/dist/emit/utilsEmitter.js +30 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +36 -1
- package/dist/loader/fetch.d.ts +31 -0
- package/dist/loader/fetch.d.ts.map +1 -1
- package/dist/loader/fetch.js +31 -0
- package/dist/loader/wsdlLoader.d.ts +32 -0
- package/dist/loader/wsdlLoader.d.ts.map +1 -1
- package/dist/loader/wsdlLoader.js +80 -9
- package/dist/openapi/buildPaths.d.ts +74 -0
- package/dist/openapi/buildPaths.d.ts.map +1 -0
- package/dist/openapi/buildPaths.js +66 -0
- package/dist/openapi/buildSchemas.d.ts +44 -0
- package/dist/openapi/buildSchemas.d.ts.map +1 -0
- package/dist/openapi/buildSchemas.js +207 -0
- package/dist/openapi/casing.d.ts +38 -0
- package/dist/openapi/casing.d.ts.map +1 -0
- package/dist/openapi/casing.js +49 -0
- package/dist/openapi/generateOpenAPI.d.ts +57 -0
- package/dist/openapi/generateOpenAPI.d.ts.map +1 -0
- package/dist/openapi/generateOpenAPI.js +174 -0
- package/dist/openapi/security.d.ts +82 -0
- package/dist/openapi/security.d.ts.map +1 -0
- package/dist/openapi/security.js +145 -0
- package/dist/pipeline.d.ts +37 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +72 -0
- package/dist/util/tools.d.ts +100 -7
- package/dist/util/tools.d.ts.map +1 -1
- package/dist/util/tools.js +85 -7
- package/dist/xsd/primitives.d.ts +33 -0
- package/dist/xsd/primitives.d.ts.map +1 -1
- package/dist/xsd/primitives.js +59 -7
- package/package.json +7 -2
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Emits TypeScript interfaces and type aliases from a compiled WSDL catalog
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
5
|
+
* This function generates a TypeScript file containing all the types required to
|
|
6
|
+
* work with the SOAP service, including:
|
|
7
|
+
*
|
|
8
|
+
* - Type aliases for simple types (enums, restrictions, etc.)
|
|
9
|
+
* - Interfaces for complex types with proper inheritance
|
|
10
|
+
* - JSDoc annotations with XML metadata for runtime marshalling
|
|
11
|
+
*
|
|
12
|
+
* Key design decisions:
|
|
13
|
+
* - Text node is modeled as "$value" (not "value") to avoid collisions with real elements
|
|
14
|
+
* - xs:complexType + xs:simpleContent/extension is flattened to `extends <BaseType>`
|
|
15
|
+
* - All properties (attributes and elements) include @xsd JSDoc
|
|
16
|
+
* - If a "$value" element is present, it is emitted last
|
|
17
|
+
*
|
|
18
|
+
* @param {string} outFile - Path to the output TypeScript file
|
|
19
|
+
* @param {CompiledCatalog} compiled - The compiled WSDL catalog
|
|
9
20
|
*/
|
|
10
21
|
export declare function emitTypes(outFile: string, compiled: CompiledCatalog): void;
|
|
11
22
|
//# sourceMappingURL=typesEmitter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typesEmitter.d.ts","sourceRoot":"","sources":["../../src/emit/typesEmitter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"typesEmitter.d.ts","sourceRoot":"","sources":["../../src/emit/typesEmitter.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,eAAe,EAAe,MAAM,+BAA+B,CAAC;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,QAgJnE"}
|
|
@@ -1,11 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript Types Emitter
|
|
3
|
+
*
|
|
4
|
+
* This module is responsible for transforming the compiled WSDL catalog into TypeScript
|
|
5
|
+
* type definitions. It generates interfaces for complex types and type aliases for
|
|
6
|
+
* simple types, handling features such as:
|
|
7
|
+
*
|
|
8
|
+
* - XML attribute flattening (attributes and elements as peer properties)
|
|
9
|
+
* - Text content as "$value" property
|
|
10
|
+
* - Type inheritance (extends) for complexContent extensions
|
|
11
|
+
* - Proper JSDoc annotations for XML metadata
|
|
12
|
+
* - Consistent property ordering and interface structuring
|
|
13
|
+
* - Optional/required markers based on XML schema requirements
|
|
14
|
+
*/
|
|
1
15
|
import fs from "node:fs";
|
|
2
16
|
/**
|
|
3
|
-
*
|
|
17
|
+
* Emits TypeScript interfaces and type aliases from a compiled WSDL catalog
|
|
18
|
+
*
|
|
19
|
+
* This function generates a TypeScript file containing all the types required to
|
|
20
|
+
* work with the SOAP service, including:
|
|
21
|
+
*
|
|
22
|
+
* - Type aliases for simple types (enums, restrictions, etc.)
|
|
23
|
+
* - Interfaces for complex types with proper inheritance
|
|
24
|
+
* - JSDoc annotations with XML metadata for runtime marshalling
|
|
25
|
+
*
|
|
26
|
+
* Key design decisions:
|
|
27
|
+
* - Text node is modeled as "$value" (not "value") to avoid collisions with real elements
|
|
28
|
+
* - xs:complexType + xs:simpleContent/extension is flattened to `extends <BaseType>`
|
|
29
|
+
* - All properties (attributes and elements) include @xsd JSDoc
|
|
30
|
+
* - If a "$value" element is present, it is emitted last
|
|
4
31
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - All properties (attributes and elements) include @xsd JSDoc.
|
|
8
|
-
* - If a "$value" element is present, it is emitted last.
|
|
32
|
+
* @param {string} outFile - Path to the output TypeScript file
|
|
33
|
+
* @param {CompiledCatalog} compiled - The compiled WSDL catalog
|
|
9
34
|
*/
|
|
10
35
|
export function emitTypes(outFile, compiled) {
|
|
11
36
|
const lines = [];
|
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
|
|
2
|
+
/**
|
|
3
|
+
* Emits utility types and constants for XML serialization/deserialization
|
|
4
|
+
*
|
|
5
|
+
* This function generates a TypeScript file containing metadata mappings that help
|
|
6
|
+
* the SOAP client distinguish between XML attributes and child elements during
|
|
7
|
+
* the conversion process. It exports:
|
|
8
|
+
*
|
|
9
|
+
* 1. A DataTypes interface defining the structure of the metadata
|
|
10
|
+
* 2. A constant containing the actual mappings extracted from the compiled catalog
|
|
11
|
+
*
|
|
12
|
+
* The metadata is critical for proper XML marshalling and unmarshalling, as it enables
|
|
13
|
+
* the client to correctly handle XML attributes vs. child elements, maintain type information
|
|
14
|
+
* during recursive processing, and ensure that the XML structure matches the WSDL specification.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} outFile - Path to the output TypeScript file
|
|
17
|
+
* @param {CompiledCatalog} compiled - The compiled WSDL catalog containing metadata
|
|
18
|
+
* @throws {Error} If metadata is missing or has an invalid structure
|
|
19
|
+
*/
|
|
2
20
|
export declare function emitUtils(outFile: string, compiled: CompiledCatalog): void;
|
|
3
21
|
//# sourceMappingURL=utilsEmitter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilsEmitter.d.ts","sourceRoot":"","sources":["../../src/emit/utilsEmitter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utilsEmitter.d.ts","sourceRoot":"","sources":["../../src/emit/utilsEmitter.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAGnE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,QAiCnE"}
|
|
@@ -1,5 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript SOAP Client Utilities Emitter
|
|
3
|
+
*
|
|
4
|
+
* This module generates utility types and constants needed for the TypeScript SOAP client
|
|
5
|
+
* to properly handle XML serialization and deserialization. It creates metadata mappings
|
|
6
|
+
* that enable the client to distinguish between XML attributes and child elements during
|
|
7
|
+
* the conversion process between TypeScript objects and XML.
|
|
8
|
+
*
|
|
9
|
+
* The generated utilities include:
|
|
10
|
+
* - A DataTypes interface defining the structure of the metadata
|
|
11
|
+
* - A constant containing the actual metadata mappings extracted from the compiled catalog
|
|
12
|
+
*/
|
|
1
13
|
import fs from "node:fs";
|
|
2
14
|
import { deriveClientName, pascalToSnakeCase } from "../util/tools.js";
|
|
15
|
+
/**
|
|
16
|
+
* Emits utility types and constants for XML serialization/deserialization
|
|
17
|
+
*
|
|
18
|
+
* This function generates a TypeScript file containing metadata mappings that help
|
|
19
|
+
* the SOAP client distinguish between XML attributes and child elements during
|
|
20
|
+
* the conversion process. It exports:
|
|
21
|
+
*
|
|
22
|
+
* 1. A DataTypes interface defining the structure of the metadata
|
|
23
|
+
* 2. A constant containing the actual mappings extracted from the compiled catalog
|
|
24
|
+
*
|
|
25
|
+
* The metadata is critical for proper XML marshalling and unmarshalling, as it enables
|
|
26
|
+
* the client to correctly handle XML attributes vs. child elements, maintain type information
|
|
27
|
+
* during recursive processing, and ensure that the XML structure matches the WSDL specification.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} outFile - Path to the output TypeScript file
|
|
30
|
+
* @param {CompiledCatalog} compiled - The compiled WSDL catalog containing metadata
|
|
31
|
+
* @throws {Error} If metadata is missing or has an invalid structure
|
|
32
|
+
*/
|
|
3
33
|
export function emitUtils(outFile, compiled) {
|
|
4
34
|
const clientName = deriveClientName(compiled);
|
|
5
35
|
const clientConstant = pascalToSnakeCase(clientName).toUpperCase();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import type { CompilerOptions } from "./config.js";
|
|
2
|
+
export { generateOpenAPI } from "./openapi/generateOpenAPI.js";
|
|
3
|
+
export { runGenerationPipeline } from "./pipeline.js";
|
|
4
|
+
/**
|
|
5
|
+
* Compiles a WSDL file to TypeScript client code
|
|
6
|
+
*
|
|
7
|
+
* This function is the main programmatic entry point for generating TypeScript
|
|
8
|
+
* client code from a WSDL file. It performs the full compilation process:
|
|
9
|
+
*
|
|
10
|
+
* 1. Loading and parsing the WSDL document
|
|
11
|
+
* 2. Compiling the WSDL into a structured catalog
|
|
12
|
+
* 3. Generating TypeScript artifacts (client, types, utilities)
|
|
13
|
+
* 4. Optionally emitting a JSON catalog for introspection
|
|
14
|
+
*
|
|
15
|
+
* The function ensures the output directory exists and handles errors properly.
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} input - Input configuration
|
|
18
|
+
* @param {string} input.wsdl - Path or URL to the WSDL file
|
|
19
|
+
* @param {string} input.outDir - Output directory for generated code
|
|
20
|
+
* @param {CompilerOptions} [input.options] - Optional compiler configuration
|
|
21
|
+
* @returns {Promise<void>}
|
|
22
|
+
* @throws {Error} If no schemas or operations are found, or if compilation fails
|
|
23
|
+
*/
|
|
2
24
|
export declare function compileWsdlToProject(input: {
|
|
3
25
|
wsdl: string;
|
|
4
26
|
outDir: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AASjD,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAC,qBAAqB,EAAC,MAAM,eAAe,CAAC;AAGpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,eAAe,CAAA;CAAE,GACjE,OAAO,CAAC,IAAI,CAAC,CAqDf"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript WSDL Client Generator - API Entry Point
|
|
3
|
+
*
|
|
4
|
+
* This module exports the public API for programmatic usage of the TypeScript WSDL client
|
|
5
|
+
* generator. It provides functions for:
|
|
6
|
+
*
|
|
7
|
+
* 1. Compiling WSDL to TypeScript client code (compileWsdlToProject)
|
|
8
|
+
* 2. Generating OpenAPI specifications from WSDL (generateOpenAPI)
|
|
9
|
+
* 3. Running the full generation pipeline (runGenerationPipeline)
|
|
10
|
+
*
|
|
11
|
+
* These functions provide a way to integrate the generator into other tools and workflows
|
|
12
|
+
* without relying on the command-line interface.
|
|
13
|
+
*/
|
|
1
14
|
import fs from "node:fs";
|
|
2
15
|
import path from "node:path";
|
|
16
|
+
import { TYPESCRIPT_WSDL_CLIENT_DEFAULT_COMPLIER_OPTIONS } from "./config.js";
|
|
3
17
|
import { loadWsdl } from "./loader/wsdlLoader.js";
|
|
4
18
|
import { compileCatalog } from "./compiler/schemaCompiler.js";
|
|
5
19
|
import { emitTypes } from "./emit/typesEmitter.js";
|
|
6
20
|
import { emitUtils } from "./emit/utilsEmitter.js";
|
|
7
21
|
import { emitCatalog } from "./emit/catalogEmitter.js";
|
|
8
22
|
import { emitClient } from "./emit/clientEmitter.js";
|
|
9
|
-
|
|
23
|
+
export { generateOpenAPI } from "./openapi/generateOpenAPI.js";
|
|
24
|
+
export { runGenerationPipeline } from "./pipeline.js";
|
|
10
25
|
// noinspection JSUnusedGlobalSymbols
|
|
26
|
+
/**
|
|
27
|
+
* Compiles a WSDL file to TypeScript client code
|
|
28
|
+
*
|
|
29
|
+
* This function is the main programmatic entry point for generating TypeScript
|
|
30
|
+
* client code from a WSDL file. It performs the full compilation process:
|
|
31
|
+
*
|
|
32
|
+
* 1. Loading and parsing the WSDL document
|
|
33
|
+
* 2. Compiling the WSDL into a structured catalog
|
|
34
|
+
* 3. Generating TypeScript artifacts (client, types, utilities)
|
|
35
|
+
* 4. Optionally emitting a JSON catalog for introspection
|
|
36
|
+
*
|
|
37
|
+
* The function ensures the output directory exists and handles errors properly.
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} input - Input configuration
|
|
40
|
+
* @param {string} input.wsdl - Path or URL to the WSDL file
|
|
41
|
+
* @param {string} input.outDir - Output directory for generated code
|
|
42
|
+
* @param {CompilerOptions} [input.options] - Optional compiler configuration
|
|
43
|
+
* @returns {Promise<void>}
|
|
44
|
+
* @throws {Error} If no schemas or operations are found, or if compilation fails
|
|
45
|
+
*/
|
|
11
46
|
export async function compileWsdlToProject(input) {
|
|
12
47
|
// Merge defaults with overrides, always set wsdl+out
|
|
13
48
|
const finalOptions = {
|
package/dist/loader/fetch.d.ts
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WSDL Document Fetcher
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for fetching WSDL and XSD documents from either
|
|
5
|
+
* HTTP/HTTPS URLs or local file paths. It handles relative paths intelligently by
|
|
6
|
+
* resolving them against a base directory, which is crucial for processing XSD
|
|
7
|
+
* imports and includes with relative paths.
|
|
8
|
+
*
|
|
9
|
+
* The fetcher supports:
|
|
10
|
+
* - HTTP/HTTPS URLs (using the global fetch API)
|
|
11
|
+
* - Absolute file paths
|
|
12
|
+
* - Relative file paths (resolved against an optional base path)
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Fetches text content from a URL or file path
|
|
16
|
+
*
|
|
17
|
+
* This function retrieves the content of a WSDL or XSD document from either
|
|
18
|
+
* a remote URL or a local file path. It handles:
|
|
19
|
+
*
|
|
20
|
+
* - HTTP/HTTPS URLs (using the global fetch API with appropriate XML headers)
|
|
21
|
+
* - Absolute local file paths
|
|
22
|
+
* - Relative paths (resolved against the provided base path)
|
|
23
|
+
*
|
|
24
|
+
* This is a key component for resolving schema imports and includes, which may
|
|
25
|
+
* use relative paths to reference other schema documents.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} urlOrPath - URL or file path to fetch
|
|
28
|
+
* @param {string} [base] - Optional base directory/URL for resolving relative paths
|
|
29
|
+
* @returns {Promise<{uri: string, text: string}>} - Object containing resolved URI and text content
|
|
30
|
+
* @throws {Error} - If HTTP request fails or file cannot be read
|
|
31
|
+
*/
|
|
1
32
|
export declare function fetchText(urlOrPath: string, base?: string): Promise<{
|
|
2
33
|
uri: string;
|
|
3
34
|
text: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/loader/fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/loader/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAcxG"}
|
package/dist/loader/fetch.js
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WSDL Document Fetcher
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for fetching WSDL and XSD documents from either
|
|
5
|
+
* HTTP/HTTPS URLs or local file paths. It handles relative paths intelligently by
|
|
6
|
+
* resolving them against a base directory, which is crucial for processing XSD
|
|
7
|
+
* imports and includes with relative paths.
|
|
8
|
+
*
|
|
9
|
+
* The fetcher supports:
|
|
10
|
+
* - HTTP/HTTPS URLs (using the global fetch API)
|
|
11
|
+
* - Absolute file paths
|
|
12
|
+
* - Relative file paths (resolved against an optional base path)
|
|
13
|
+
*/
|
|
1
14
|
import fs from "node:fs";
|
|
2
15
|
import path from "node:path";
|
|
16
|
+
/**
|
|
17
|
+
* Fetches text content from a URL or file path
|
|
18
|
+
*
|
|
19
|
+
* This function retrieves the content of a WSDL or XSD document from either
|
|
20
|
+
* a remote URL or a local file path. It handles:
|
|
21
|
+
*
|
|
22
|
+
* - HTTP/HTTPS URLs (using the global fetch API with appropriate XML headers)
|
|
23
|
+
* - Absolute local file paths
|
|
24
|
+
* - Relative paths (resolved against the provided base path)
|
|
25
|
+
*
|
|
26
|
+
* This is a key component for resolving schema imports and includes, which may
|
|
27
|
+
* use relative paths to reference other schema documents.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} urlOrPath - URL or file path to fetch
|
|
30
|
+
* @param {string} [base] - Optional base directory/URL for resolving relative paths
|
|
31
|
+
* @returns {Promise<{uri: string, text: string}>} - Object containing resolved URI and text content
|
|
32
|
+
* @throws {Error} - If HTTP request fails or file cannot be read
|
|
33
|
+
*/
|
|
3
34
|
export async function fetchText(urlOrPath, base) {
|
|
4
35
|
let uri = urlOrPath;
|
|
5
36
|
if (base && !/^https?:/i.test(urlOrPath) && !path.isAbsolute(urlOrPath)) {
|
|
@@ -1,14 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a single XSD schema document with its associated context
|
|
3
|
+
*
|
|
4
|
+
* @interface SchemaDoc
|
|
5
|
+
* @property {string} uri - Base directory or URL path of the schema document
|
|
6
|
+
* @property {any} xml - Parsed XML structure of the schema node
|
|
7
|
+
* @property {string} targetNS - Target namespace of the schema
|
|
8
|
+
* @property {Record<string, string>} prefixes - Namespace prefix-to-URI mapping for this schema
|
|
9
|
+
*/
|
|
1
10
|
export type SchemaDoc = {
|
|
2
11
|
uri: string;
|
|
3
12
|
xml: any;
|
|
4
13
|
targetNS: string;
|
|
5
14
|
prefixes: Record<string, string>;
|
|
6
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Complete catalog of WSDL and all associated schemas
|
|
18
|
+
*
|
|
19
|
+
* @interface WsdlCatalog
|
|
20
|
+
* @property {string} wsdlUri - URI/path of the source WSDL document
|
|
21
|
+
* @property {any} wsdlXml - Parsed XML structure of the entire WSDL
|
|
22
|
+
* @property {SchemaDoc[]} schemas - Array of all schema documents (from WSDL and imports)
|
|
23
|
+
* @property {Record<string, string>} prefixMap - Global namespace prefix-to-URI mapping
|
|
24
|
+
*/
|
|
7
25
|
export type WsdlCatalog = {
|
|
8
26
|
wsdlUri: string;
|
|
9
27
|
wsdlXml: any;
|
|
10
28
|
schemas: SchemaDoc[];
|
|
11
29
|
prefixMap: Record<string, string>;
|
|
12
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Loads a WSDL document from a URL or file path and resolves all associated schemas
|
|
33
|
+
*
|
|
34
|
+
* This function:
|
|
35
|
+
* 1. Fetches and parses the WSDL document
|
|
36
|
+
* 2. Extracts namespace information and target namespace
|
|
37
|
+
* 3. Locates schema definitions in the WSDL types section
|
|
38
|
+
* 4. Recursively resolves all schema imports and includes
|
|
39
|
+
* 5. Returns a complete catalog of all schemas for compilation
|
|
40
|
+
*
|
|
41
|
+
* @param {string} wsdlUrlOrPath - URL or file path to the WSDL document
|
|
42
|
+
* @returns {Promise<WsdlCatalog>} - Complete catalog of WSDL and schemas
|
|
43
|
+
* @throws {Error} - If the document is not a valid WSDL 1.1 file
|
|
44
|
+
*/
|
|
13
45
|
export declare function loadWsdl(wsdlUrlOrPath: string): Promise<WsdlCatalog>;
|
|
14
46
|
//# sourceMappingURL=wsdlLoader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wsdlLoader.d.ts","sourceRoot":"","sources":["../../src/loader/wsdlLoader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wsdlLoader.d.ts","sourceRoot":"","sources":["../../src/loader/wsdlLoader.ts"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC,CAAC;AAKF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAqC1E"}
|
|
@@ -1,22 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WSDL Document Loader and Schema Resolver
|
|
3
|
+
*
|
|
4
|
+
* This module handles the loading, parsing, and resolution of WSDL documents and their
|
|
5
|
+
* associated XSD schemas. It supports both local file paths and remote URLs, recursively
|
|
6
|
+
* resolving schema includes and imports to build a complete catalog of all schemas
|
|
7
|
+
* referenced by the WSDL.
|
|
8
|
+
*
|
|
9
|
+
* The loader uses fast-xml-parser for XML parsing and handles namespace prefixes,
|
|
10
|
+
* target namespaces, and schema relationships to prepare a comprehensive representation
|
|
11
|
+
* for the compiler stage.
|
|
12
|
+
*/
|
|
1
13
|
import { XMLParser } from "fast-xml-parser";
|
|
2
14
|
import { fetchText } from "./fetch.js";
|
|
3
15
|
import path from "node:path";
|
|
4
16
|
// noinspection ES6UnusedImports
|
|
5
17
|
import { getChildrenWithLocalName, normalizeArray } from "../util/tools.js";
|
|
18
|
+
// Configure XML parser to preserve attributes with @_ prefix
|
|
6
19
|
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "@_" });
|
|
20
|
+
/**
|
|
21
|
+
* Loads a WSDL document from a URL or file path and resolves all associated schemas
|
|
22
|
+
*
|
|
23
|
+
* This function:
|
|
24
|
+
* 1. Fetches and parses the WSDL document
|
|
25
|
+
* 2. Extracts namespace information and target namespace
|
|
26
|
+
* 3. Locates schema definitions in the WSDL types section
|
|
27
|
+
* 4. Recursively resolves all schema imports and includes
|
|
28
|
+
* 5. Returns a complete catalog of all schemas for compilation
|
|
29
|
+
*
|
|
30
|
+
* @param {string} wsdlUrlOrPath - URL or file path to the WSDL document
|
|
31
|
+
* @returns {Promise<WsdlCatalog>} - Complete catalog of WSDL and schemas
|
|
32
|
+
* @throws {Error} - If the document is not a valid WSDL 1.1 file
|
|
33
|
+
*/
|
|
7
34
|
export async function loadWsdl(wsdlUrlOrPath) {
|
|
35
|
+
// Fetch and parse the WSDL document
|
|
8
36
|
const { uri: wsdlUri, text } = await fetchText(wsdlUrlOrPath);
|
|
9
37
|
const wsdlXml = parser.parse(text);
|
|
38
|
+
// Extract the WSDL definitions node (with or without namespace prefix)
|
|
10
39
|
const defs = wsdlXml["wsdl:definitions"] || wsdlXml["definitions"];
|
|
11
40
|
if (!defs)
|
|
12
41
|
throw new Error("Not a WSDL 1.1 file: missing wsdl:definitions");
|
|
13
|
-
// WSDL
|
|
42
|
+
// Extract namespace prefixes declared at the WSDL level
|
|
14
43
|
const prefixMap = {};
|
|
15
44
|
for (const [k, v] of Object.entries(defs)) {
|
|
16
45
|
if (k.startsWith("@_xmlns:"))
|
|
17
46
|
prefixMap[k.slice(8)] = String(v);
|
|
18
47
|
}
|
|
48
|
+
// Extract target namespace from the WSDL
|
|
19
49
|
const tns = defs["@_targetNamespace"] || "";
|
|
50
|
+
// Locate the types section which contains schema definitions
|
|
20
51
|
const types = defs["wsdl:types"] || defs["types"];
|
|
21
52
|
const schemas = [];
|
|
22
53
|
const visited = new Set(); // de-dupe fetched schema docs by absolute URL/path
|
|
@@ -24,6 +55,7 @@ export async function loadWsdl(wsdlUrlOrPath) {
|
|
|
24
55
|
// Find any <xsd:schema> (prefix-agnostic) directly under wsdl:types
|
|
25
56
|
const rawSchemas = getChildrenWithLocalName(types, "schema");
|
|
26
57
|
const baseDir = path.dirname(wsdlUri);
|
|
58
|
+
// Process each schema node, resolving imports and includes
|
|
27
59
|
for (const s of rawSchemas) {
|
|
28
60
|
const discovered = await resolveSchema(s, baseDir, visited);
|
|
29
61
|
schemas.push(...discovered);
|
|
@@ -32,17 +64,29 @@ export async function loadWsdl(wsdlUrlOrPath) {
|
|
|
32
64
|
console.log(`[wsdl] types->schemas: ${schemas.length}`);
|
|
33
65
|
return { wsdlUri, wsdlXml, schemas, prefixMap: { ...prefixMap, tns } };
|
|
34
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Recursively resolves a schema node and all its imports and includes
|
|
69
|
+
*
|
|
70
|
+
* This function processes a schema node, extracts its namespace information,
|
|
71
|
+
* and recursively fetches and resolves any imported or included schemas.
|
|
72
|
+
*
|
|
73
|
+
* @param {any} schemaNode - The XML schema node to process
|
|
74
|
+
* @param {string} baseDir - Base directory/URL for resolving relative paths
|
|
75
|
+
* @param {Set<string>} visited - Set of already processed schema URIs to prevent cycles
|
|
76
|
+
* @returns {Promise<SchemaDoc[]>} - Array of resolved schema documents
|
|
77
|
+
*/
|
|
35
78
|
async function resolveSchema(schemaNode, baseDir, visited) {
|
|
36
79
|
const out = [];
|
|
80
|
+
// Extract target namespace and prefix declarations
|
|
37
81
|
const targetNS = schemaNode["@_targetNamespace"] || "";
|
|
38
82
|
const prefixes = {};
|
|
39
83
|
for (const [k, v] of Object.entries(schemaNode)) {
|
|
40
84
|
if (k.startsWith("@_xmlns:"))
|
|
41
85
|
prefixes[k.slice(8)] = String(v);
|
|
42
86
|
}
|
|
43
|
-
//
|
|
87
|
+
// Add this schema to the output collection
|
|
44
88
|
out.push({ uri: baseDir, xml: schemaNode, targetNS, prefixes });
|
|
45
|
-
//
|
|
89
|
+
// Process <include> elements (schemas from same namespace)
|
|
46
90
|
for (const inc of getChildrenWithLocalName(schemaNode, "include")) {
|
|
47
91
|
const loc = inc?.["@_schemaLocation"];
|
|
48
92
|
if (!loc)
|
|
@@ -50,6 +94,7 @@ async function resolveSchema(schemaNode, baseDir, visited) {
|
|
|
50
94
|
const more = await fetchAndResolveSchemaDoc(loc, baseDir, visited);
|
|
51
95
|
out.push(...more);
|
|
52
96
|
}
|
|
97
|
+
// Process <import> elements (schemas from different namespaces)
|
|
53
98
|
for (const imp of getChildrenWithLocalName(schemaNode, "import")) {
|
|
54
99
|
const loc = imp?.["@_schemaLocation"];
|
|
55
100
|
if (!loc)
|
|
@@ -59,30 +104,56 @@ async function resolveSchema(schemaNode, baseDir, visited) {
|
|
|
59
104
|
}
|
|
60
105
|
return out;
|
|
61
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Fetches and resolves an external schema document
|
|
109
|
+
*
|
|
110
|
+
* This function fetches an external schema document from a URL or file path,
|
|
111
|
+
* parses it, and recursively resolves any imports or includes it contains.
|
|
112
|
+
*
|
|
113
|
+
* @param {string} schemaLocation - URL or file path to the schema document
|
|
114
|
+
* @param {string} baseDir - Base directory/URL for resolving relative paths
|
|
115
|
+
* @param {Set<string>} visited - Set of already processed schema URIs to prevent cycles
|
|
116
|
+
* @returns {Promise<SchemaDoc[]>} - Array of resolved schema documents
|
|
117
|
+
*/
|
|
62
118
|
async function fetchAndResolveSchemaDoc(schemaLocation, baseDir, visited) {
|
|
119
|
+
// Fetch and parse the schema document
|
|
63
120
|
const { uri, text } = await fetchText(schemaLocation, baseDir);
|
|
64
121
|
const docKey = uri;
|
|
122
|
+
// Skip if already processed to prevent infinite recursion
|
|
65
123
|
if (visited.has(docKey))
|
|
66
124
|
return [];
|
|
67
125
|
visited.add(docKey);
|
|
68
126
|
const sx = parser.parse(text);
|
|
69
|
-
// The fetched document may contain one or more <schema> nodes at the root (prefix-agnostic)
|
|
127
|
+
// The fetched document may contain one or more <schema> nodes at the root (prefix-agnostic)
|
|
70
128
|
const roots = getChildrenWithLocalName(sx, "schema");
|
|
71
129
|
const docs = [];
|
|
130
|
+
// Process each schema node in the document
|
|
72
131
|
for (const sn of roots) {
|
|
132
|
+
// Extract target namespace and prefix declarations
|
|
73
133
|
const tns = sn["@_targetNamespace"] || "";
|
|
74
134
|
const prefixes = {};
|
|
75
135
|
for (const [k, v] of Object.entries(sn)) {
|
|
76
136
|
if (k.startsWith("@_xmlns:"))
|
|
77
137
|
prefixes[k.slice(8)] = String(v);
|
|
78
138
|
}
|
|
139
|
+
// Add this schema to the output collection
|
|
79
140
|
const thisDir = path.dirname(uri);
|
|
80
141
|
docs.push({ uri: thisDir, xml: sn, targetNS: tns, prefixes });
|
|
81
|
-
//
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
142
|
+
// Recursively process any imports and includes
|
|
143
|
+
for (const inc of getChildrenWithLocalName(sn, "include")) {
|
|
144
|
+
const loc = inc?.["@_schemaLocation"];
|
|
145
|
+
if (!loc)
|
|
146
|
+
continue;
|
|
147
|
+
const more = await fetchAndResolveSchemaDoc(loc, thisDir, visited);
|
|
148
|
+
docs.push(...more);
|
|
149
|
+
}
|
|
150
|
+
for (const imp of getChildrenWithLocalName(sn, "import")) {
|
|
151
|
+
const loc = imp?.["@_schemaLocation"];
|
|
152
|
+
if (!loc)
|
|
153
|
+
continue;
|
|
154
|
+
const more = await fetchAndResolveSchemaDoc(loc, thisDir, visited);
|
|
155
|
+
docs.push(...more);
|
|
156
|
+
}
|
|
86
157
|
}
|
|
87
158
|
return docs;
|
|
88
159
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAPI Paths Builder
|
|
3
|
+
*
|
|
4
|
+
* This module transforms WSDL operations into OpenAPI 3.1 paths and operations.
|
|
5
|
+
* It bridges the gap between SOAP's operation-centric model and REST's resource-oriented
|
|
6
|
+
* approach by mapping each SOAP operation to a corresponding REST endpoint.
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Converts WSDL operations to RESTful paths with configurable styles
|
|
10
|
+
* - Supports operation-specific overrides for methods, descriptions, etc.
|
|
11
|
+
* - Handles security requirements and header parameters
|
|
12
|
+
* - Organizes operations into tags for better API documentation
|
|
13
|
+
* - Properly links request/response schemas to the components section
|
|
14
|
+
*/
|
|
15
|
+
import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
|
|
16
|
+
import type { PathStyle } from "./casing.js";
|
|
17
|
+
/**
|
|
18
|
+
* Schema for operation overrides file
|
|
19
|
+
*
|
|
20
|
+
* This interface defines the structure of the optional JSON file that can
|
|
21
|
+
* provide operation-specific overrides for method, deprecation status,
|
|
22
|
+
* and documentation.
|
|
23
|
+
*
|
|
24
|
+
* @interface OpsOverridesFile
|
|
25
|
+
* @property {string} [method] - HTTP method to use (post, get, put, patch, delete)
|
|
26
|
+
* @property {boolean} [deprecated] - Whether to mark the operation as deprecated
|
|
27
|
+
* @property {string} [summary] - Short summary for the operation
|
|
28
|
+
* @property {string} [description] - Detailed description for the operation
|
|
29
|
+
*/
|
|
30
|
+
export interface OpsOverridesFile {
|
|
31
|
+
[opName: string]: {
|
|
32
|
+
method?: string;
|
|
33
|
+
deprecated?: boolean;
|
|
34
|
+
summary?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Schema for operation to tag mapping file
|
|
40
|
+
*
|
|
41
|
+
* This interface defines the structure of the optional JSON file that maps
|
|
42
|
+
* operation names to tags for better organization in the OpenAPI specification.
|
|
43
|
+
*
|
|
44
|
+
* @interface TagsMappingFile
|
|
45
|
+
* @property {string} string Tag name to assign to the operation
|
|
46
|
+
*/
|
|
47
|
+
export interface TagsMappingFile {
|
|
48
|
+
[opName: string]: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Options for building OpenAPI paths
|
|
52
|
+
*
|
|
53
|
+
* @interface BuildPathsOptions
|
|
54
|
+
* @property {string} [basePath] - Base path prefix for all operations (e.g., /v1/soap)
|
|
55
|
+
* @property {PathStyle} pathStyle - Style for converting operation names to path segments
|
|
56
|
+
* @property {string} defaultMethod - Default HTTP method for operations
|
|
57
|
+
* @property {TagsMappingFile} [tagsMap] - Mapping of operation names to tags
|
|
58
|
+
* @property {OpsOverridesFile} [overrides] - Operation-specific overrides
|
|
59
|
+
* @property {string} defaultTag - Default tag for operations without explicit tags
|
|
60
|
+
* @property {Record<string, any[]>} opSecurity - Operation-specific security requirements
|
|
61
|
+
* @property {Record<string, string[]>} opHeaderParameters - Operation-specific header parameters
|
|
62
|
+
*/
|
|
63
|
+
export interface BuildPathsOptions {
|
|
64
|
+
basePath?: string;
|
|
65
|
+
pathStyle: PathStyle;
|
|
66
|
+
defaultMethod: string;
|
|
67
|
+
tagsMap?: TagsMappingFile;
|
|
68
|
+
overrides?: OpsOverridesFile;
|
|
69
|
+
defaultTag: string;
|
|
70
|
+
opSecurity: Record<string, any[] | undefined>;
|
|
71
|
+
opHeaderParameters: Record<string, string[]>;
|
|
72
|
+
}
|
|
73
|
+
export declare function buildPaths(compiled: CompiledCatalog, opts: BuildPathsOptions): Record<string, any>;
|
|
74
|
+
//# sourceMappingURL=buildPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPaths.d.ts","sourceRoot":"","sources":["../../src/openapi/buildPaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAG3C;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB;IAC/B,CAAC,MAAM,EAAE,MAAM,GAAG;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAE9B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,SAAS,CAAC,CAAC;IAC9C,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAC9C;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,iBAAiB,uBAyD5E"}
|