swagger-typescript-api 13.2.8 → 13.2.10
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 +30 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/lib.cjs +3 -1
- package/dist/lib.d.cts +226 -11
- package/dist/lib.d.ts +226 -11
- package/dist/lib.js +2 -2
- package/dist/{src-BtVFSrff.cjs → src-C5bMYV9w.cjs} +130 -80
- package/dist/src-C5bMYV9w.cjs.map +1 -0
- package/dist/{src-4gUT3jPg.js → src-s8addnrG.js} +183 -152
- package/dist/src-s8addnrG.js.map +1 -0
- package/package.json +12 -12
- package/templates/base/http-clients/fetch-http-client.ejs +1 -1
- package/dist/src-4gUT3jPg.js.map +0 -1
- package/dist/src-BtVFSrff.cjs.map +0 -1
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { __export } from "./chunk-Cl8Af3a2.js";
|
|
2
|
+
import * as module from "node:module";
|
|
2
3
|
import { consola } from "consola";
|
|
3
4
|
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";
|
|
7
5
|
import * as typescript from "typescript";
|
|
8
|
-
import * as path$3 from "node:path";
|
|
9
|
-
import * as path$2 from "node:path";
|
|
10
6
|
import * as path$1 from "node:path";
|
|
11
7
|
import path from "node:path";
|
|
12
8
|
import { Biome, Distribution } from "@biomejs/js-api";
|
|
13
|
-
import * as nanoid$1 from "nanoid";
|
|
14
9
|
import * as nanoid from "nanoid";
|
|
15
10
|
import * as yaml from "js-yaml";
|
|
16
11
|
import * as swagger2openapi from "swagger2openapi";
|
|
17
|
-
import * as url$2 from "node:url";
|
|
18
12
|
import * as url$1 from "node:url";
|
|
19
13
|
import url from "node:url";
|
|
20
14
|
import * as Eta from "eta";
|
|
@@ -29,11 +23,11 @@ var CodeFormatter = class {
|
|
|
29
23
|
removeUnusedImports = (content) => {
|
|
30
24
|
const tempFileName = "file.ts";
|
|
31
25
|
const host = new TsLanguageServiceHost(tempFileName, content);
|
|
32
|
-
const languageService = typescript
|
|
26
|
+
const languageService = typescript.createLanguageService(host);
|
|
33
27
|
const fileTextChanges = languageService.organizeImports({
|
|
34
28
|
type: "file",
|
|
35
29
|
fileName: tempFileName
|
|
36
|
-
}, { newLineCharacter: typescript
|
|
30
|
+
}, { newLineCharacter: typescript.sys.newLine }, void 0)[0];
|
|
37
31
|
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);
|
|
38
32
|
return content;
|
|
39
33
|
};
|
|
@@ -44,8 +38,8 @@ var CodeFormatter = class {
|
|
|
44
38
|
files: { maxSize: Number.MAX_SAFE_INTEGER },
|
|
45
39
|
formatter: { indentStyle: "space" }
|
|
46
40
|
});
|
|
47
|
-
const formatted = biome.formatContent(biomeProject.projectKey, content, { filePath: path$
|
|
48
|
-
name: nanoid
|
|
41
|
+
const formatted = biome.formatContent(biomeProject.projectKey, content, { filePath: path$1.format({
|
|
42
|
+
name: nanoid.nanoid(),
|
|
49
43
|
ext: "ts"
|
|
50
44
|
}) });
|
|
51
45
|
return formatted.content;
|
|
@@ -63,11 +57,11 @@ var TsLanguageServiceHost = class {
|
|
|
63
57
|
constructor(fileName, content) {
|
|
64
58
|
this.fileName = fileName;
|
|
65
59
|
this.content = content;
|
|
66
|
-
const tsconfig = typescript
|
|
67
|
-
this.compilerOptions = tsconfig ? typescript
|
|
60
|
+
const tsconfig = typescript.findConfigFile(fileName, typescript.sys.fileExists);
|
|
61
|
+
this.compilerOptions = tsconfig ? typescript.convertCompilerOptionsFromJson(typescript.readConfigFile(tsconfig, typescript.sys.readFile).config.compilerOptions, "").options : typescript.getDefaultCompilerOptions();
|
|
68
62
|
}
|
|
69
63
|
getNewLine() {
|
|
70
|
-
return "newLine" in typescript
|
|
64
|
+
return "newLine" in typescript.sys ? typescript.sys.newLine : "\n";
|
|
71
65
|
}
|
|
72
66
|
getScriptFileNames() {
|
|
73
67
|
return [this.fileName];
|
|
@@ -76,23 +70,23 @@ var TsLanguageServiceHost = class {
|
|
|
76
70
|
return this.compilerOptions;
|
|
77
71
|
}
|
|
78
72
|
getDefaultLibFileName() {
|
|
79
|
-
return typescript
|
|
73
|
+
return typescript.getDefaultLibFileName(this.getCompilationSettings());
|
|
80
74
|
}
|
|
81
75
|
getCurrentDirectory() {
|
|
82
76
|
return process.cwd();
|
|
83
77
|
}
|
|
84
78
|
getScriptVersion() {
|
|
85
|
-
return typescript
|
|
79
|
+
return typescript.version;
|
|
86
80
|
}
|
|
87
81
|
getScriptSnapshot() {
|
|
88
|
-
return typescript
|
|
82
|
+
return typescript.ScriptSnapshot.fromString(this.content);
|
|
89
83
|
}
|
|
90
84
|
readFile(fileName, encoding) {
|
|
91
85
|
if (fileName === this.fileName) return this.content;
|
|
92
|
-
return typescript
|
|
86
|
+
return typescript.sys.readFile(fileName, encoding);
|
|
93
87
|
}
|
|
94
|
-
fileExists(path$
|
|
95
|
-
return typescript
|
|
88
|
+
fileExists(path$2) {
|
|
89
|
+
return typescript.sys.fileExists(path$2);
|
|
96
90
|
}
|
|
97
91
|
};
|
|
98
92
|
|
|
@@ -162,7 +156,7 @@ const getRandomInt = (min = 0, max = 1) => {
|
|
|
162
156
|
var ComponentTypeNameResolver = class extends NameResolver {
|
|
163
157
|
counter = 1;
|
|
164
158
|
fallbackNameCounter = 1;
|
|
165
|
-
countersByVariant = new Map();
|
|
159
|
+
countersByVariant = /* @__PURE__ */ new Map();
|
|
166
160
|
constructor(config, reservedNames) {
|
|
167
161
|
super(config, reservedNames, (variants) => {
|
|
168
162
|
const randomVariant = variants[getRandomInt(0, variants.length - 1)];
|
|
@@ -184,7 +178,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
184
178
|
//#endregion
|
|
185
179
|
//#region package.json
|
|
186
180
|
var name = "swagger-typescript-api";
|
|
187
|
-
var version = "13.2.
|
|
181
|
+
var version = "13.2.10";
|
|
188
182
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
189
183
|
var homepage = "https://github.com/acacode/swagger-typescript-api";
|
|
190
184
|
var bugs = "https://github.com/acacode/swagger-typescript-api/issues";
|
|
@@ -204,7 +198,7 @@ var exports = { ".": {
|
|
|
204
198
|
}
|
|
205
199
|
} };
|
|
206
200
|
var main = "./dist/lib.cjs";
|
|
207
|
-
var module = "./dist/lib.js";
|
|
201
|
+
var module$1 = "./dist/lib.js";
|
|
208
202
|
var types = "./dist/lib.d.cts";
|
|
209
203
|
var bin = {
|
|
210
204
|
"sta": "./dist/cli.js",
|
|
@@ -224,10 +218,10 @@ var scripts = {
|
|
|
224
218
|
"typedoc": "typedoc"
|
|
225
219
|
};
|
|
226
220
|
var dependencies = {
|
|
227
|
-
"@biomejs/js-api": "
|
|
228
|
-
"@biomejs/wasm-nodejs": "2.
|
|
221
|
+
"@biomejs/js-api": "3.0.0",
|
|
222
|
+
"@biomejs/wasm-nodejs": "2.2.4",
|
|
229
223
|
"@types/swagger-schema-official": "^2.0.25",
|
|
230
|
-
"c12": "^3.0
|
|
224
|
+
"c12": "^3.2.0",
|
|
231
225
|
"citty": "^0.1.6",
|
|
232
226
|
"consola": "^3.4.2",
|
|
233
227
|
"eta": "^2.2.0",
|
|
@@ -239,22 +233,22 @@ var dependencies = {
|
|
|
239
233
|
"typescript": "~5.9.2"
|
|
240
234
|
};
|
|
241
235
|
var devDependencies = {
|
|
242
|
-
"@biomejs/biome": "2.
|
|
236
|
+
"@biomejs/biome": "2.2.4",
|
|
243
237
|
"@changesets/changelog-github": "0.5.1",
|
|
244
|
-
"@changesets/cli": "2.29.
|
|
245
|
-
"@tsconfig/
|
|
238
|
+
"@changesets/cli": "2.29.7",
|
|
239
|
+
"@tsconfig/node20": "20.1.6",
|
|
246
240
|
"@tsconfig/strictest": "2.0.5",
|
|
247
241
|
"@types/js-yaml": "4.0.9",
|
|
248
242
|
"@types/lodash": "4.17.20",
|
|
249
|
-
"@types/node": "24.2
|
|
243
|
+
"@types/node": "24.3.2",
|
|
250
244
|
"@types/swagger2openapi": "7.0.4",
|
|
251
|
-
"axios": "1.
|
|
245
|
+
"axios": "1.12.1",
|
|
252
246
|
"openapi-types": "12.1.3",
|
|
253
|
-
"tsdown": "0.
|
|
254
|
-
"typedoc": "0.28.
|
|
247
|
+
"tsdown": "0.15.1",
|
|
248
|
+
"typedoc": "0.28.12",
|
|
255
249
|
"vitest": "3.2.4"
|
|
256
250
|
};
|
|
257
|
-
var packageManager = "yarn@4.9.
|
|
251
|
+
var packageManager = "yarn@4.9.4";
|
|
258
252
|
var engines = { "node": ">=20" };
|
|
259
253
|
var publishConfig = {
|
|
260
254
|
"access": "public",
|
|
@@ -278,7 +272,7 @@ var package_default = {
|
|
|
278
272
|
type,
|
|
279
273
|
exports,
|
|
280
274
|
main,
|
|
281
|
-
module,
|
|
275
|
+
module: module$1,
|
|
282
276
|
types,
|
|
283
277
|
bin,
|
|
284
278
|
files,
|
|
@@ -304,7 +298,7 @@ __export(constants_exports, {
|
|
|
304
298
|
RESERVED_PATH_ARG_NAMES: () => RESERVED_PATH_ARG_NAMES,
|
|
305
299
|
RESERVED_QUERY_ARG_NAMES: () => RESERVED_QUERY_ARG_NAMES,
|
|
306
300
|
RESERVED_REQ_PARAMS_ARG_NAMES: () => RESERVED_REQ_PARAMS_ARG_NAMES,
|
|
307
|
-
SCHEMA_TYPES: () => SCHEMA_TYPES
|
|
301
|
+
SCHEMA_TYPES: () => SCHEMA_TYPES$1
|
|
308
302
|
});
|
|
309
303
|
const DEFAULT_BODY_ARG_NAME = "data";
|
|
310
304
|
const FILE_PREFIX = `/* eslint-disable */
|
|
@@ -343,7 +337,7 @@ const RESERVED_REQ_PARAMS_ARG_NAMES = [
|
|
|
343
337
|
"reqParams",
|
|
344
338
|
"httpParams"
|
|
345
339
|
];
|
|
346
|
-
const SCHEMA_TYPES = {
|
|
340
|
+
const SCHEMA_TYPES$1 = {
|
|
347
341
|
ARRAY: "array",
|
|
348
342
|
OBJECT: "object",
|
|
349
343
|
ENUM: "enum",
|
|
@@ -433,7 +427,7 @@ var CodeGenConfig = class {
|
|
|
433
427
|
httpClient: "http-client",
|
|
434
428
|
outOfModuleApi: "Common"
|
|
435
429
|
};
|
|
436
|
-
routeNameDuplicatesMap = new Map();
|
|
430
|
+
routeNameDuplicatesMap = /* @__PURE__ */ new Map();
|
|
437
431
|
hooks = {
|
|
438
432
|
onPreBuildRoutePath: (_routePath) => void 0,
|
|
439
433
|
onBuildRoutePath: (_routeData) => void 0,
|
|
@@ -543,10 +537,10 @@ var CodeGenConfig = class {
|
|
|
543
537
|
]
|
|
544
538
|
};
|
|
545
539
|
compilerTsConfig = {
|
|
546
|
-
module: typescript
|
|
540
|
+
module: typescript.ModuleKind.ESNext,
|
|
547
541
|
noImplicitReturns: true,
|
|
548
542
|
alwaysStrict: true,
|
|
549
|
-
target: typescript
|
|
543
|
+
target: typescript.ScriptTarget.ESNext,
|
|
550
544
|
declaration: true,
|
|
551
545
|
noImplicitAny: false,
|
|
552
546
|
sourceMap: false,
|
|
@@ -700,6 +694,7 @@ var CodeGenConfig = class {
|
|
|
700
694
|
}
|
|
701
695
|
update = (update) => {
|
|
702
696
|
objectAssign(this, update);
|
|
697
|
+
if (this.enumNamesAsValues) this.extractEnums = true;
|
|
703
698
|
};
|
|
704
699
|
};
|
|
705
700
|
|
|
@@ -767,7 +762,7 @@ var SchemaFormatters = class {
|
|
|
767
762
|
this.templatesWorker = schemaParser.templatesWorker;
|
|
768
763
|
}
|
|
769
764
|
base = {
|
|
770
|
-
[SCHEMA_TYPES.ENUM]: (parsedSchema) => {
|
|
765
|
+
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
771
766
|
if (this.config.generateUnionEnums) return {
|
|
772
767
|
...parsedSchema,
|
|
773
768
|
$content: parsedSchema.content,
|
|
@@ -779,15 +774,15 @@ var SchemaFormatters = class {
|
|
|
779
774
|
content: this.config.Ts.EnumFieldsWrapper(parsedSchema.content)
|
|
780
775
|
};
|
|
781
776
|
},
|
|
782
|
-
[SCHEMA_TYPES.OBJECT]: (parsedSchema) => {
|
|
783
|
-
if (parsedSchema.nullable) return this.inline[SCHEMA_TYPES.OBJECT](parsedSchema);
|
|
777
|
+
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
778
|
+
if (parsedSchema.nullable) return this.inline[SCHEMA_TYPES$1.OBJECT](parsedSchema);
|
|
784
779
|
return {
|
|
785
780
|
...parsedSchema,
|
|
786
781
|
$content: parsedSchema.content,
|
|
787
782
|
content: this.formatObjectContent(parsedSchema.content)
|
|
788
783
|
};
|
|
789
784
|
},
|
|
790
|
-
[SCHEMA_TYPES.PRIMITIVE]: (parsedSchema) => {
|
|
785
|
+
[SCHEMA_TYPES$1.PRIMITIVE]: (parsedSchema) => {
|
|
791
786
|
return {
|
|
792
787
|
...parsedSchema,
|
|
793
788
|
$content: parsedSchema.content
|
|
@@ -795,13 +790,13 @@ var SchemaFormatters = class {
|
|
|
795
790
|
}
|
|
796
791
|
};
|
|
797
792
|
inline = {
|
|
798
|
-
[SCHEMA_TYPES.ENUM]: (parsedSchema) => {
|
|
793
|
+
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
799
794
|
return {
|
|
800
795
|
...parsedSchema,
|
|
801
796
|
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType(lodash.compact([...parsedSchema.content.map(({ value }) => `${value}`), parsedSchema.nullable && this.config.Ts.Keyword.Null])) || this.config.Ts.Keyword.Any
|
|
802
797
|
};
|
|
803
798
|
},
|
|
804
|
-
[SCHEMA_TYPES.OBJECT]: (parsedSchema) => {
|
|
799
|
+
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
805
800
|
if (typeof parsedSchema.content === "string") return {
|
|
806
801
|
...parsedSchema,
|
|
807
802
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
@@ -887,7 +882,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
887
882
|
parse() {
|
|
888
883
|
let contentType;
|
|
889
884
|
const { type: type$1, description: description$1, items } = this.schema || {};
|
|
890
|
-
if (Array.isArray(items) && type$1 === SCHEMA_TYPES.ARRAY) {
|
|
885
|
+
if (Array.isArray(items) && type$1 === SCHEMA_TYPES$1.ARRAY) {
|
|
891
886
|
const tupleContent = [];
|
|
892
887
|
for (const item of items) tupleContent.push(this.schemaParserFabric.createSchemaParser({
|
|
893
888
|
schema: item,
|
|
@@ -905,8 +900,8 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
905
900
|
...typeof this.schema === "object" ? this.schema : {},
|
|
906
901
|
$schemaPath: this.schemaPath.slice(),
|
|
907
902
|
$parsedSchema: true,
|
|
908
|
-
schemaType: SCHEMA_TYPES.PRIMITIVE,
|
|
909
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
903
|
+
schemaType: SCHEMA_TYPES$1.PRIMITIVE,
|
|
904
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
910
905
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
911
906
|
name: this.typeName,
|
|
912
907
|
description: this.schemaFormatters.formatDescription(description$1),
|
|
@@ -926,12 +921,12 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
926
921
|
...typeof this.schema === "object" ? this.schema : {},
|
|
927
922
|
$schemaPath: this.schemaPath.slice(),
|
|
928
923
|
$parsedSchema: true,
|
|
929
|
-
schemaType: SCHEMA_TYPES.COMPLEX,
|
|
930
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
924
|
+
schemaType: SCHEMA_TYPES$1.COMPLEX,
|
|
925
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
931
926
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
932
927
|
name: this.typeName,
|
|
933
928
|
description: this.schemaFormatters.formatDescription(this.schema.description || lodash.compact(lodash.map(this.schema[complexType], "description"))[0] || ""),
|
|
934
|
-
content: this.config.Ts.IntersectionType(lodash.compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
929
|
+
content: this.config.Ts.IntersectionType(lodash.compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES$1.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
935
930
|
schema: simpleSchema,
|
|
936
931
|
schemaPath: this.schemaPath
|
|
937
932
|
}).getInlineParseContent())])) || this.config.Ts.Keyword.Any
|
|
@@ -961,8 +956,8 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
961
956
|
...typeof this.schema === "object" ? this.schema : {},
|
|
962
957
|
$schemaPath: this.schemaPath.slice(),
|
|
963
958
|
$parsedSchema: true,
|
|
964
|
-
schemaType: SCHEMA_TYPES.COMPLEX,
|
|
965
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
959
|
+
schemaType: SCHEMA_TYPES$1.COMPLEX,
|
|
960
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
966
961
|
typeIdentifier: ts.Keyword.Type,
|
|
967
962
|
name: this.typeName,
|
|
968
963
|
description: this.schemaFormatters.formatDescription(this.schema.description),
|
|
@@ -1041,7 +1036,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1041
1036
|
let mappingPropertySchemaEnumKeysMap = {};
|
|
1042
1037
|
let mappingPropertySchema = lodash.get(abstractSchemaStruct?.component?.rawTypeData, ["properties", discPropertyName]);
|
|
1043
1038
|
if (this.schemaUtils.isRefSchema(mappingPropertySchema)) mappingPropertySchema = this.schemaUtils.getSchemaRefType(mappingPropertySchema);
|
|
1044
|
-
if (mappingPropertySchema?.rawTypeData?.$parsed?.type === SCHEMA_TYPES.ENUM) mappingPropertySchemaEnumKeysMap = lodash.reduce(mappingPropertySchema.rawTypeData.$parsed.enum, (acc, key, index) => {
|
|
1039
|
+
if (mappingPropertySchema?.rawTypeData?.$parsed?.type === SCHEMA_TYPES$1.ENUM) mappingPropertySchemaEnumKeysMap = lodash.reduce(mappingPropertySchema.rawTypeData.$parsed.enum, (acc, key, index) => {
|
|
1045
1040
|
const enumKey = mappingPropertySchema.rawTypeData.$parsed.content[index].key;
|
|
1046
1041
|
acc[key] = ts.EnumUsageKey(mappingPropertySchema.rawTypeData.$parsed.typeName, enumKey);
|
|
1047
1042
|
return acc;
|
|
@@ -1058,9 +1053,9 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1058
1053
|
...schema,
|
|
1059
1054
|
$ref: abstractSchemaStruct.component.$ref
|
|
1060
1055
|
};
|
|
1061
|
-
if (this.schemaUtils.getInternalSchemaType(schema) === SCHEMA_TYPES.OBJECT) for (const schemaPropertyName in schema.properties) {
|
|
1056
|
+
if (this.schemaUtils.getInternalSchemaType(schema) === SCHEMA_TYPES$1.OBJECT) for (const schemaPropertyName in schema.properties) {
|
|
1062
1057
|
const schemaProperty = schema.properties[schemaPropertyName];
|
|
1063
|
-
if (schemaPropertyName === discPropertyName && this.schemaUtils.getInternalSchemaType(schemaProperty) === SCHEMA_TYPES.ENUM && schemaProperty.enum.length === 1 && mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]]) schema.properties[schemaPropertyName] = this.schemaParserFabric.createSchema({ content: mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]] });
|
|
1058
|
+
if (schemaPropertyName === discPropertyName && this.schemaUtils.getInternalSchemaType(schemaProperty) === SCHEMA_TYPES$1.ENUM && schemaProperty.enum.length === 1 && mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]]) schema.properties[schemaPropertyName] = this.schemaParserFabric.createSchema({ content: mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]] });
|
|
1064
1059
|
}
|
|
1065
1060
|
return schema;
|
|
1066
1061
|
});
|
|
@@ -1099,7 +1094,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1099
1094
|
createComplexSchemaStruct = () => {
|
|
1100
1095
|
const ts = this.config.Ts;
|
|
1101
1096
|
const complexType = this.schemaUtils.getComplexType(this.schema);
|
|
1102
|
-
if (complexType === SCHEMA_TYPES.COMPLEX_UNKNOWN) return null;
|
|
1097
|
+
if (complexType === SCHEMA_TYPES$1.COMPLEX_UNKNOWN) return null;
|
|
1103
1098
|
return { content: ts.ExpressionGroup(this.schemaParser._complexSchemaParsers[complexType](this.schema)) };
|
|
1104
1099
|
};
|
|
1105
1100
|
};
|
|
@@ -1156,9 +1151,19 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1156
1151
|
let content = null;
|
|
1157
1152
|
const formatValue = (value) => {
|
|
1158
1153
|
if (value === null) return this.config.Ts.NullValue(value);
|
|
1159
|
-
if (keyType.includes(this.schemaUtils.getSchemaType({ type: "number" })))
|
|
1160
|
-
|
|
1161
|
-
|
|
1154
|
+
if (keyType.includes(this.schemaUtils.getSchemaType({ type: "number" }))) {
|
|
1155
|
+
const maybeNumber = typeof value === "number" ? value : Number(value);
|
|
1156
|
+
if (!Number.isNaN(maybeNumber)) return this.config.Ts.NumberValue(maybeNumber);
|
|
1157
|
+
}
|
|
1158
|
+
if (keyType.includes(this.schemaUtils.getSchemaType({ type: "boolean" }))) {
|
|
1159
|
+
if (typeof value === "boolean") return this.config.Ts.BooleanValue(value);
|
|
1160
|
+
if (value === "true" || value === "false") return this.config.Ts.BooleanValue(value === "true");
|
|
1161
|
+
}
|
|
1162
|
+
switch (typeof value) {
|
|
1163
|
+
case "number": return this.config.Ts.NumberValue(value);
|
|
1164
|
+
case "boolean": return this.config.Ts.BooleanValue(value);
|
|
1165
|
+
default: return this.config.Ts.StringValue(value);
|
|
1166
|
+
}
|
|
1162
1167
|
};
|
|
1163
1168
|
if (Array.isArray(enumNames) && lodash.size(enumNames)) content = enumNames.map((enumName, index) => {
|
|
1164
1169
|
const enumValue = lodash.get(this.schema.enum, index);
|
|
@@ -1192,8 +1197,8 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1192
1197
|
$ref,
|
|
1193
1198
|
typeName: this.typeName || $ref && refType.typeName || null,
|
|
1194
1199
|
$parsedSchema: true,
|
|
1195
|
-
schemaType: SCHEMA_TYPES.ENUM,
|
|
1196
|
-
type: SCHEMA_TYPES.ENUM,
|
|
1200
|
+
schemaType: SCHEMA_TYPES$1.ENUM,
|
|
1201
|
+
type: SCHEMA_TYPES$1.ENUM,
|
|
1197
1202
|
keyType,
|
|
1198
1203
|
typeIdentifier: this.config.generateUnionEnums ? this.config.Ts.Keyword.Type : this.config.Ts.Keyword.Enum,
|
|
1199
1204
|
name: this.typeName,
|
|
@@ -1218,8 +1223,8 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1218
1223
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1219
1224
|
$schemaPath: this.schemaPath.slice(),
|
|
1220
1225
|
$parsedSchema: true,
|
|
1221
|
-
schemaType: SCHEMA_TYPES.OBJECT,
|
|
1222
|
-
type: SCHEMA_TYPES.OBJECT,
|
|
1226
|
+
schemaType: SCHEMA_TYPES$1.OBJECT,
|
|
1227
|
+
type: SCHEMA_TYPES$1.OBJECT,
|
|
1223
1228
|
typeIdentifier: this.config.Ts.Keyword.Interface,
|
|
1224
1229
|
name: this.typeName,
|
|
1225
1230
|
description: this.schemaFormatters.formatDescription(this.schema.description),
|
|
@@ -1301,7 +1306,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1301
1306
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1302
1307
|
oneOf: type$1.map((type$2) => ({ type: type$2 }))
|
|
1303
1308
|
});
|
|
1304
|
-
if (Array.isArray(items) && type$1 === SCHEMA_TYPES.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1309
|
+
if (Array.isArray(items) && type$1 === SCHEMA_TYPES$1.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1305
1310
|
schema: item,
|
|
1306
1311
|
schemaPath: this.schemaPath
|
|
1307
1312
|
}).getInlineParseContent()));
|
|
@@ -1309,8 +1314,8 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1309
1314
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1310
1315
|
$schemaPath: this.schemaPath.slice(),
|
|
1311
1316
|
$parsedSchema: true,
|
|
1312
|
-
schemaType: SCHEMA_TYPES.PRIMITIVE,
|
|
1313
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
1317
|
+
schemaType: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1318
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1314
1319
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
1315
1320
|
name: this.typeName,
|
|
1316
1321
|
description: this.schemaFormatters.formatDescription(description$1),
|
|
@@ -1391,67 +1396,67 @@ var SchemaParser = class {
|
|
|
1391
1396
|
this.schemaPath = [...schemaPath || []];
|
|
1392
1397
|
}
|
|
1393
1398
|
_complexSchemaParsers = {
|
|
1394
|
-
[SCHEMA_TYPES.COMPLEX_ONE_OF]: (schema) => {
|
|
1399
|
+
[SCHEMA_TYPES$1.COMPLEX_ONE_OF]: (schema) => {
|
|
1395
1400
|
const SchemaParser$1 = this.config.schemaParsers.complexOneOf || OneOfSchemaParser;
|
|
1396
1401
|
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1397
1402
|
return schemaParser.parse();
|
|
1398
1403
|
},
|
|
1399
|
-
[SCHEMA_TYPES.COMPLEX_ALL_OF]: (schema) => {
|
|
1404
|
+
[SCHEMA_TYPES$1.COMPLEX_ALL_OF]: (schema) => {
|
|
1400
1405
|
const SchemaParser$1 = this.config.schemaParsers.complexAllOf || AllOfSchemaParser;
|
|
1401
1406
|
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1402
1407
|
return schemaParser.parse();
|
|
1403
1408
|
},
|
|
1404
|
-
[SCHEMA_TYPES.COMPLEX_ANY_OF]: (schema) => {
|
|
1409
|
+
[SCHEMA_TYPES$1.COMPLEX_ANY_OF]: (schema) => {
|
|
1405
1410
|
const SchemaParser$1 = this.config.schemaParsers.complexAnyOf || AnyOfSchemaParser;
|
|
1406
1411
|
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1407
1412
|
return schemaParser.parse();
|
|
1408
1413
|
},
|
|
1409
|
-
[SCHEMA_TYPES.COMPLEX_NOT]: (schema) => {
|
|
1414
|
+
[SCHEMA_TYPES$1.COMPLEX_NOT]: (schema) => {
|
|
1410
1415
|
const SchemaParser$1 = this.config.schemaParsers.complexNot || NotSchemaParser;
|
|
1411
1416
|
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1412
1417
|
return schemaParser.parse();
|
|
1413
1418
|
}
|
|
1414
1419
|
};
|
|
1415
1420
|
_baseSchemaParsers = {
|
|
1416
|
-
[SCHEMA_TYPES.ENUM]: (schema, typeName) => {
|
|
1421
|
+
[SCHEMA_TYPES$1.ENUM]: (schema, typeName) => {
|
|
1417
1422
|
const SchemaParser$1 = this.config.schemaParsers.enum || EnumSchemaParser;
|
|
1418
1423
|
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1419
1424
|
return schemaParser.parse();
|
|
1420
1425
|
},
|
|
1421
|
-
[SCHEMA_TYPES.OBJECT]: (schema, typeName) => {
|
|
1426
|
+
[SCHEMA_TYPES$1.OBJECT]: (schema, typeName) => {
|
|
1422
1427
|
const SchemaParser$1 = this.config.schemaParsers.object || ObjectSchemaParser;
|
|
1423
1428
|
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1424
1429
|
return schemaParser.parse();
|
|
1425
1430
|
},
|
|
1426
|
-
[SCHEMA_TYPES.COMPLEX]: (schema, typeName) => {
|
|
1431
|
+
[SCHEMA_TYPES$1.COMPLEX]: (schema, typeName) => {
|
|
1427
1432
|
const SchemaParser$1 = this.config.schemaParsers.complex || ComplexSchemaParser;
|
|
1428
1433
|
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1429
1434
|
return schemaParser.parse();
|
|
1430
1435
|
},
|
|
1431
|
-
[SCHEMA_TYPES.PRIMITIVE]: (schema, typeName) => {
|
|
1436
|
+
[SCHEMA_TYPES$1.PRIMITIVE]: (schema, typeName) => {
|
|
1432
1437
|
const SchemaParser$1 = this.config.schemaParsers.primitive || PrimitiveSchemaParser;
|
|
1433
1438
|
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1434
1439
|
return schemaParser.parse();
|
|
1435
1440
|
},
|
|
1436
|
-
[SCHEMA_TYPES.DISCRIMINATOR]: (schema, typeName) => {
|
|
1441
|
+
[SCHEMA_TYPES$1.DISCRIMINATOR]: (schema, typeName) => {
|
|
1437
1442
|
const SchemaParser$1 = this.config.schemaParsers.discriminator || DiscriminatorSchemaParser;
|
|
1438
1443
|
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1439
1444
|
return schemaParser.parse();
|
|
1440
1445
|
},
|
|
1441
|
-
[SCHEMA_TYPES.ARRAY]: (schema, typeName) => {
|
|
1446
|
+
[SCHEMA_TYPES$1.ARRAY]: (schema, typeName) => {
|
|
1442
1447
|
const SchemaParser$1 = this.config.schemaParsers.array || ArraySchemaParser;
|
|
1443
1448
|
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1444
1449
|
return schemaParser.parse();
|
|
1445
1450
|
}
|
|
1446
1451
|
};
|
|
1447
1452
|
parseSchema = () => {
|
|
1448
|
-
if (!this.schema) return this._baseSchemaParsers[SCHEMA_TYPES.PRIMITIVE](null, this.typeName);
|
|
1453
|
+
if (!this.schema) return this._baseSchemaParsers[SCHEMA_TYPES$1.PRIMITIVE](null, this.typeName);
|
|
1449
1454
|
let schemaType = null;
|
|
1450
1455
|
let parsedSchema = null;
|
|
1451
1456
|
if (typeof this.schema === "string") return this.schema;
|
|
1452
1457
|
if (!this.schema.$parsed) {
|
|
1453
1458
|
if (!this.typeName && this.schemaUtils.isRefSchema(this.schema)) this.typeName = this.schemaUtils.getSchemaType(this.schema);
|
|
1454
|
-
if (this.schema.items && !Array.isArray(this.schema.items) && !this.schema.type) this.schema.type = SCHEMA_TYPES.ARRAY;
|
|
1459
|
+
if (this.schema.items && !Array.isArray(this.schema.items) && !this.schema.type) this.schema.type = SCHEMA_TYPES$1.ARRAY;
|
|
1455
1460
|
if (Array.isArray(this.schema.enum) && this.schema.enum.length === 1 && this.schema.enum[0] == null) {
|
|
1456
1461
|
consola.debug("invalid enum schema", this.schema);
|
|
1457
1462
|
this.schema = { type: this.config.Ts.Keyword.Null };
|
|
@@ -1566,8 +1571,8 @@ var SchemaUtils = class {
|
|
|
1566
1571
|
if (enumFieldType === this.config.Ts.Keyword.Undefined) return;
|
|
1567
1572
|
return internalCase(enumFieldType);
|
|
1568
1573
|
}
|
|
1569
|
-
if (lodash.keys(schema.properties).length) return SCHEMA_TYPES.OBJECT;
|
|
1570
|
-
if (schema.items) return SCHEMA_TYPES.ARRAY;
|
|
1574
|
+
if (lodash.keys(schema.properties).length) return SCHEMA_TYPES$1.OBJECT;
|
|
1575
|
+
if (schema.items) return SCHEMA_TYPES$1.ARRAY;
|
|
1571
1576
|
return null;
|
|
1572
1577
|
};
|
|
1573
1578
|
checkAndAddRequiredKeys = (schema, resultType) => {
|
|
@@ -1611,26 +1616,26 @@ var SchemaUtils = class {
|
|
|
1611
1616
|
return this.config.componentTypeNameResolver.resolve([...(prefixes || []).map((prefix) => pascalCase(`${prefix} ${typeName}`)), ...(suffixes || []).map((suffix) => pascalCase(`${typeName} ${suffix}`))], shouldReserve);
|
|
1612
1617
|
};
|
|
1613
1618
|
getComplexType = (schema) => {
|
|
1614
|
-
if (schema.oneOf) return SCHEMA_TYPES.COMPLEX_ONE_OF;
|
|
1615
|
-
if (schema.allOf) return SCHEMA_TYPES.COMPLEX_ALL_OF;
|
|
1616
|
-
if (schema.anyOf) return SCHEMA_TYPES.COMPLEX_ANY_OF;
|
|
1617
|
-
if (schema.not) return SCHEMA_TYPES.COMPLEX_NOT;
|
|
1618
|
-
return SCHEMA_TYPES.COMPLEX_UNKNOWN;
|
|
1619
|
+
if (schema.oneOf) return SCHEMA_TYPES$1.COMPLEX_ONE_OF;
|
|
1620
|
+
if (schema.allOf) return SCHEMA_TYPES$1.COMPLEX_ALL_OF;
|
|
1621
|
+
if (schema.anyOf) return SCHEMA_TYPES$1.COMPLEX_ANY_OF;
|
|
1622
|
+
if (schema.not) return SCHEMA_TYPES$1.COMPLEX_NOT;
|
|
1623
|
+
return SCHEMA_TYPES$1.COMPLEX_UNKNOWN;
|
|
1619
1624
|
};
|
|
1620
1625
|
getInternalSchemaType = (schema) => {
|
|
1621
|
-
if (!lodash.isEmpty(schema.enum) || !lodash.isEmpty(this.getEnumNames(schema))) return SCHEMA_TYPES.ENUM;
|
|
1622
|
-
if (schema.discriminator) return SCHEMA_TYPES.DISCRIMINATOR;
|
|
1623
|
-
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES.COMPLEX;
|
|
1624
|
-
if (!lodash.isEmpty(schema.properties)) return SCHEMA_TYPES.OBJECT;
|
|
1625
|
-
if (schema.type === SCHEMA_TYPES.ARRAY) return SCHEMA_TYPES.ARRAY;
|
|
1626
|
-
return SCHEMA_TYPES.PRIMITIVE;
|
|
1626
|
+
if (!lodash.isEmpty(schema.enum) || !lodash.isEmpty(this.getEnumNames(schema))) return SCHEMA_TYPES$1.ENUM;
|
|
1627
|
+
if (schema.discriminator) return SCHEMA_TYPES$1.DISCRIMINATOR;
|
|
1628
|
+
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES$1.COMPLEX;
|
|
1629
|
+
if (!lodash.isEmpty(schema.properties)) return SCHEMA_TYPES$1.OBJECT;
|
|
1630
|
+
if (schema.type === SCHEMA_TYPES$1.ARRAY) return SCHEMA_TYPES$1.ARRAY;
|
|
1631
|
+
return SCHEMA_TYPES$1.PRIMITIVE;
|
|
1627
1632
|
};
|
|
1628
1633
|
getSchemaType = (schema) => {
|
|
1629
1634
|
if (!schema) return this.config.Ts.Keyword.Any;
|
|
1630
1635
|
const refTypeInfo = this.getSchemaRefType(schema);
|
|
1631
1636
|
if (refTypeInfo) return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, this.typeNameFormatter.format(refTypeInfo.typeName)));
|
|
1632
1637
|
let resultType;
|
|
1633
|
-
if (this.isConstantSchema(schema)) resultType = this.formatJsValue(schema.const);
|
|
1638
|
+
if (this.isConstantSchema(schema) && !schema.enum) resultType = this.formatJsValue(schema.const);
|
|
1634
1639
|
else {
|
|
1635
1640
|
const primitiveType = this.getSchemaPrimitiveType(schema);
|
|
1636
1641
|
if (primitiveType == null) return this.config.Ts.Keyword.Any;
|
|
@@ -1654,10 +1659,9 @@ var SchemaUtils = class {
|
|
|
1654
1659
|
case "string": return this.config.Ts.StringValue(value);
|
|
1655
1660
|
case "boolean": return this.config.Ts.BooleanValue(value);
|
|
1656
1661
|
case "number": return this.config.Ts.NumberValue(value);
|
|
1657
|
-
default:
|
|
1662
|
+
default:
|
|
1658
1663
|
if (value === null) return this.config.Ts.NullValue(value);
|
|
1659
1664
|
return this.config.Ts.Keyword.Any;
|
|
1660
|
-
}
|
|
1661
1665
|
}
|
|
1662
1666
|
};
|
|
1663
1667
|
};
|
|
@@ -2056,7 +2060,7 @@ var SchemaRoutes = class {
|
|
|
2056
2060
|
};
|
|
2057
2061
|
};
|
|
2058
2062
|
createRequestParamsSchema = ({ queryParams, queryObjectSchema, pathArgsSchemas, extractRequestParams, routeName }) => {
|
|
2059
|
-
if (!queryParams || !queryParams.length) return null;
|
|
2063
|
+
if ((!queryParams || !queryParams.length) && (!pathArgsSchemas || !pathArgsSchemas.length)) return null;
|
|
2060
2064
|
const pathParams = pathArgsSchemas.reduce((acc, pathArgSchema) => {
|
|
2061
2065
|
if (pathArgSchema.name) acc[pathArgSchema.name] = {
|
|
2062
2066
|
...pathArgSchema,
|
|
@@ -2349,8 +2353,8 @@ var SchemaRoutes = class {
|
|
|
2349
2353
|
var SchemaWalker = class {
|
|
2350
2354
|
config;
|
|
2351
2355
|
swaggerSchemaResolver;
|
|
2352
|
-
schemas = new Map();
|
|
2353
|
-
caches = new Map();
|
|
2356
|
+
schemas = /* @__PURE__ */ new Map();
|
|
2357
|
+
caches = /* @__PURE__ */ new Map();
|
|
2354
2358
|
constructor(config, swaggerSchemaResolver) {
|
|
2355
2359
|
this.config = config;
|
|
2356
2360
|
this.swaggerSchemaResolver = swaggerSchemaResolver;
|
|
@@ -2365,8 +2369,8 @@ var SchemaWalker = class {
|
|
|
2365
2369
|
return ref.startsWith("http://") || ref.startsWith("https://");
|
|
2366
2370
|
};
|
|
2367
2371
|
_getRefDataFromSchema = (schema, ref) => {
|
|
2368
|
-
const path$
|
|
2369
|
-
const refData = lodash.get(schema, path$
|
|
2372
|
+
const path$2 = ref.replace("#", "").split("/");
|
|
2373
|
+
const refData = lodash.get(schema, path$2);
|
|
2370
2374
|
if (refData) this.caches.set(ref, refData);
|
|
2371
2375
|
return refData;
|
|
2372
2376
|
};
|
|
@@ -2379,15 +2383,15 @@ var Request = class {
|
|
|
2379
2383
|
constructor(config) {
|
|
2380
2384
|
this.config = config;
|
|
2381
2385
|
}
|
|
2382
|
-
async download({ url: url$
|
|
2386
|
+
async download({ url: url$2, authToken,...options }) {
|
|
2383
2387
|
const requestOptions = {};
|
|
2384
2388
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2385
2389
|
lodash.merge(requestOptions, options, this.config.requestOptions);
|
|
2386
2390
|
try {
|
|
2387
|
-
const response = await fetch(url$
|
|
2391
|
+
const response = await fetch(url$2, requestOptions);
|
|
2388
2392
|
return await response.text();
|
|
2389
2393
|
} catch (error) {
|
|
2390
|
-
const message = `error while fetching data from URL "${url$
|
|
2394
|
+
const message = `error while fetching data from URL "${url$2}"`;
|
|
2391
2395
|
consola.error(message, error);
|
|
2392
2396
|
return message;
|
|
2393
2397
|
}
|
|
@@ -2406,9 +2410,9 @@ var SwaggerSchemaResolver = class {
|
|
|
2406
2410
|
this.request = new Request(config);
|
|
2407
2411
|
}
|
|
2408
2412
|
async create() {
|
|
2409
|
-
const { spec, patch, input, url: url$
|
|
2413
|
+
const { spec, patch, input, url: url$2, authorizationToken } = this.config;
|
|
2410
2414
|
if (spec) return await this.convertSwaggerObject(spec, { patch });
|
|
2411
|
-
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url$
|
|
2415
|
+
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url$2, authorizationToken);
|
|
2412
2416
|
const swaggerSchemaObject = this.processSwaggerSchemaFile(swaggerSchemaFile);
|
|
2413
2417
|
return await this.convertSwaggerObject(swaggerSchemaObject, { patch });
|
|
2414
2418
|
}
|
|
@@ -2486,6 +2490,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2486
2490
|
|
|
2487
2491
|
//#endregion
|
|
2488
2492
|
//#region src/templates-worker.ts
|
|
2493
|
+
const require = module.createRequire(import.meta.url);
|
|
2489
2494
|
var TemplatesWorker = class {
|
|
2490
2495
|
config;
|
|
2491
2496
|
fileSystem;
|
|
@@ -2498,12 +2503,12 @@ var TemplatesWorker = class {
|
|
|
2498
2503
|
if (this.config.silent) consola.level = 0;
|
|
2499
2504
|
}
|
|
2500
2505
|
getTemplatePaths = (config) => {
|
|
2501
|
-
const __dirname$1 = path$
|
|
2502
|
-
const baseTemplatesPath = path$
|
|
2503
|
-
const defaultTemplatesPath = path$
|
|
2504
|
-
const modularTemplatesPath = path$
|
|
2506
|
+
const __dirname$1 = path$1.dirname(url$1.fileURLToPath(import.meta.url));
|
|
2507
|
+
const baseTemplatesPath = path$1.resolve(__dirname$1, "../templates/base");
|
|
2508
|
+
const defaultTemplatesPath = path$1.resolve(__dirname$1, "../templates/default");
|
|
2509
|
+
const modularTemplatesPath = path$1.resolve(__dirname$1, "../templates/modular");
|
|
2505
2510
|
const originalTemplatesPath = config.modular ? modularTemplatesPath : defaultTemplatesPath;
|
|
2506
|
-
const customTemplatesPath = config.templates && path$
|
|
2511
|
+
const customTemplatesPath = config.templates && path$1.resolve(process.cwd(), config.templates);
|
|
2507
2512
|
return {
|
|
2508
2513
|
base: baseTemplatesPath,
|
|
2509
2514
|
default: defaultTemplatesPath,
|
|
@@ -2512,20 +2517,20 @@ var TemplatesWorker = class {
|
|
|
2512
2517
|
custom: customTemplatesPath
|
|
2513
2518
|
};
|
|
2514
2519
|
};
|
|
2515
|
-
cropExtension = (path$
|
|
2520
|
+
cropExtension = (path$2) => this.config.templateExtensions.reduce((path$3, ext) => path$3.endsWith(ext) ? path$3.replace(ext, "") : path$3, path$2);
|
|
2516
2521
|
getTemplateFullPath = (path_, fileName) => {
|
|
2517
|
-
const raw = path$
|
|
2522
|
+
const raw = path$1.resolve(path_, "./", this.cropExtension(fileName));
|
|
2518
2523
|
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
|
|
2519
2524
|
return pathVariants.find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
2520
2525
|
};
|
|
2521
|
-
requireFnFromTemplate =
|
|
2526
|
+
requireFnFromTemplate = (packageOrPath) => {
|
|
2522
2527
|
const isPath = packageOrPath.startsWith("./") || packageOrPath.startsWith("../");
|
|
2523
|
-
if (isPath) return
|
|
2524
|
-
return
|
|
2528
|
+
if (isPath) return require(path$1.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2529
|
+
return require(packageOrPath);
|
|
2525
2530
|
};
|
|
2526
|
-
getTemplate = (name$1, fileName, path$
|
|
2531
|
+
getTemplate = (name$1, fileName, path$2) => {
|
|
2527
2532
|
const { templatePaths } = this.config;
|
|
2528
|
-
if (path$
|
|
2533
|
+
if (path$2) return this.fileSystem.getFileContent(path$2);
|
|
2529
2534
|
if (!fileName) return "";
|
|
2530
2535
|
const customFullPath = templatePaths.custom && this.getTemplateFullPath(templatePaths.custom, fileName);
|
|
2531
2536
|
let fileContent = customFullPath && this.fileSystem.getFileContent(customFullPath);
|
|
@@ -2548,21 +2553,21 @@ var TemplatesWorker = class {
|
|
|
2548
2553
|
[name$1]: this.getTemplate(name$1, fileName)
|
|
2549
2554
|
}), {});
|
|
2550
2555
|
};
|
|
2551
|
-
findTemplateWithExt = (path$
|
|
2552
|
-
const raw = this.cropExtension(path$
|
|
2556
|
+
findTemplateWithExt = (path$2) => {
|
|
2557
|
+
const raw = this.cropExtension(path$2);
|
|
2553
2558
|
const pathVariants = this.config.templateExtensions.map((extension) => `${raw}${extension}`);
|
|
2554
2559
|
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2555
2560
|
};
|
|
2556
2561
|
getTemplateContent = (path_) => {
|
|
2557
2562
|
const foundTemplatePathKey = lodash.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
2558
2563
|
if (foundTemplatePathKey) {
|
|
2559
|
-
const rawPath = path$
|
|
2564
|
+
const rawPath = path$1.resolve(path_.replace(`@${foundTemplatePathKey}`, lodash.get(this.config.templatePaths, foundTemplatePathKey)));
|
|
2560
2565
|
const fixedPath = this.findTemplateWithExt(rawPath);
|
|
2561
2566
|
if (fixedPath) return this.fileSystem.getFileContent(fixedPath);
|
|
2562
2567
|
}
|
|
2563
|
-
const customPath = this.config.templatePaths.custom && this.findTemplateWithExt(path$
|
|
2568
|
+
const customPath = this.config.templatePaths.custom && this.findTemplateWithExt(path$1.resolve(this.config.templatePaths.custom, path_));
|
|
2564
2569
|
if (customPath) return this.fileSystem.getFileContent(customPath);
|
|
2565
|
-
const originalPath = this.findTemplateWithExt(path$
|
|
2570
|
+
const originalPath = this.findTemplateWithExt(path$1.resolve(this.config.templatePaths.original, path_));
|
|
2566
2571
|
if (originalPath) return this.fileSystem.getFileContent(originalPath);
|
|
2567
2572
|
return "";
|
|
2568
2573
|
};
|
|
@@ -2574,8 +2579,8 @@ var TemplatesWorker = class {
|
|
|
2574
2579
|
}, {
|
|
2575
2580
|
async: false,
|
|
2576
2581
|
...options,
|
|
2577
|
-
includeFile: (path$
|
|
2578
|
-
return this.renderTemplate(this.getTemplateContent(path$
|
|
2582
|
+
includeFile: (path$2, configuration$1, options$1 = {}) => {
|
|
2583
|
+
return this.renderTemplate(this.getTemplateContent(path$2), configuration$1, options$1);
|
|
2579
2584
|
}
|
|
2580
2585
|
});
|
|
2581
2586
|
};
|
|
@@ -2601,23 +2606,23 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2601
2606
|
compileTSCode = (input) => {
|
|
2602
2607
|
const fileNameFull = `${input.fileName}${input.fileExtension}`;
|
|
2603
2608
|
const output = {};
|
|
2604
|
-
const host = typescript
|
|
2609
|
+
const host = typescript.createCompilerHost(this.config.compilerTsConfig, true);
|
|
2605
2610
|
const fileNames = [fileNameFull];
|
|
2606
2611
|
const originalSourceFileGet = host.getSourceFile.bind(host);
|
|
2607
2612
|
host.getSourceFile = (sourceFileName, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
2608
2613
|
if (sourceFileName !== fileNameFull) return originalSourceFileGet(sourceFileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
2609
|
-
return typescript
|
|
2614
|
+
return typescript.createSourceFile(sourceFileName, input.fileContent, languageVersion, true, typescript.ScriptKind.TS);
|
|
2610
2615
|
};
|
|
2611
2616
|
host.writeFile = (fileName, contents) => {
|
|
2612
2617
|
output[fileName] = contents;
|
|
2613
2618
|
};
|
|
2614
|
-
typescript
|
|
2619
|
+
typescript.createProgram(fileNames, this.config.compilerTsConfig, host).emit();
|
|
2615
2620
|
return output;
|
|
2616
2621
|
};
|
|
2617
2622
|
translate = async (input) => {
|
|
2618
2623
|
const compiled = this.compileTSCode(input);
|
|
2619
|
-
const jsFileName = `${input.fileName}${typescript
|
|
2620
|
-
const dtsFileName = `${input.fileName}${typescript
|
|
2624
|
+
const jsFileName = `${input.fileName}${typescript.Extension.Js}`;
|
|
2625
|
+
const dtsFileName = `${input.fileName}${typescript.Extension.Dts}`;
|
|
2621
2626
|
const sourceContent = compiled[jsFileName];
|
|
2622
2627
|
const tsImportRows = input.fileContent.split("\n").filter((line) => line.startsWith("import "));
|
|
2623
2628
|
const declarationContent = compiled[dtsFileName].split("\n").map((line) => {
|
|
@@ -2626,11 +2631,11 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2626
2631
|
}).join("\n");
|
|
2627
2632
|
return [{
|
|
2628
2633
|
fileName: input.fileName,
|
|
2629
|
-
fileExtension: typescript
|
|
2634
|
+
fileExtension: typescript.Extension.Js,
|
|
2630
2635
|
fileContent: await this.codeFormatter.formatCode(sourceContent)
|
|
2631
2636
|
}, {
|
|
2632
2637
|
fileName: input.fileName,
|
|
2633
|
-
fileExtension: typescript
|
|
2638
|
+
fileExtension: typescript.Extension.Dts,
|
|
2634
2639
|
fileContent: await this.codeFormatter.formatCode(declarationContent)
|
|
2635
2640
|
}];
|
|
2636
2641
|
};
|
|
@@ -2639,7 +2644,7 @@ var JavascriptTranslator = class extends Translator {
|
|
|
2639
2644
|
//#endregion
|
|
2640
2645
|
//#region src/type-name-formatter.ts
|
|
2641
2646
|
var TypeNameFormatter = class {
|
|
2642
|
-
formattedModelNamesMap = new Map();
|
|
2647
|
+
formattedModelNamesMap = /* @__PURE__ */ new Map();
|
|
2643
2648
|
config;
|
|
2644
2649
|
constructor(config) {
|
|
2645
2650
|
this.config = config;
|
|
@@ -2682,16 +2687,16 @@ var TypeNameFormatter = class {
|
|
|
2682
2687
|
//#endregion
|
|
2683
2688
|
//#region src/util/file-system.ts
|
|
2684
2689
|
var FileSystem = class {
|
|
2685
|
-
getFileContent = (path$
|
|
2686
|
-
return fs.readFileSync(path$
|
|
2690
|
+
getFileContent = (path$2) => {
|
|
2691
|
+
return fs.readFileSync(path$2, { encoding: "utf8" });
|
|
2687
2692
|
};
|
|
2688
|
-
readDir = (path$
|
|
2689
|
-
return fs.readdirSync(path$
|
|
2693
|
+
readDir = (path$2) => {
|
|
2694
|
+
return fs.readdirSync(path$2);
|
|
2690
2695
|
};
|
|
2691
|
-
pathIsDir = (path$
|
|
2692
|
-
if (!path$
|
|
2696
|
+
pathIsDir = (path$2) => {
|
|
2697
|
+
if (!path$2) return false;
|
|
2693
2698
|
try {
|
|
2694
|
-
const stat = fs.statSync(path$
|
|
2699
|
+
const stat = fs.statSync(path$2);
|
|
2695
2700
|
return stat.isDirectory();
|
|
2696
2701
|
} catch (e) {
|
|
2697
2702
|
return false;
|
|
@@ -2702,27 +2707,27 @@ var FileSystem = class {
|
|
|
2702
2707
|
if (fileNameParts.length > 1) fileNameParts.pop();
|
|
2703
2708
|
return fileNameParts.join(".");
|
|
2704
2709
|
};
|
|
2705
|
-
removeDir = (path$
|
|
2710
|
+
removeDir = (path$2) => {
|
|
2706
2711
|
try {
|
|
2707
|
-
if (typeof fs.rmSync === "function") fs.rmSync(path$
|
|
2708
|
-
else fs.rmdirSync(path$
|
|
2712
|
+
if (typeof fs.rmSync === "function") fs.rmSync(path$2, { recursive: true });
|
|
2713
|
+
else fs.rmdirSync(path$2, { recursive: true });
|
|
2709
2714
|
} catch (e) {
|
|
2710
2715
|
consola.debug("failed to remove dir", e);
|
|
2711
2716
|
}
|
|
2712
2717
|
};
|
|
2713
|
-
createDir = (path$
|
|
2718
|
+
createDir = (path$2) => {
|
|
2714
2719
|
try {
|
|
2715
|
-
fs.mkdirSync(path$
|
|
2720
|
+
fs.mkdirSync(path$2, { recursive: true });
|
|
2716
2721
|
} catch (e) {
|
|
2717
2722
|
consola.debug("failed to create dir", e);
|
|
2718
2723
|
}
|
|
2719
2724
|
};
|
|
2720
|
-
cleanDir = (path$
|
|
2721
|
-
this.removeDir(path$
|
|
2722
|
-
this.createDir(path$
|
|
2725
|
+
cleanDir = (path$2) => {
|
|
2726
|
+
this.removeDir(path$2);
|
|
2727
|
+
this.createDir(path$2);
|
|
2723
2728
|
};
|
|
2724
|
-
pathIsExist = (path$
|
|
2725
|
-
return !!path$
|
|
2729
|
+
pathIsExist = (path$2) => {
|
|
2730
|
+
return !!path$2 && fs.existsSync(path$2);
|
|
2726
2731
|
};
|
|
2727
2732
|
createFile = ({ path: path_, fileName, content, withPrefix }) => {
|
|
2728
2733
|
const __dirname$1 = path$1.dirname(url$1.fileURLToPath(import.meta.url));
|
|
@@ -3028,6 +3033,32 @@ var CodeGenProcess = class {
|
|
|
3028
3033
|
};
|
|
3029
3034
|
};
|
|
3030
3035
|
|
|
3036
|
+
//#endregion
|
|
3037
|
+
//#region types/index.ts
|
|
3038
|
+
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind$1) {
|
|
3039
|
+
RequestContentKind$1["JSON"] = "JSON";
|
|
3040
|
+
RequestContentKind$1["URL_ENCODED"] = "URL_ENCODED";
|
|
3041
|
+
RequestContentKind$1["FORM_DATA"] = "FORM_DATA";
|
|
3042
|
+
RequestContentKind$1["IMAGE"] = "IMAGE";
|
|
3043
|
+
RequestContentKind$1["OTHER"] = "OTHER";
|
|
3044
|
+
RequestContentKind$1["TEXT"] = "TEXT";
|
|
3045
|
+
return RequestContentKind$1;
|
|
3046
|
+
}({});
|
|
3047
|
+
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES$2) {
|
|
3048
|
+
SCHEMA_TYPES$2["ARRAY"] = "array";
|
|
3049
|
+
SCHEMA_TYPES$2["OBJECT"] = "object";
|
|
3050
|
+
SCHEMA_TYPES$2["ENUM"] = "enum";
|
|
3051
|
+
SCHEMA_TYPES$2["REF"] = "$ref";
|
|
3052
|
+
SCHEMA_TYPES$2["PRIMITIVE"] = "primitive";
|
|
3053
|
+
SCHEMA_TYPES$2["COMPLEX"] = "complex";
|
|
3054
|
+
SCHEMA_TYPES$2["COMPLEX_ONE_OF"] = "oneOf";
|
|
3055
|
+
SCHEMA_TYPES$2["COMPLEX_ANY_OF"] = "anyOf";
|
|
3056
|
+
SCHEMA_TYPES$2["COMPLEX_ALL_OF"] = "allOf";
|
|
3057
|
+
SCHEMA_TYPES$2["COMPLEX_NOT"] = "not";
|
|
3058
|
+
SCHEMA_TYPES$2["COMPLEX_UNKNOWN"] = "__unknown";
|
|
3059
|
+
return SCHEMA_TYPES$2;
|
|
3060
|
+
}({});
|
|
3061
|
+
|
|
3031
3062
|
//#endregion
|
|
3032
3063
|
//#region src/commands/generate-templates/configuration.ts
|
|
3033
3064
|
var TemplatesGenConfig = class {
|
|
@@ -3169,5 +3200,5 @@ async function generateApi(config) {
|
|
|
3169
3200
|
}
|
|
3170
3201
|
|
|
3171
3202
|
//#endregion
|
|
3172
|
-
export { CodeGenConfig, HTTP_CLIENT, TemplatesGenConfig, constants_exports, generateApi, generateTemplates, package_default };
|
|
3173
|
-
//# sourceMappingURL=src-
|
|
3203
|
+
export { CodeGenConfig, HTTP_CLIENT, RequestContentKind, SCHEMA_TYPES, TemplatesGenConfig, constants_exports, generateApi, generateTemplates, package_default };
|
|
3204
|
+
//# sourceMappingURL=src-s8addnrG.js.map
|