openapi-class-transformer 1.0.23 → 1.1.2

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.
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("reflect-metadata");
4
+ //# sourceMappingURL=setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/test-utils/setup.ts"],"names":[],"mappings":";;AAAA,4BAA0B"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Export style options
3
+ */
4
+ export type ExportStyle = 'namespace' | 'direct' | 'both';
5
+ /**
6
+ * Options for export generation
7
+ */
8
+ export interface ExportOptions {
9
+ style: ExportStyle;
10
+ skipJsExtensions: boolean;
11
+ }
12
+ /**
13
+ * Extract all exported class names from a TypeScript file
14
+ * @param filePath Path to the TypeScript file
15
+ * @returns Array of exported class names
16
+ */
17
+ export declare function extractClassNames(filePath: string): string[];
18
+ /**
19
+ * Walk directory and collect all classes from .ts files
20
+ * @param directory Directory to scan
21
+ * @returns Map of file paths to their exported class names
22
+ */
23
+ export declare function extractAllClassNames(directory: string): Map<string, string[]>;
24
+ /**
25
+ * Generate export statement(s) based on export style
26
+ * @param identifier Module identifier (e.g., 'app_project', 'v1alpha1')
27
+ * @param relativePath Relative path to module (e.g., './app-project/index')
28
+ * @param classNames Array of class names to export (for direct/both modes)
29
+ * @param options Export options
30
+ * @returns Array of export statements
31
+ */
32
+ export declare function generateExportStatements(identifier: string, relativePath: string, classNames: string[], options: ExportOptions): string[];
33
+ /**
34
+ * Compute relative path from one directory to a file
35
+ * @param fromDir Source directory (where the import is)
36
+ * @param toFile Target file path
37
+ * @returns Relative path with forward slashes and ./ prefix
38
+ */
39
+ export declare function computeRelativePath(fromDir: string, toFile: string): string;
40
+ /**
41
+ * Generate direct export statements for all models in a directory
42
+ * @param modelsDir Path to models directory
43
+ * @param fromDir Directory where the index file will be located
44
+ * @param options Export options
45
+ * @returns Array of export statements
46
+ */
47
+ export declare function generateDirectModelExports(modelsDir: string, fromDir: string, options: ExportOptions): string[];
48
+ //# sourceMappingURL=export-style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-style.d.ts","sourceRoot":"","sources":["../../src/utils/export-style.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAe5D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CA0B7E;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAAE,EACpB,OAAO,EAAE,aAAa,GACrB,MAAM,EAAE,CA6BV;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3E;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,GACrB,MAAM,EAAE,CAcV"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.extractClassNames = extractClassNames;
37
+ exports.extractAllClassNames = extractAllClassNames;
38
+ exports.generateExportStatements = generateExportStatements;
39
+ exports.computeRelativePath = computeRelativePath;
40
+ exports.generateDirectModelExports = generateDirectModelExports;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ /**
44
+ * Extract all exported class names from a TypeScript file
45
+ * @param filePath Path to the TypeScript file
46
+ * @returns Array of exported class names
47
+ */
48
+ function extractClassNames(filePath) {
49
+ if (!fs.existsSync(filePath)) {
50
+ return [];
51
+ }
52
+ const content = fs.readFileSync(filePath, 'utf-8');
53
+ const classRegex = /export\s+class\s+(\w+)/g;
54
+ const classNames = [];
55
+ let match;
56
+ while ((match = classRegex.exec(content)) !== null) {
57
+ classNames.push(match[1]);
58
+ }
59
+ return classNames;
60
+ }
61
+ /**
62
+ * Walk directory and collect all classes from .ts files
63
+ * @param directory Directory to scan
64
+ * @returns Map of file paths to their exported class names
65
+ */
66
+ function extractAllClassNames(directory) {
67
+ const classMap = new Map();
68
+ if (!fs.existsSync(directory)) {
69
+ return classMap;
70
+ }
71
+ function walkDir(dir) {
72
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
73
+ for (const entry of entries) {
74
+ const fullPath = path.join(dir, entry.name);
75
+ if (entry.isDirectory()) {
76
+ walkDir(fullPath);
77
+ }
78
+ else if (entry.isFile() && entry.name.endsWith('.ts') && entry.name !== 'index.ts') {
79
+ const classNames = extractClassNames(fullPath);
80
+ if (classNames.length > 0) {
81
+ classMap.set(fullPath, classNames);
82
+ }
83
+ }
84
+ }
85
+ }
86
+ walkDir(directory);
87
+ return classMap;
88
+ }
89
+ /**
90
+ * Generate export statement(s) based on export style
91
+ * @param identifier Module identifier (e.g., 'app_project', 'v1alpha1')
92
+ * @param relativePath Relative path to module (e.g., './app-project/index')
93
+ * @param classNames Array of class names to export (for direct/both modes)
94
+ * @param options Export options
95
+ * @returns Array of export statements
96
+ */
97
+ function generateExportStatements(identifier, relativePath, classNames, options) {
98
+ const extension = options.skipJsExtensions ? '' : '.js';
99
+ const fullPath = `${relativePath}${extension}`;
100
+ const exports = [];
101
+ switch (options.style) {
102
+ case 'namespace':
103
+ exports.push(`export * as ${identifier} from '${fullPath}';`);
104
+ break;
105
+ case 'direct':
106
+ if (classNames.length > 0) {
107
+ const names = classNames.join(', ');
108
+ exports.push(`export { ${names} } from '${fullPath}';`);
109
+ }
110
+ break;
111
+ case 'both':
112
+ // Namespace export first
113
+ exports.push(`export * as ${identifier} from '${fullPath}';`);
114
+ // Then direct export if there are classes
115
+ if (classNames.length > 0) {
116
+ const names = classNames.join(', ');
117
+ exports.push(`export { ${names} } from '${fullPath}';`);
118
+ }
119
+ break;
120
+ }
121
+ return exports;
122
+ }
123
+ /**
124
+ * Compute relative path from one directory to a file
125
+ * @param fromDir Source directory (where the import is)
126
+ * @param toFile Target file path
127
+ * @returns Relative path with forward slashes and ./ prefix
128
+ */
129
+ function computeRelativePath(fromDir, toFile) {
130
+ const relativePath = path
131
+ .relative(fromDir, toFile)
132
+ .replace(/\.ts$/, '') // Remove .ts extension
133
+ .replace(/\\/g, '/'); // Normalize to forward slashes
134
+ return `./${relativePath}`;
135
+ }
136
+ /**
137
+ * Generate direct export statements for all models in a directory
138
+ * @param modelsDir Path to models directory
139
+ * @param fromDir Directory where the index file will be located
140
+ * @param options Export options
141
+ * @returns Array of export statements
142
+ */
143
+ function generateDirectModelExports(modelsDir, fromDir, options) {
144
+ const classMap = extractAllClassNames(modelsDir);
145
+ const exports = [];
146
+ const extension = options.skipJsExtensions ? '' : '.js';
147
+ for (const [filePath, classNames] of classMap.entries()) {
148
+ if (classNames.length > 0) {
149
+ const relativePath = computeRelativePath(fromDir, filePath);
150
+ const names = classNames.join(', ');
151
+ exports.push(`export { ${names} } from '${relativePath}${extension}';`);
152
+ }
153
+ }
154
+ return exports;
155
+ }
156
+ //# sourceMappingURL=export-style.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export-style.js","sourceRoot":"","sources":["../../src/utils/export-style.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,8CAeC;AAOD,oDA0BC;AAUD,4DAkCC;AAQD,kDAOC;AASD,gEAkBC;AA3JD,uCAAyB;AACzB,2CAA6B;AAe7B;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,QAAgB;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,yBAAyB,CAAC;IAC7C,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,IAAI,KAAK,CAAC;IACV,OAAO,CAAC,KAAK,GAAG,UAAU,CAAC,IAAI,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,GAAG,CAAC,CAAC,CAAG,+BAA+B;IAEzD,OAAO,KAAK,YAAY,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACxC,SAAiB,EACjB,OAAe,EACf,OAAsB;IAEtB,MAAM,QAAQ,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAExD,KAAK,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QACxD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,MAAM,YAAY,GAAG,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YAC5D,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpC,OAAO,CAAC,IAAI,CAAC,YAAY,KAAK,YAAY,YAAY,GAAG,SAAS,IAAI,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-class-transformer",
3
- "version": "1.0.23",
3
+ "version": "1.1.2",
4
4
  "description": "Generate class-transformer compatible TypeScript classes from OpenAPI specs with full decorator support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -41,11 +41,21 @@
41
41
  "class-transformer": "^0.5.1",
42
42
  "commander": "^12.0.0"
43
43
  },
44
+ "peerDependencies": {
45
+ "class-validator": "^0.14.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "class-validator": {
49
+ "optional": true
50
+ }
51
+ },
44
52
  "devDependencies": {
45
53
  "@jest/globals": "^29.7.0",
46
54
  "@types/jest": "^29.5.14",
47
55
  "@types/node": "^22.10.2",
56
+ "class-validator": "^0.14.3",
48
57
  "jest": "^29.7.0",
58
+ "reflect-metadata": "^0.2.2",
49
59
  "ts-jest": "^29.2.5",
50
60
  "ts-node": "^10.9.2",
51
61
  "typescript": "^5.7.2"