swagger-typescript-api 13.2.5 → 13.2.7
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/CHANGELOG.md +12 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/lib.cjs +1 -1
- package/dist/lib.d.cts +5 -10
- package/dist/lib.d.ts +5 -11
- package/dist/lib.js +1 -1
- package/dist/{src-DW0ilIpJ.js → src-BgBqKQNC.js} +83 -72
- package/dist/src-BgBqKQNC.js.map +1 -0
- package/dist/{src-B15eFEWm.cjs → src-DYNtMxii.cjs} +13 -9
- package/dist/src-DYNtMxii.cjs.map +1 -0
- package/package.json +3 -3
- package/templates/base/data-contract-jsdoc.ejs +1 -1
- package/dist/src-B15eFEWm.cjs.map +0 -1
- package/dist/src-DW0ilIpJ.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# swagger-typescript-api
|
|
2
2
|
|
|
3
|
+
## 13.2.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1308](https://github.com/acacode/swagger-typescript-api/pull/1308) [`36fc899`](https://github.com/acacode/swagger-typescript-api/commit/36fc899c9078e9df55ef97dfb83cbf654914fd7a) Thanks [@js2me](https://github.com/js2me)! - add missing required state for query param with $ref
|
|
8
|
+
|
|
9
|
+
## 13.2.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1306](https://github.com/acacode/swagger-typescript-api/pull/1306) [`fe125cb`](https://github.com/acacode/swagger-typescript-api/commit/fe125cb6820621447f2cbf35c8bc0604fcc466dd) Thanks [@js2me](https://github.com/js2me)! - better extracting description for request body extacting types
|
|
14
|
+
|
|
3
15
|
## 13.2.5
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const require_src = require('./src-
|
|
2
|
+
const require_src = require('./src-DYNtMxii.cjs');
|
|
3
3
|
const node_path = require_src.__toESM(require("node:path"));
|
|
4
4
|
const c12 = require_src.__toESM(require("c12"));
|
|
5
5
|
const citty = require_src.__toESM(require("citty"));
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { CodeGenConfig, HTTP_CLIENT, TemplatesGenConfig, generateApi, generateTemplates, package_default } from "./src-
|
|
2
|
+
import { CodeGenConfig, HTTP_CLIENT, TemplatesGenConfig, generateApi, generateTemplates, package_default } from "./src-BgBqKQNC.js";
|
|
3
3
|
import * as path$1 from "node:path";
|
|
4
4
|
import { loadConfig } from "c12";
|
|
5
5
|
import { defineCommand, runMain } from "citty";
|
package/dist/lib.cjs
CHANGED
package/dist/lib.d.cts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { OpenAPI } from "openapi-types";
|
|
2
|
+
import * as typescript$1 from "typescript";
|
|
2
3
|
import * as typescript from "typescript";
|
|
3
4
|
import * as lodash19 from "lodash";
|
|
5
|
+
import * as lodash14 from "lodash";
|
|
4
6
|
import lodash from "lodash";
|
|
5
7
|
import * as swagger_schema_official16 from "swagger-schema-official";
|
|
6
8
|
import * as eta20 from "eta";
|
|
@@ -339,14 +341,7 @@ declare class SchemaRoutes {
|
|
|
339
341
|
};
|
|
340
342
|
};
|
|
341
343
|
convertRouteParamsIntoObject: (params: any) => any;
|
|
342
|
-
getRequestBodyInfo: (routeInfo: any, routeParams: any, parsedSchemas: any, routeName: any) =>
|
|
343
|
-
paramName: any;
|
|
344
|
-
contentTypes: any[];
|
|
345
|
-
contentKind: string;
|
|
346
|
-
schema: any;
|
|
347
|
-
type: any;
|
|
348
|
-
required: any;
|
|
349
|
-
};
|
|
344
|
+
getRequestBodyInfo: (routeInfo: any, routeParams: any, parsedSchemas: any, routeName: any) => any;
|
|
350
345
|
createRequestParamsSchema: ({
|
|
351
346
|
queryParams,
|
|
352
347
|
queryObjectSchema,
|
|
@@ -386,7 +381,7 @@ declare class JavascriptTranslator extends Translator {
|
|
|
386
381
|
compileTSCode: (input: TranslatorIO) => Record<string, string>;
|
|
387
382
|
translate: (input: any) => Promise<{
|
|
388
383
|
fileName: any;
|
|
389
|
-
fileExtension: typescript.Extension;
|
|
384
|
+
fileExtension: typescript$1.Extension;
|
|
390
385
|
fileContent: string;
|
|
391
386
|
}[]>;
|
|
392
387
|
}
|
|
@@ -1592,7 +1587,7 @@ declare function generateApi(config: Partial<GenerateApiConfiguration["config"]>
|
|
|
1592
1587
|
eol?: boolean | undefined;
|
|
1593
1588
|
}) => string;
|
|
1594
1589
|
NameResolver: typeof NameResolver;
|
|
1595
|
-
_:
|
|
1590
|
+
_: lodash14.LoDashStatic;
|
|
1596
1591
|
require: (packageOrPath: string) => Promise<any>;
|
|
1597
1592
|
};
|
|
1598
1593
|
};
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
1
|
import * as lodash19 from "lodash";
|
|
2
|
+
import * as lodash14 from "lodash";
|
|
3
3
|
import lodash from "lodash";
|
|
4
|
+
import * as typescript$1 from "typescript";
|
|
4
5
|
import * as typescript from "typescript";
|
|
5
6
|
import * as eta20 from "eta";
|
|
6
7
|
import { OpenAPI } from "openapi-types";
|
|
@@ -338,14 +339,7 @@ declare class SchemaRoutes {
|
|
|
338
339
|
};
|
|
339
340
|
};
|
|
340
341
|
convertRouteParamsIntoObject: (params: any) => any;
|
|
341
|
-
getRequestBodyInfo: (routeInfo: any, routeParams: any, parsedSchemas: any, routeName: any) =>
|
|
342
|
-
paramName: any;
|
|
343
|
-
contentTypes: any[];
|
|
344
|
-
contentKind: string;
|
|
345
|
-
schema: any;
|
|
346
|
-
type: any;
|
|
347
|
-
required: any;
|
|
348
|
-
};
|
|
342
|
+
getRequestBodyInfo: (routeInfo: any, routeParams: any, parsedSchemas: any, routeName: any) => any;
|
|
349
343
|
createRequestParamsSchema: ({
|
|
350
344
|
queryParams,
|
|
351
345
|
queryObjectSchema,
|
|
@@ -385,7 +379,7 @@ declare class JavascriptTranslator extends Translator {
|
|
|
385
379
|
compileTSCode: (input: TranslatorIO) => Record<string, string>;
|
|
386
380
|
translate: (input: any) => Promise<{
|
|
387
381
|
fileName: any;
|
|
388
|
-
fileExtension: typescript.Extension;
|
|
382
|
+
fileExtension: typescript$1.Extension;
|
|
389
383
|
fileContent: string;
|
|
390
384
|
}[]>;
|
|
391
385
|
}
|
|
@@ -1591,7 +1585,7 @@ declare function generateApi(config: Partial<GenerateApiConfiguration["config"]>
|
|
|
1591
1585
|
eol?: boolean | undefined;
|
|
1592
1586
|
}) => string;
|
|
1593
1587
|
NameResolver: typeof NameResolver;
|
|
1594
|
-
_:
|
|
1588
|
+
_: lodash14.LoDashStatic;
|
|
1595
1589
|
require: (packageOrPath: string) => Promise<any>;
|
|
1596
1590
|
};
|
|
1597
1591
|
};
|
package/dist/lib.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
2
|
import { consola } from "consola";
|
|
3
3
|
import lodash from "lodash";
|
|
4
|
+
import * as typescript$3 from "typescript";
|
|
5
|
+
import * as typescript$2 from "typescript";
|
|
6
|
+
import * as typescript$1 from "typescript";
|
|
4
7
|
import * as typescript from "typescript";
|
|
8
|
+
import * as path$3 from "node:path";
|
|
9
|
+
import * as path$2 from "node:path";
|
|
5
10
|
import * as path$1 from "node:path";
|
|
6
11
|
import path from "node:path";
|
|
7
12
|
import { Biome, Distribution } from "@biomejs/js-api";
|
|
13
|
+
import * as nanoid$1 from "nanoid";
|
|
8
14
|
import * as nanoid from "nanoid";
|
|
9
15
|
import * as yaml from "js-yaml";
|
|
10
16
|
import * as swagger2openapi from "swagger2openapi";
|
|
17
|
+
import * as url$2 from "node:url";
|
|
11
18
|
import * as url$1 from "node:url";
|
|
12
19
|
import url from "node:url";
|
|
13
20
|
import * as Eta from "eta";
|
|
@@ -22,11 +29,11 @@ var CodeFormatter = class {
|
|
|
22
29
|
removeUnusedImports = (content) => {
|
|
23
30
|
const tempFileName = "file.ts";
|
|
24
31
|
const host = new TsLanguageServiceHost(tempFileName, content);
|
|
25
|
-
const languageService = typescript.createLanguageService(host);
|
|
32
|
+
const languageService = typescript$3.createLanguageService(host);
|
|
26
33
|
const fileTextChanges = languageService.organizeImports({
|
|
27
34
|
type: "file",
|
|
28
35
|
fileName: tempFileName
|
|
29
|
-
}, { newLineCharacter: typescript.sys.newLine }, void 0)[0];
|
|
36
|
+
}, { newLineCharacter: typescript$3.sys.newLine }, void 0)[0];
|
|
30
37
|
if (fileTextChanges?.textChanges.length) return fileTextChanges.textChanges.reduceRight((content$1, { span, newText }) => `${content$1.slice(0, span.start)}${newText}${content$1.slice(span.start + span.length)}`, content);
|
|
31
38
|
return content;
|
|
32
39
|
};
|
|
@@ -37,8 +44,8 @@ var CodeFormatter = class {
|
|
|
37
44
|
files: { maxSize: Number.MAX_SAFE_INTEGER },
|
|
38
45
|
formatter: { indentStyle: "space" }
|
|
39
46
|
});
|
|
40
|
-
const formatted = biome.formatContent(biomeProject.projectKey, content, { filePath: path$
|
|
41
|
-
name: nanoid.nanoid(),
|
|
47
|
+
const formatted = biome.formatContent(biomeProject.projectKey, content, { filePath: path$3.format({
|
|
48
|
+
name: nanoid$1.nanoid(),
|
|
42
49
|
ext: "ts"
|
|
43
50
|
}) });
|
|
44
51
|
return formatted.content;
|
|
@@ -56,11 +63,11 @@ var TsLanguageServiceHost = class {
|
|
|
56
63
|
constructor(fileName, content) {
|
|
57
64
|
this.fileName = fileName;
|
|
58
65
|
this.content = content;
|
|
59
|
-
const tsconfig = typescript.findConfigFile(fileName, typescript.sys.fileExists);
|
|
60
|
-
this.compilerOptions = tsconfig ? typescript.convertCompilerOptionsFromJson(typescript.readConfigFile(tsconfig, typescript.sys.readFile).config.compilerOptions, "").options : typescript.getDefaultCompilerOptions();
|
|
66
|
+
const tsconfig = typescript$3.findConfigFile(fileName, typescript$3.sys.fileExists);
|
|
67
|
+
this.compilerOptions = tsconfig ? typescript$3.convertCompilerOptionsFromJson(typescript$3.readConfigFile(tsconfig, typescript$3.sys.readFile).config.compilerOptions, "").options : typescript$3.getDefaultCompilerOptions();
|
|
61
68
|
}
|
|
62
69
|
getNewLine() {
|
|
63
|
-
return "newLine" in typescript.sys ? typescript.sys.newLine : "\n";
|
|
70
|
+
return "newLine" in typescript$3.sys ? typescript$3.sys.newLine : "\n";
|
|
64
71
|
}
|
|
65
72
|
getScriptFileNames() {
|
|
66
73
|
return [this.fileName];
|
|
@@ -69,23 +76,23 @@ var TsLanguageServiceHost = class {
|
|
|
69
76
|
return this.compilerOptions;
|
|
70
77
|
}
|
|
71
78
|
getDefaultLibFileName() {
|
|
72
|
-
return typescript.getDefaultLibFileName(this.getCompilationSettings());
|
|
79
|
+
return typescript$3.getDefaultLibFileName(this.getCompilationSettings());
|
|
73
80
|
}
|
|
74
81
|
getCurrentDirectory() {
|
|
75
82
|
return process.cwd();
|
|
76
83
|
}
|
|
77
84
|
getScriptVersion() {
|
|
78
|
-
return typescript.version;
|
|
85
|
+
return typescript$3.version;
|
|
79
86
|
}
|
|
80
87
|
getScriptSnapshot() {
|
|
81
|
-
return typescript.ScriptSnapshot.fromString(this.content);
|
|
88
|
+
return typescript$3.ScriptSnapshot.fromString(this.content);
|
|
82
89
|
}
|
|
83
90
|
readFile(fileName, encoding) {
|
|
84
91
|
if (fileName === this.fileName) return this.content;
|
|
85
|
-
return typescript.sys.readFile(fileName, encoding);
|
|
92
|
+
return typescript$3.sys.readFile(fileName, encoding);
|
|
86
93
|
}
|
|
87
|
-
fileExists(path$
|
|
88
|
-
return typescript.sys.fileExists(path$
|
|
94
|
+
fileExists(path$4) {
|
|
95
|
+
return typescript$3.sys.fileExists(path$4);
|
|
89
96
|
}
|
|
90
97
|
};
|
|
91
98
|
|
|
@@ -155,7 +162,7 @@ const getRandomInt = (min = 0, max = 1) => {
|
|
|
155
162
|
var ComponentTypeNameResolver = class extends NameResolver {
|
|
156
163
|
counter = 1;
|
|
157
164
|
fallbackNameCounter = 1;
|
|
158
|
-
countersByVariant =
|
|
165
|
+
countersByVariant = new Map();
|
|
159
166
|
constructor(config, reservedNames) {
|
|
160
167
|
super(config, reservedNames, (variants) => {
|
|
161
168
|
const randomVariant = variants[getRandomInt(0, variants.length - 1)];
|
|
@@ -177,7 +184,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
177
184
|
//#endregion
|
|
178
185
|
//#region package.json
|
|
179
186
|
var name = "swagger-typescript-api";
|
|
180
|
-
var version = "13.2.
|
|
187
|
+
var version = "13.2.7";
|
|
181
188
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
182
189
|
var homepage = "https://github.com/acacode/swagger-typescript-api";
|
|
183
190
|
var bugs = "https://github.com/acacode/swagger-typescript-api/issues";
|
|
@@ -239,11 +246,11 @@ var devDependencies = {
|
|
|
239
246
|
"@tsconfig/strictest": "2.0.5",
|
|
240
247
|
"@types/js-yaml": "4.0.9",
|
|
241
248
|
"@types/lodash": "4.17.18",
|
|
242
|
-
"@types/node": "24.0.
|
|
249
|
+
"@types/node": "24.0.4",
|
|
243
250
|
"@types/swagger2openapi": "7.0.4",
|
|
244
251
|
"axios": "1.10.0",
|
|
245
252
|
"openapi-types": "12.1.3",
|
|
246
|
-
"tsdown": "0.12.
|
|
253
|
+
"tsdown": "0.12.9",
|
|
247
254
|
"typedoc": "0.28.5",
|
|
248
255
|
"vitest": "3.2.4"
|
|
249
256
|
};
|
|
@@ -426,7 +433,7 @@ var CodeGenConfig = class {
|
|
|
426
433
|
httpClient: "http-client",
|
|
427
434
|
outOfModuleApi: "Common"
|
|
428
435
|
};
|
|
429
|
-
routeNameDuplicatesMap =
|
|
436
|
+
routeNameDuplicatesMap = new Map();
|
|
430
437
|
hooks = {
|
|
431
438
|
onPreBuildRoutePath: (_routePath) => void 0,
|
|
432
439
|
onBuildRoutePath: (_routeData) => void 0,
|
|
@@ -536,10 +543,10 @@ var CodeGenConfig = class {
|
|
|
536
543
|
]
|
|
537
544
|
};
|
|
538
545
|
compilerTsConfig = {
|
|
539
|
-
module: typescript.ModuleKind.ESNext,
|
|
546
|
+
module: typescript$2.ModuleKind.ESNext,
|
|
540
547
|
noImplicitReturns: true,
|
|
541
548
|
alwaysStrict: true,
|
|
542
|
-
target: typescript.ScriptTarget.ESNext,
|
|
549
|
+
target: typescript$2.ScriptTarget.ESNext,
|
|
543
550
|
declaration: true,
|
|
544
551
|
noImplicitAny: false,
|
|
545
552
|
sourceMap: false,
|
|
@@ -1864,6 +1871,7 @@ var SchemaRoutes = class {
|
|
|
1864
1871
|
...refTypeInfo.rawTypeData,
|
|
1865
1872
|
...refTypeInfo.rawTypeData.schema || {}
|
|
1866
1873
|
};
|
|
1874
|
+
if (parameter?.required && !routeParam.required) routeParam.required = parameter.required;
|
|
1867
1875
|
} else {
|
|
1868
1876
|
if (!parameter.in) return;
|
|
1869
1877
|
if (!routeParams[parameter.in]) routeParams[parameter.in] = [];
|
|
@@ -2036,7 +2044,9 @@ var SchemaRoutes = class {
|
|
|
2036
2044
|
if (schema?.typeData) schema.typeData.isExtractedRequestBody = true;
|
|
2037
2045
|
content = this.schemaParserFabric.getInlineParseContent({ $ref: schema.$ref });
|
|
2038
2046
|
}
|
|
2047
|
+
if (schema && schema.typeData && !schema.typeData.description && requestBody?.description) schema.typeData.description = requestBody.description;
|
|
2039
2048
|
return {
|
|
2049
|
+
...requestBody || {},
|
|
2040
2050
|
paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
|
|
2041
2051
|
contentTypes,
|
|
2042
2052
|
contentKind,
|
|
@@ -2218,6 +2228,7 @@ var SchemaRoutes = class {
|
|
|
2218
2228
|
type: queryType
|
|
2219
2229
|
} : void 0,
|
|
2220
2230
|
body: requestBodyInfo.type ? {
|
|
2231
|
+
...requestBodyInfo,
|
|
2221
2232
|
name: nameResolver.resolve([requestBodyInfo.paramName, ...RESERVED_BODY_ARG_NAMES]),
|
|
2222
2233
|
optional: !requestBodyInfo.required,
|
|
2223
2234
|
type: requestBodyInfo.type
|
|
@@ -2338,8 +2349,8 @@ var SchemaRoutes = class {
|
|
|
2338
2349
|
var SchemaWalker = class {
|
|
2339
2350
|
config;
|
|
2340
2351
|
swaggerSchemaResolver;
|
|
2341
|
-
schemas =
|
|
2342
|
-
caches =
|
|
2352
|
+
schemas = new Map();
|
|
2353
|
+
caches = new Map();
|
|
2343
2354
|
constructor(config, swaggerSchemaResolver) {
|
|
2344
2355
|
this.config = config;
|
|
2345
2356
|
this.swaggerSchemaResolver = swaggerSchemaResolver;
|
|
@@ -2354,8 +2365,8 @@ var SchemaWalker = class {
|
|
|
2354
2365
|
return ref.startsWith("http://") || ref.startsWith("https://");
|
|
2355
2366
|
};
|
|
2356
2367
|
_getRefDataFromSchema = (schema, ref) => {
|
|
2357
|
-
const path$
|
|
2358
|
-
const refData = lodash.get(schema, path$
|
|
2368
|
+
const path$4 = ref.replace("#", "").split("/");
|
|
2369
|
+
const refData = lodash.get(schema, path$4);
|
|
2359
2370
|
if (refData) this.caches.set(ref, refData);
|
|
2360
2371
|
return refData;
|
|
2361
2372
|
};
|
|
@@ -2368,15 +2379,15 @@ var Request = class {
|
|
|
2368
2379
|
constructor(config) {
|
|
2369
2380
|
this.config = config;
|
|
2370
2381
|
}
|
|
2371
|
-
async download({ url: url$
|
|
2382
|
+
async download({ url: url$3, authToken,...options }) {
|
|
2372
2383
|
const requestOptions = {};
|
|
2373
2384
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2374
2385
|
lodash.merge(requestOptions, options, this.config.requestOptions);
|
|
2375
2386
|
try {
|
|
2376
|
-
const response = await fetch(url$
|
|
2387
|
+
const response = await fetch(url$3, requestOptions);
|
|
2377
2388
|
return await response.text();
|
|
2378
2389
|
} catch (error) {
|
|
2379
|
-
const message = `error while fetching data from URL "${url$
|
|
2390
|
+
const message = `error while fetching data from URL "${url$3}"`;
|
|
2380
2391
|
consola.error(message, error);
|
|
2381
2392
|
return message;
|
|
2382
2393
|
}
|
|
@@ -2395,9 +2406,9 @@ var SwaggerSchemaResolver = class {
|
|
|
2395
2406
|
this.request = new Request(config);
|
|
2396
2407
|
}
|
|
2397
2408
|
async create() {
|
|
2398
|
-
const { spec, patch, input, url: url$
|
|
2409
|
+
const { spec, patch, input, url: url$3, authorizationToken } = this.config;
|
|
2399
2410
|
if (spec) return await this.convertSwaggerObject(spec, { patch });
|
|
2400
|
-
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url$
|
|
2411
|
+
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url$3, authorizationToken);
|
|
2401
2412
|
const swaggerSchemaObject = this.processSwaggerSchemaFile(swaggerSchemaFile);
|
|
2402
2413
|
return await this.convertSwaggerObject(swaggerSchemaObject, { patch });
|
|
2403
2414
|
}
|
|
@@ -2487,12 +2498,12 @@ var TemplatesWorker = class {
|
|
|
2487
2498
|
if (this.config.silent) consola.level = 0;
|
|
2488
2499
|
}
|
|
2489
2500
|
getTemplatePaths = (config) => {
|
|
2490
|
-
const __dirname$1 = path$
|
|
2491
|
-
const baseTemplatesPath = path$
|
|
2492
|
-
const defaultTemplatesPath = path$
|
|
2493
|
-
const modularTemplatesPath = path$
|
|
2501
|
+
const __dirname$1 = path$2.dirname(url$2.fileURLToPath(import.meta.url));
|
|
2502
|
+
const baseTemplatesPath = path$2.resolve(__dirname$1, "../templates/base");
|
|
2503
|
+
const defaultTemplatesPath = path$2.resolve(__dirname$1, "../templates/default");
|
|
2504
|
+
const modularTemplatesPath = path$2.resolve(__dirname$1, "../templates/modular");
|
|
2494
2505
|
const originalTemplatesPath = config.modular ? modularTemplatesPath : defaultTemplatesPath;
|
|
2495
|
-
const customTemplatesPath = config.templates && path$
|
|
2506
|
+
const customTemplatesPath = config.templates && path$2.resolve(process.cwd(), config.templates);
|
|
2496
2507
|
return {
|
|
2497
2508
|
base: baseTemplatesPath,
|
|
2498
2509
|
default: defaultTemplatesPath,
|
|
@@ -2501,20 +2512,20 @@ var TemplatesWorker = class {
|
|
|
2501
2512
|
custom: customTemplatesPath
|
|
2502
2513
|
};
|
|
2503
2514
|
};
|
|
2504
|
-
cropExtension = (path$
|
|
2515
|
+
cropExtension = (path$4) => this.config.templateExtensions.reduce((path$5, ext) => path$5.endsWith(ext) ? path$5.replace(ext, "") : path$5, path$4);
|
|
2505
2516
|
getTemplateFullPath = (path_, fileName) => {
|
|
2506
|
-
const raw = path$
|
|
2517
|
+
const raw = path$2.resolve(path_, "./", this.cropExtension(fileName));
|
|
2507
2518
|
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
|
|
2508
2519
|
return pathVariants.find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
2509
2520
|
};
|
|
2510
2521
|
requireFnFromTemplate = async (packageOrPath) => {
|
|
2511
2522
|
const isPath = packageOrPath.startsWith("./") || packageOrPath.startsWith("../");
|
|
2512
|
-
if (isPath) return await import(path$
|
|
2523
|
+
if (isPath) return await import(path$2.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2513
2524
|
return await import(packageOrPath);
|
|
2514
2525
|
};
|
|
2515
|
-
getTemplate = (name$1, fileName, path$
|
|
2526
|
+
getTemplate = (name$1, fileName, path$4) => {
|
|
2516
2527
|
const { templatePaths } = this.config;
|
|
2517
|
-
if (path$
|
|
2528
|
+
if (path$4) return this.fileSystem.getFileContent(path$4);
|
|
2518
2529
|
if (!fileName) return "";
|
|
2519
2530
|
const customFullPath = templatePaths.custom && this.getTemplateFullPath(templatePaths.custom, fileName);
|
|
2520
2531
|
let fileContent = customFullPath && this.fileSystem.getFileContent(customFullPath);
|
|
@@ -2537,21 +2548,21 @@ var TemplatesWorker = class {
|
|
|
2537
2548
|
[name$1]: this.getTemplate(name$1, fileName)
|
|
2538
2549
|
}), {});
|
|
2539
2550
|
};
|
|
2540
|
-
findTemplateWithExt = (path$
|
|
2541
|
-
const raw = this.cropExtension(path$
|
|
2551
|
+
findTemplateWithExt = (path$4) => {
|
|
2552
|
+
const raw = this.cropExtension(path$4);
|
|
2542
2553
|
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
|
|
2543
2554
|
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2544
2555
|
};
|
|
2545
2556
|
getTemplateContent = (path_) => {
|
|
2546
2557
|
const foundTemplatePathKey = lodash.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
2547
2558
|
if (foundTemplatePathKey) {
|
|
2548
|
-
const rawPath = path$
|
|
2559
|
+
const rawPath = path$2.resolve(path_.replace(`@${foundTemplatePathKey}`, lodash.get(this.config.templatePaths, foundTemplatePathKey)));
|
|
2549
2560
|
const fixedPath = this.findTemplateWithExt(rawPath);
|
|
2550
2561
|
if (fixedPath) return this.fileSystem.getFileContent(fixedPath);
|
|
2551
2562
|
}
|
|
2552
|
-
const customPath = this.config.templatePaths.custom && this.findTemplateWithExt(path$
|
|
2563
|
+
const customPath = this.config.templatePaths.custom && this.findTemplateWithExt(path$2.resolve(this.config.templatePaths.custom, path_));
|
|
2553
2564
|
if (customPath) return this.fileSystem.getFileContent(customPath);
|
|
2554
|
-
const originalPath = this.findTemplateWithExt(path$
|
|
2565
|
+
const originalPath = this.findTemplateWithExt(path$2.resolve(this.config.templatePaths.original, path_));
|
|
2555
2566
|
if (originalPath) return this.fileSystem.getFileContent(originalPath);
|
|
2556
2567
|
return "";
|
|
2557
2568
|
};
|
|
@@ -2563,8 +2574,8 @@ var TemplatesWorker = class {
|
|
|
2563
2574
|
}, {
|
|
2564
2575
|
async: false,
|
|
2565
2576
|
...options,
|
|
2566
|
-
includeFile: (path$
|
|
2567
|
-
return this.renderTemplate(this.getTemplateContent(path$
|
|
2577
|
+
includeFile: (path$4, configuration$1, options$1 = {}) => {
|
|
2578
|
+
return this.renderTemplate(this.getTemplateContent(path$4), configuration$1, options$1);
|
|
2568
2579
|
}
|
|
2569
2580
|
});
|
|
2570
2581
|
};
|
|
@@ -2590,23 +2601,23 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2590
2601
|
compileTSCode = (input) => {
|
|
2591
2602
|
const fileNameFull = `${input.fileName}${input.fileExtension}`;
|
|
2592
2603
|
const output = {};
|
|
2593
|
-
const host = typescript.createCompilerHost(this.config.compilerTsConfig, true);
|
|
2604
|
+
const host = typescript$1.createCompilerHost(this.config.compilerTsConfig, true);
|
|
2594
2605
|
const fileNames = [fileNameFull];
|
|
2595
2606
|
const originalSourceFileGet = host.getSourceFile.bind(host);
|
|
2596
2607
|
host.getSourceFile = (sourceFileName, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
2597
2608
|
if (sourceFileName !== fileNameFull) return originalSourceFileGet(sourceFileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
2598
|
-
return typescript.createSourceFile(sourceFileName, input.fileContent, languageVersion, true, typescript.ScriptKind.TS);
|
|
2609
|
+
return typescript$1.createSourceFile(sourceFileName, input.fileContent, languageVersion, true, typescript$1.ScriptKind.TS);
|
|
2599
2610
|
};
|
|
2600
2611
|
host.writeFile = (fileName, contents) => {
|
|
2601
2612
|
output[fileName] = contents;
|
|
2602
2613
|
};
|
|
2603
|
-
typescript.createProgram(fileNames, this.config.compilerTsConfig, host).emit();
|
|
2614
|
+
typescript$1.createProgram(fileNames, this.config.compilerTsConfig, host).emit();
|
|
2604
2615
|
return output;
|
|
2605
2616
|
};
|
|
2606
2617
|
translate = async (input) => {
|
|
2607
2618
|
const compiled = this.compileTSCode(input);
|
|
2608
|
-
const jsFileName = `${input.fileName}${typescript.Extension.Js}`;
|
|
2609
|
-
const dtsFileName = `${input.fileName}${typescript.Extension.Dts}`;
|
|
2619
|
+
const jsFileName = `${input.fileName}${typescript$1.Extension.Js}`;
|
|
2620
|
+
const dtsFileName = `${input.fileName}${typescript$1.Extension.Dts}`;
|
|
2610
2621
|
const sourceContent = compiled[jsFileName];
|
|
2611
2622
|
const tsImportRows = input.fileContent.split("\n").filter((line) => line.startsWith("import "));
|
|
2612
2623
|
const declarationContent = compiled[dtsFileName].split("\n").map((line) => {
|
|
@@ -2615,11 +2626,11 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2615
2626
|
}).join("\n");
|
|
2616
2627
|
return [{
|
|
2617
2628
|
fileName: input.fileName,
|
|
2618
|
-
fileExtension: typescript.Extension.Js,
|
|
2629
|
+
fileExtension: typescript$1.Extension.Js,
|
|
2619
2630
|
fileContent: await this.codeFormatter.formatCode(sourceContent)
|
|
2620
2631
|
}, {
|
|
2621
2632
|
fileName: input.fileName,
|
|
2622
|
-
fileExtension: typescript.Extension.Dts,
|
|
2633
|
+
fileExtension: typescript$1.Extension.Dts,
|
|
2623
2634
|
fileContent: await this.codeFormatter.formatCode(declarationContent)
|
|
2624
2635
|
}];
|
|
2625
2636
|
};
|
|
@@ -2628,7 +2639,7 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2628
2639
|
//#endregion
|
|
2629
2640
|
//#region src/type-name-formatter.ts
|
|
2630
2641
|
var TypeNameFormatter = class {
|
|
2631
|
-
formattedModelNamesMap =
|
|
2642
|
+
formattedModelNamesMap = new Map();
|
|
2632
2643
|
config;
|
|
2633
2644
|
constructor(config) {
|
|
2634
2645
|
this.config = config;
|
|
@@ -2671,16 +2682,16 @@ var TypeNameFormatter = class {
|
|
|
2671
2682
|
//#endregion
|
|
2672
2683
|
//#region src/util/file-system.ts
|
|
2673
2684
|
var FileSystem = class {
|
|
2674
|
-
getFileContent = (path$
|
|
2675
|
-
return fs.readFileSync(path$
|
|
2685
|
+
getFileContent = (path$4) => {
|
|
2686
|
+
return fs.readFileSync(path$4, { encoding: "utf8" });
|
|
2676
2687
|
};
|
|
2677
|
-
readDir = (path$
|
|
2678
|
-
return fs.readdirSync(path$
|
|
2688
|
+
readDir = (path$4) => {
|
|
2689
|
+
return fs.readdirSync(path$4);
|
|
2679
2690
|
};
|
|
2680
|
-
pathIsDir = (path$
|
|
2681
|
-
if (!path$
|
|
2691
|
+
pathIsDir = (path$4) => {
|
|
2692
|
+
if (!path$4) return false;
|
|
2682
2693
|
try {
|
|
2683
|
-
const stat = fs.statSync(path$
|
|
2694
|
+
const stat = fs.statSync(path$4);
|
|
2684
2695
|
return stat.isDirectory();
|
|
2685
2696
|
} catch (e) {
|
|
2686
2697
|
return false;
|
|
@@ -2691,27 +2702,27 @@ var FileSystem = class {
|
|
|
2691
2702
|
if (fileNameParts.length > 1) fileNameParts.pop();
|
|
2692
2703
|
return fileNameParts.join(".");
|
|
2693
2704
|
};
|
|
2694
|
-
removeDir = (path$
|
|
2705
|
+
removeDir = (path$4) => {
|
|
2695
2706
|
try {
|
|
2696
|
-
if (typeof fs.rmSync === "function") fs.rmSync(path$
|
|
2697
|
-
else fs.rmdirSync(path$
|
|
2707
|
+
if (typeof fs.rmSync === "function") fs.rmSync(path$4, { recursive: true });
|
|
2708
|
+
else fs.rmdirSync(path$4, { recursive: true });
|
|
2698
2709
|
} catch (e) {
|
|
2699
2710
|
consola.debug("failed to remove dir", e);
|
|
2700
2711
|
}
|
|
2701
2712
|
};
|
|
2702
|
-
createDir = (path$
|
|
2713
|
+
createDir = (path$4) => {
|
|
2703
2714
|
try {
|
|
2704
|
-
fs.mkdirSync(path$
|
|
2715
|
+
fs.mkdirSync(path$4, { recursive: true });
|
|
2705
2716
|
} catch (e) {
|
|
2706
2717
|
consola.debug("failed to create dir", e);
|
|
2707
2718
|
}
|
|
2708
2719
|
};
|
|
2709
|
-
cleanDir = (path$
|
|
2710
|
-
this.removeDir(path$
|
|
2711
|
-
this.createDir(path$
|
|
2720
|
+
cleanDir = (path$4) => {
|
|
2721
|
+
this.removeDir(path$4);
|
|
2722
|
+
this.createDir(path$4);
|
|
2712
2723
|
};
|
|
2713
|
-
pathIsExist = (path$
|
|
2714
|
-
return !!path$
|
|
2724
|
+
pathIsExist = (path$4) => {
|
|
2725
|
+
return !!path$4 && fs.existsSync(path$4);
|
|
2715
2726
|
};
|
|
2716
2727
|
createFile = ({ path: path_, fileName, content, withPrefix }) => {
|
|
2717
2728
|
const __dirname$1 = path$1.dirname(url$1.fileURLToPath(import.meta.url));
|
|
@@ -3159,4 +3170,4 @@ async function generateApi(config) {
|
|
|
3159
3170
|
|
|
3160
3171
|
//#endregion
|
|
3161
3172
|
export { CodeGenConfig, HTTP_CLIENT, TemplatesGenConfig, constants_exports, generateApi, generateTemplates, package_default };
|
|
3162
|
-
//# sourceMappingURL=src-
|
|
3173
|
+
//# sourceMappingURL=src-BgBqKQNC.js.map
|