swagger-typescript-api 13.2.16 → 13.2.17
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/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/cli.cjs +14 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/{cli.js → cli.mjs} +3 -2
- package/dist/cli.mjs.map +1 -0
- package/dist/{src-D-LZ3PGk.js → generate-templates-BO-5CKCm.mjs} +338 -347
- package/dist/generate-templates-BO-5CKCm.mjs.map +1 -0
- package/dist/{src-DWf638kx.cjs → generate-templates-wjE78AWV.cjs} +366 -369
- package/dist/generate-templates-wjE78AWV.cjs.map +1 -0
- package/dist/index.cjs +17 -6
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +105 -223
- package/dist/index.d.cts.map +1 -1
- package/dist/{index.d.ts → index.d.mts} +105 -224
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +23 -28
- package/templates/default/procedure-call.ejs +1 -1
- package/templates/modular/procedure-call.ejs +1 -1
- package/CHANGELOG.md +0 -1770
- package/dist/chunk-Bp6m_JJh.js +0 -13
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/src-D-LZ3PGk.js.map +0 -1
- package/dist/src-DWf638kx.cjs.map +0 -1
- /package/dist/{cli.d.ts → cli.d.mts} +0 -0
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
9
|
let target = {};
|
|
10
|
-
for (var name
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
for (var name in all) {
|
|
11
|
+
__defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (!no_symbols) {
|
|
17
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
}
|
|
14
19
|
return target;
|
|
15
20
|
};
|
|
16
21
|
var __copyProps = (to, from, except, desc) => {
|
|
17
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
24
|
+
key = keys[i];
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
26
|
+
__defProp(to, key, {
|
|
27
|
+
get: ((k) => from[k]).bind(null, key),
|
|
28
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
return to;
|
|
25
34
|
};
|
|
@@ -30,17 +39,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
39
|
|
|
31
40
|
//#endregion
|
|
32
41
|
let consola = require("consola");
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
let es_toolkit = require("es-toolkit");
|
|
43
|
+
es_toolkit = __toESM(es_toolkit);
|
|
44
|
+
let es_toolkit_compat = require("es-toolkit/compat");
|
|
45
|
+
es_toolkit_compat = __toESM(es_toolkit_compat);
|
|
36
46
|
let typescript = require("typescript");
|
|
37
47
|
typescript = __toESM(typescript);
|
|
38
48
|
let node_path = require("node:path");
|
|
39
49
|
node_path = __toESM(node_path);
|
|
40
|
-
let
|
|
41
|
-
__biomejs_js_api = __toESM(__biomejs_js_api);
|
|
50
|
+
let _biomejs_js_api = require("@biomejs/js-api");
|
|
42
51
|
let nanoid = require("nanoid");
|
|
43
52
|
nanoid = __toESM(nanoid);
|
|
53
|
+
let node_crypto = require("node:crypto");
|
|
54
|
+
node_crypto = __toESM(node_crypto);
|
|
44
55
|
let swagger2openapi = require("swagger2openapi");
|
|
45
56
|
swagger2openapi = __toESM(swagger2openapi);
|
|
46
57
|
let yaml = require("yaml");
|
|
@@ -50,7 +61,6 @@ node_module = __toESM(node_module);
|
|
|
50
61
|
let node_url = require("node:url");
|
|
51
62
|
node_url = __toESM(node_url);
|
|
52
63
|
let eta = require("eta");
|
|
53
|
-
eta = __toESM(eta);
|
|
54
64
|
let node_fs = require("node:fs");
|
|
55
65
|
node_fs = __toESM(node_fs);
|
|
56
66
|
|
|
@@ -67,11 +77,11 @@ var CodeFormatter = class {
|
|
|
67
77
|
type: "file",
|
|
68
78
|
fileName: tempFileName
|
|
69
79
|
}, { newLineCharacter: typescript.sys.newLine }, void 0)[0];
|
|
70
|
-
if (fileTextChanges?.textChanges.length) return fileTextChanges.textChanges.reduceRight((content
|
|
80
|
+
if (fileTextChanges?.textChanges.length) return fileTextChanges.textChanges.reduceRight((content, { span, newText }) => `${content.slice(0, span.start)}${newText}${content.slice(span.start + span.length)}`, content);
|
|
71
81
|
return content;
|
|
72
82
|
};
|
|
73
83
|
format = async (content) => {
|
|
74
|
-
const biome = await
|
|
84
|
+
const biome = await _biomejs_js_api.Biome.create({ distribution: _biomejs_js_api.Distribution.NODE });
|
|
75
85
|
const biomeProject = biome.openProject();
|
|
76
86
|
biome.applyConfiguration(biomeProject.projectKey, {
|
|
77
87
|
files: { maxSize: Number.MAX_SAFE_INTEGER },
|
|
@@ -123,8 +133,8 @@ var TsLanguageServiceHost = class {
|
|
|
123
133
|
if (fileName === this.fileName) return this.content;
|
|
124
134
|
return typescript.sys.readFile(fileName, encoding);
|
|
125
135
|
}
|
|
126
|
-
fileExists(path
|
|
127
|
-
return typescript.sys.fileExists(path
|
|
136
|
+
fileExists(path) {
|
|
137
|
+
return typescript.sys.fileExists(path);
|
|
128
138
|
}
|
|
129
139
|
};
|
|
130
140
|
|
|
@@ -140,14 +150,14 @@ var NameResolver = class {
|
|
|
140
150
|
this.reserve(reservedNames);
|
|
141
151
|
}
|
|
142
152
|
reserve(names) {
|
|
143
|
-
const fixedNames =
|
|
144
|
-
for (const name
|
|
153
|
+
const fixedNames = (0, es_toolkit.uniq)((0, es_toolkit.compact)(names));
|
|
154
|
+
for (const name of fixedNames) if (this.reservedNames.indexOf(name) === -1) this.reservedNames.push(name);
|
|
145
155
|
}
|
|
146
156
|
unreserve(names) {
|
|
147
|
-
this.reservedNames = this.reservedNames.filter((reservedName) => !names.some((name
|
|
157
|
+
this.reservedNames = this.reservedNames.filter((reservedName) => !names.some((name) => name === reservedName));
|
|
148
158
|
}
|
|
149
|
-
isReserved(name
|
|
150
|
-
return this.reservedNames.some((reservedName) => reservedName === name
|
|
159
|
+
isReserved(name) {
|
|
160
|
+
return this.reservedNames.some((reservedName) => reservedName === name);
|
|
151
161
|
}
|
|
152
162
|
resolve(variants, resolver, extras, shouldReserve = true) {
|
|
153
163
|
if (typeof resolver === "function") {
|
|
@@ -165,7 +175,7 @@ var NameResolver = class {
|
|
|
165
175
|
}
|
|
166
176
|
if (Array.isArray(variants)) {
|
|
167
177
|
let usageName = null;
|
|
168
|
-
const uniqVariants =
|
|
178
|
+
const uniqVariants = (0, es_toolkit.uniq)((0, es_toolkit.compact)(variants));
|
|
169
179
|
for (const variant of uniqVariants) if (!usageName && (!shouldReserve || !this.isReserved(variant))) usageName = variant;
|
|
170
180
|
if (usageName) {
|
|
171
181
|
shouldReserve && this.reserve([usageName]);
|
|
@@ -181,12 +191,9 @@ var NameResolver = class {
|
|
|
181
191
|
|
|
182
192
|
//#endregion
|
|
183
193
|
//#region src/util/random.ts
|
|
184
|
-
const getRandomFloat = (min = 0, max = 1) => {
|
|
185
|
-
return Math.random() * (max - min) + min;
|
|
186
|
-
};
|
|
187
194
|
const getRandomInt = (min = 0, max = 1) => {
|
|
188
195
|
if (min === max) return min;
|
|
189
|
-
return Math.round(
|
|
196
|
+
return Math.round(Math.random() * (max - min) + min);
|
|
190
197
|
};
|
|
191
198
|
|
|
192
199
|
//#endregion
|
|
@@ -216,12 +223,12 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
216
223
|
//#endregion
|
|
217
224
|
//#region package.json
|
|
218
225
|
var name = "swagger-typescript-api";
|
|
219
|
-
var version = "13.2.
|
|
226
|
+
var version = "13.2.17";
|
|
220
227
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
221
228
|
|
|
222
229
|
//#endregion
|
|
223
230
|
//#region src/constants.ts
|
|
224
|
-
var constants_exports = /* @__PURE__ */
|
|
231
|
+
var constants_exports = /* @__PURE__ */ __exportAll({
|
|
225
232
|
DEFAULT_BODY_ARG_NAME: () => DEFAULT_BODY_ARG_NAME,
|
|
226
233
|
FILE_PREFIX: () => FILE_PREFIX,
|
|
227
234
|
HTTP_CLIENT: () => HTTP_CLIENT,
|
|
@@ -285,16 +292,6 @@ const SCHEMA_TYPES$1 = {
|
|
|
285
292
|
COMPLEX_UNKNOWN: "__unknown"
|
|
286
293
|
};
|
|
287
294
|
|
|
288
|
-
//#endregion
|
|
289
|
-
//#region src/util/object-assign.ts
|
|
290
|
-
const objectAssign = (target, updater) => {
|
|
291
|
-
if (!updater) return;
|
|
292
|
-
const update = typeof updater === "function" ? updater(target) : updater;
|
|
293
|
-
const undefinedKeys = lodash.default.map(update, (value, key) => value === void 0 && key).filter((key) => typeof key === "string");
|
|
294
|
-
Object.assign(target, lodash.default.merge(target, update));
|
|
295
|
-
for (const key of undefinedKeys) target[key] = void 0;
|
|
296
|
-
};
|
|
297
|
-
|
|
298
295
|
//#endregion
|
|
299
296
|
//#region src/configuration.ts
|
|
300
297
|
const TsKeyword = {
|
|
@@ -495,11 +492,11 @@ var CodeGenConfig = class {
|
|
|
495
492
|
BooleanValue: (content) => `${content}`,
|
|
496
493
|
NumberValue: (content) => `${content}`,
|
|
497
494
|
NullValue: () => "null",
|
|
498
|
-
UnionType: (contents) =>
|
|
495
|
+
UnionType: (contents) => (0, es_toolkit.uniq)(contents).join(` ${this.Ts.Keyword.Union} `),
|
|
499
496
|
ExpressionGroup: (content) => content ? `(${content})` : "",
|
|
500
|
-
IntersectionType: (contents) =>
|
|
497
|
+
IntersectionType: (contents) => (0, es_toolkit.uniq)(contents).join(` ${this.Ts.Keyword.Intersection} `),
|
|
501
498
|
RecordType: (key, value) => this.Ts.TypeWithGeneric(this.Ts.Keyword.Record, [key, value]),
|
|
502
|
-
TypeField: ({ readonly, key, optional, value }) =>
|
|
499
|
+
TypeField: ({ readonly, key, optional, value }) => (0, es_toolkit.compact)([
|
|
503
500
|
readonly && "readonly ",
|
|
504
501
|
key,
|
|
505
502
|
optional && "?",
|
|
@@ -509,12 +506,12 @@ var CodeGenConfig = class {
|
|
|
509
506
|
InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
|
|
510
507
|
EnumUsageKey: (enumStruct, key) => `${enumStruct}.${key}`,
|
|
511
508
|
EnumField: (key, value) => `${key} = ${value}`,
|
|
512
|
-
EnumFieldDescription: (description
|
|
513
|
-
if (description
|
|
509
|
+
EnumFieldDescription: (description) => {
|
|
510
|
+
if (description) return ` /** ${description} */`;
|
|
514
511
|
else return "";
|
|
515
512
|
},
|
|
516
|
-
EnumFieldsWrapper: (contents) =>
|
|
517
|
-
return [this.Ts.EnumFieldDescription(description
|
|
513
|
+
EnumFieldsWrapper: (contents) => contents.map(({ key, value, description }) => {
|
|
514
|
+
return (0, es_toolkit.compact)([this.Ts.EnumFieldDescription(description), ` ${this.Ts.EnumField(key, value)}`]).join("\n");
|
|
518
515
|
}).join(",\n"),
|
|
519
516
|
ObjectWrapper: (content) => `{\n${content}\n}`,
|
|
520
517
|
MultilineComment: (contents, formatFn) => [...contents.length === 1 ? [`/** ${contents[0]} */`] : [
|
|
@@ -604,13 +601,13 @@ var CodeGenConfig = class {
|
|
|
604
601
|
}
|
|
605
602
|
];
|
|
606
603
|
templateExtensions = [".eta", ".ejs"];
|
|
607
|
-
constructor({ codeGenConstructs, primitiveTypeConstructs, constants, templateInfos, hooks
|
|
608
|
-
|
|
609
|
-
|
|
604
|
+
constructor({ codeGenConstructs, primitiveTypeConstructs, constants, templateInfos, hooks, ...otherConfig }) {
|
|
605
|
+
Object.assign(this.Ts, codeGenConstructs);
|
|
606
|
+
Object.assign(this.primitiveTypes, primitiveTypeConstructs);
|
|
610
607
|
this.defaultResponseType = this.Ts.Keyword.Void;
|
|
611
608
|
this.update({
|
|
612
609
|
...otherConfig,
|
|
613
|
-
hooks:
|
|
610
|
+
hooks: (0, es_toolkit.merge)(this.hooks, hooks || {}),
|
|
614
611
|
constants: {
|
|
615
612
|
...constants_exports,
|
|
616
613
|
...constants
|
|
@@ -626,7 +623,7 @@ var CodeGenConfig = class {
|
|
|
626
623
|
this.componentTypeNameResolver = new ComponentTypeNameResolver(this, []);
|
|
627
624
|
}
|
|
628
625
|
update = (update) => {
|
|
629
|
-
|
|
626
|
+
Object.assign(this, update);
|
|
630
627
|
if (this.enumNamesAsValues) this.extractEnums = true;
|
|
631
628
|
};
|
|
632
629
|
};
|
|
@@ -731,7 +728,7 @@ var SchemaFormatters = class {
|
|
|
731
728
|
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
732
729
|
return {
|
|
733
730
|
...parsedSchema,
|
|
734
|
-
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType(
|
|
731
|
+
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType((0, es_toolkit.compact)([...parsedSchema.content.map(({ value }) => `${value}`), parsedSchema.nullable && this.config.Ts.Keyword.Null])) || this.config.Ts.Keyword.Any
|
|
735
732
|
};
|
|
736
733
|
},
|
|
737
734
|
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
@@ -748,14 +745,14 @@ var SchemaFormatters = class {
|
|
|
748
745
|
}
|
|
749
746
|
};
|
|
750
747
|
formatSchema = (parsedSchema, formatType = "base") => {
|
|
751
|
-
const schemaType =
|
|
752
|
-
return
|
|
748
|
+
const schemaType = (0, es_toolkit_compat.get)(parsedSchema, ["schemaType"]) || (0, es_toolkit_compat.get)(parsedSchema, ["$parsed", "schemaType"]);
|
|
749
|
+
return (0, es_toolkit_compat.get)(this, [formatType, schemaType])?.(parsedSchema) || parsedSchema;
|
|
753
750
|
};
|
|
754
|
-
formatDescription = (description
|
|
755
|
-
if (!description
|
|
756
|
-
if (!description
|
|
757
|
-
if (inline) return
|
|
758
|
-
return description
|
|
751
|
+
formatDescription = (description, inline) => {
|
|
752
|
+
if (!description) return "";
|
|
753
|
+
if (!description.includes("\n")) return description;
|
|
754
|
+
if (inline) return (0, es_toolkit.compact)(description.split(/\n/g).map((part) => part.trim())).join(" ");
|
|
755
|
+
return description.replace(/\n$/g, "");
|
|
759
756
|
};
|
|
760
757
|
formatObjectContent = (content) => {
|
|
761
758
|
const fields = [];
|
|
@@ -816,7 +813,7 @@ var MonoSchemaParser = class {
|
|
|
816
813
|
var ArraySchemaParser = class extends MonoSchemaParser {
|
|
817
814
|
parse() {
|
|
818
815
|
let contentType;
|
|
819
|
-
const { type, description
|
|
816
|
+
const { type, description, items } = this.schema || {};
|
|
820
817
|
if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) {
|
|
821
818
|
const tupleContent = [];
|
|
822
819
|
for (const item of items) tupleContent.push(this.schemaParserFabric.createSchemaParser({
|
|
@@ -839,7 +836,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
839
836
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
840
837
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
841
838
|
name: this.typeName,
|
|
842
|
-
description: this.schemaFormatters.formatDescription(description
|
|
839
|
+
description: this.schemaFormatters.formatDescription(description),
|
|
843
840
|
content: this.schemaUtils.safeAddNullToType(this.schema, contentType)
|
|
844
841
|
};
|
|
845
842
|
}
|
|
@@ -850,7 +847,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
850
847
|
var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
851
848
|
parse() {
|
|
852
849
|
const complexType = this.schemaUtils.getComplexType(this.schema);
|
|
853
|
-
const simpleSchema =
|
|
850
|
+
const simpleSchema = (0, es_toolkit.omit)(this.schema, Object.keys(this.schemaParser._complexSchemaParsers));
|
|
854
851
|
const complexSchemaContent = this.schemaParser._complexSchemaParsers[complexType](this.schema);
|
|
855
852
|
return {
|
|
856
853
|
...typeof this.schema === "object" ? this.schema : {},
|
|
@@ -860,8 +857,8 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
860
857
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
861
858
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
862
859
|
name: this.typeName,
|
|
863
|
-
description: this.schemaFormatters.formatDescription(this.schema.description ||
|
|
864
|
-
content: this.config.Ts.IntersectionType(
|
|
860
|
+
description: this.schemaFormatters.formatDescription(this.schema.description || (0, es_toolkit.compact)((this.schema[complexType] || []).map((item) => item?.description))[0] || ""),
|
|
861
|
+
content: this.config.Ts.IntersectionType((0, es_toolkit.compact)([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES$1.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
865
862
|
schema: simpleSchema,
|
|
866
863
|
schemaPath: this.schemaPath
|
|
867
864
|
}).getInlineParseContent())])) || this.config.Ts.Keyword.Any
|
|
@@ -874,7 +871,7 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
874
871
|
var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
875
872
|
parse() {
|
|
876
873
|
const ts = this.config.Ts;
|
|
877
|
-
const { discriminator
|
|
874
|
+
const { discriminator, ...noDiscriminatorSchema } = this.schema;
|
|
878
875
|
if (!discriminator.mapping) return this.schemaParserFabric.createSchemaParser({
|
|
879
876
|
schema: noDiscriminatorSchema,
|
|
880
877
|
typeName: this.typeName,
|
|
@@ -886,7 +883,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
886
883
|
skipMappingType,
|
|
887
884
|
abstractSchemaStruct
|
|
888
885
|
});
|
|
889
|
-
const schemaContent = ts.IntersectionType([abstractSchemaStruct?.content, discriminatorSchemaStruct?.content]
|
|
886
|
+
const schemaContent = ts.IntersectionType((0, es_toolkit.compact)([abstractSchemaStruct?.content, discriminatorSchemaStruct?.content]));
|
|
890
887
|
return {
|
|
891
888
|
...typeof this.schema === "object" ? this.schema : {},
|
|
892
889
|
$schemaPath: this.schemaPath.slice(),
|
|
@@ -907,7 +904,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
907
904
|
this.typeName
|
|
908
905
|
]);
|
|
909
906
|
const { discriminator } = this.schema;
|
|
910
|
-
const mappingEntries =
|
|
907
|
+
const mappingEntries = Object.entries(discriminator.mapping || {});
|
|
911
908
|
const ableToCreateMappingType = !skipMappingType && !!(abstractSchemaStruct?.typeName && mappingEntries.length);
|
|
912
909
|
const mappingContents = [];
|
|
913
910
|
let mappingTypeName;
|
|
@@ -967,22 +964,24 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
967
964
|
};
|
|
968
965
|
createMappingPropertySchemaEnumKeys = ({ abstractSchemaStruct, discPropertyName }) => {
|
|
969
966
|
const ts = this.config.Ts;
|
|
970
|
-
|
|
971
|
-
let mappingPropertySchema =
|
|
967
|
+
const mappingPropertySchemaEnumKeysMap = {};
|
|
968
|
+
let mappingPropertySchema = (0, es_toolkit_compat.get)(abstractSchemaStruct?.component?.rawTypeData, ["properties", discPropertyName]);
|
|
972
969
|
if (this.schemaUtils.isRefSchema(mappingPropertySchema)) mappingPropertySchema = this.schemaUtils.getSchemaRefType(mappingPropertySchema);
|
|
973
970
|
const parsedEnum = mappingPropertySchema?.rawTypeData?.$parsed;
|
|
974
|
-
if (parsedEnum?.type === SCHEMA_TYPES$1.ENUM)
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
const
|
|
978
|
-
if (
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
971
|
+
if (parsedEnum?.type === SCHEMA_TYPES$1.ENUM) {
|
|
972
|
+
const enumEntries = (parsedEnum.enum || []).map((key, index) => [key, index]);
|
|
973
|
+
for (const [key, index] of enumEntries) {
|
|
974
|
+
const enumContent = parsedEnum.content?.[index];
|
|
975
|
+
if (this.config.generateUnionEnums) {
|
|
976
|
+
const literalValue = enumContent?.value ?? (key !== void 0 ? ts.StringValue(key) : void 0);
|
|
977
|
+
if (literalValue !== void 0) mappingPropertySchemaEnumKeysMap[key] = literalValue;
|
|
978
|
+
} else if (parsedEnum.typeName && enumContent?.key) mappingPropertySchemaEnumKeysMap[key] = ts.EnumUsageKey(parsedEnum.typeName, enumContent.key);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
982
981
|
return mappingPropertySchemaEnumKeysMap;
|
|
983
982
|
};
|
|
984
983
|
mutateMappingDependentSchema = ({ discPropertyName, abstractSchemaStruct, mappingSchema, refPath, mappingPropertySchemaEnumKeysMap }) => {
|
|
985
|
-
const complexSchemaKeys =
|
|
984
|
+
const complexSchemaKeys = Object.keys(this.schemaParser._complexSchemaParsers);
|
|
986
985
|
if (mappingSchema.$ref && abstractSchemaStruct?.component?.$ref) {
|
|
987
986
|
const mappingRefSchema = this.schemaUtils.getSchemaRefType(mappingSchema)?.rawTypeData;
|
|
988
987
|
if (mappingRefSchema) {
|
|
@@ -1001,11 +1000,11 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1001
1000
|
}
|
|
1002
1001
|
};
|
|
1003
1002
|
createAbstractSchemaStruct = () => {
|
|
1004
|
-
const { discriminator
|
|
1005
|
-
const complexSchemaKeys =
|
|
1006
|
-
const schema =
|
|
1003
|
+
const { discriminator, ...noDiscriminatorSchema } = this.schema;
|
|
1004
|
+
const complexSchemaKeys = Object.keys(this.schemaParser._complexSchemaParsers);
|
|
1005
|
+
const schema = (0, es_toolkit.omit)(structuredClone(noDiscriminatorSchema), complexSchemaKeys);
|
|
1007
1006
|
const schemaIsAny = this.schemaParserFabric.getInlineParseContent(structuredClone(schema)) === this.config.Ts.Keyword.Any;
|
|
1008
|
-
if (!
|
|
1007
|
+
if (!Object.keys(schema).length || schemaIsAny) return null;
|
|
1009
1008
|
const typeName = this.schemaUtils.resolveTypeName(this.typeName, {
|
|
1010
1009
|
prefixes: this.config.extractingOptions.discriminatorAbstractPrefix,
|
|
1011
1010
|
resolver: this.config.extractingOptions.discriminatorAbstractResolver
|
|
@@ -1074,9 +1073,9 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1074
1073
|
const refType = this.schemaUtils.getSchemaRefType(this.schema);
|
|
1075
1074
|
const $ref = refType?.$ref || null;
|
|
1076
1075
|
if (Array.isArray(this.schema.enum)) this.schema.enum = this.schema.enum.filter((key) => key != null);
|
|
1077
|
-
if (Array.isArray(this.schema.enum) && Array.isArray(this.schema.enum[0])) return this.schemaParserFabric.parseSchema({ oneOf: this.schema.enum.map((enumNames
|
|
1076
|
+
if (Array.isArray(this.schema.enum) && Array.isArray(this.schema.enum[0])) return this.schemaParserFabric.parseSchema({ oneOf: this.schema.enum.map((enumNames) => ({
|
|
1078
1077
|
type: "array",
|
|
1079
|
-
items: enumNames
|
|
1078
|
+
items: enumNames.map((enumName) => ({
|
|
1080
1079
|
type: "string",
|
|
1081
1080
|
enum: [enumName]
|
|
1082
1081
|
}))
|
|
@@ -1101,8 +1100,8 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1101
1100
|
default: return this.config.Ts.StringValue(value);
|
|
1102
1101
|
}
|
|
1103
1102
|
};
|
|
1104
|
-
if (Array.isArray(enumNames) &&
|
|
1105
|
-
const enumValue =
|
|
1103
|
+
if (Array.isArray(enumNames) && enumNames.length > 0) content = enumNames.map((enumName, index) => {
|
|
1104
|
+
const enumValue = (0, es_toolkit_compat.get)(this.schema.enum, index);
|
|
1106
1105
|
const formattedKey = this.formatEnumKey({
|
|
1107
1106
|
key: enumName,
|
|
1108
1107
|
value: enumValue
|
|
@@ -1170,21 +1169,24 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1170
1169
|
}
|
|
1171
1170
|
getObjectSchemaContent = (schema) => {
|
|
1172
1171
|
const { properties, additionalProperties } = schema || {};
|
|
1173
|
-
const propertiesContent =
|
|
1174
|
-
|
|
1175
|
-
const
|
|
1172
|
+
const propertiesContent = [];
|
|
1173
|
+
for (const [name, property] of Object.entries(properties || {})) {
|
|
1174
|
+
const required = this.schemaUtils.isPropertyRequired(name, property, schema);
|
|
1175
|
+
const rawTypeData = (0, es_toolkit_compat.get)(this.schemaUtils.getSchemaRefType(property), "rawTypeData", {});
|
|
1176
1176
|
const nullable = !!(rawTypeData.nullable || property.nullable);
|
|
1177
|
-
const fieldName = this.typeNameFormatter.isValidName(name
|
|
1177
|
+
const fieldName = this.typeNameFormatter.isValidName(name) ? name : this.config.Ts.StringValue(name);
|
|
1178
1178
|
const fieldValue = this.schemaParserFabric.createSchemaParser({
|
|
1179
1179
|
schema: property,
|
|
1180
|
-
schemaPath: [...this.schemaPath, name
|
|
1180
|
+
schemaPath: [...this.schemaPath, name]
|
|
1181
1181
|
}).getInlineParseContent();
|
|
1182
1182
|
const readOnly = property.readOnly;
|
|
1183
|
-
|
|
1183
|
+
const complexType = this.schemaUtils.getComplexType(property);
|
|
1184
|
+
const rawDataComplexType = this.schemaUtils.getComplexType(rawTypeData);
|
|
1185
|
+
propertiesContent.push({
|
|
1184
1186
|
...property,
|
|
1185
1187
|
$$raw: property,
|
|
1186
1188
|
title: property.title,
|
|
1187
|
-
description: property.description ||
|
|
1189
|
+
description: property.description || (0, es_toolkit.compact)((property[complexType] || []).map((item) => item?.description))[0] || rawTypeData.description || (0, es_toolkit.compact)((rawTypeData[rawDataComplexType] || []).map((item) => item?.description))[0] || "",
|
|
1188
1190
|
isRequired: required,
|
|
1189
1191
|
isNullable: nullable,
|
|
1190
1192
|
name: fieldName,
|
|
@@ -1195,8 +1197,8 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1195
1197
|
key: fieldName,
|
|
1196
1198
|
value: fieldValue
|
|
1197
1199
|
})
|
|
1198
|
-
};
|
|
1199
|
-
}
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1200
1202
|
if (additionalProperties) {
|
|
1201
1203
|
const propertyNamesSchema = this.schemaUtils.getSchemaPropertyNamesSchema(schema);
|
|
1202
1204
|
let interfaceKeysContent;
|
|
@@ -1221,7 +1223,7 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1221
1223
|
var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
1222
1224
|
parse() {
|
|
1223
1225
|
let contentType = null;
|
|
1224
|
-
const { additionalProperties, type, description
|
|
1226
|
+
const { additionalProperties, type, description, items } = this.schema || {};
|
|
1225
1227
|
if (type === this.config.Ts.Keyword.Object && additionalProperties) {
|
|
1226
1228
|
const propertyNamesSchema = this.schemaUtils.getSchemaPropertyNamesSchema(this.schema);
|
|
1227
1229
|
let recordKeysContent;
|
|
@@ -1240,7 +1242,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1240
1242
|
}
|
|
1241
1243
|
if (Array.isArray(type) && type.length) contentType = this.schemaParser._complexSchemaParsers.oneOf({
|
|
1242
1244
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1243
|
-
oneOf: type.map((type
|
|
1245
|
+
oneOf: type.map((type) => ({ type }))
|
|
1244
1246
|
});
|
|
1245
1247
|
if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1246
1248
|
schema: item,
|
|
@@ -1254,7 +1256,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1254
1256
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1255
1257
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
1256
1258
|
name: this.typeName,
|
|
1257
|
-
description: this.schemaFormatters.formatDescription(description
|
|
1259
|
+
description: this.schemaFormatters.formatDescription(description),
|
|
1258
1260
|
content: type === this.config.Ts.Keyword.Null ? type : contentType || this.schemaUtils.getSchemaType(this.schema)
|
|
1259
1261
|
};
|
|
1260
1262
|
}
|
|
@@ -1389,7 +1391,7 @@ var SchemaParser = class {
|
|
|
1389
1391
|
}
|
|
1390
1392
|
schemaType = this.schemaUtils.getInternalSchemaType(this.schema);
|
|
1391
1393
|
this.schemaPath.push(this.typeName);
|
|
1392
|
-
|
|
1394
|
+
(0, es_toolkit.merge)(this.schema, this.config.hooks.onPreParseSchema(this.schema, this.typeName, schemaType) || {});
|
|
1393
1395
|
parsedSchema = this._baseSchemaParsers[schemaType](this.schema, this.typeName);
|
|
1394
1396
|
this.schema.$parsed = this.config.hooks.onParseSchema(this.schema, parsedSchema) || parsedSchema;
|
|
1395
1397
|
if (this.config.sortTypes && Array.isArray(this.schema.$parsed?.content)) this.schema.$parsed.content = this.schema.$parsed.content.sort(sortByProperty("name"));
|
|
@@ -1406,28 +1408,23 @@ var SchemaParser = class {
|
|
|
1406
1408
|
return this.schemaFormatters.formatSchema(parsedSchema, "base").content;
|
|
1407
1409
|
};
|
|
1408
1410
|
extractSchemaFromResponseStruct = (responseStruct) => {
|
|
1409
|
-
const { content
|
|
1410
|
-
const firstResponse =
|
|
1411
|
-
const firstSchema =
|
|
1411
|
+
const { content, ...extras } = responseStruct;
|
|
1412
|
+
const firstResponse = Object.values(content || {})[0];
|
|
1413
|
+
const firstSchema = (0, es_toolkit_compat.get)(firstResponse, "schema");
|
|
1412
1414
|
if (!firstSchema) return;
|
|
1415
|
+
const { schema: _, ...restResponse } = firstResponse || {};
|
|
1413
1416
|
return {
|
|
1414
1417
|
...extras,
|
|
1415
|
-
...
|
|
1418
|
+
...restResponse,
|
|
1416
1419
|
...firstSchema
|
|
1417
1420
|
};
|
|
1418
1421
|
};
|
|
1419
1422
|
};
|
|
1420
1423
|
|
|
1421
|
-
//#endregion
|
|
1422
|
-
//#region src/util/internal-case.ts
|
|
1423
|
-
function internalCase(value) {
|
|
1424
|
-
return lodash.default.camelCase(lodash.default.lowerCase(value));
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
1424
|
//#endregion
|
|
1428
1425
|
//#region src/util/pascal-case.ts
|
|
1429
1426
|
function pascalCase(value) {
|
|
1430
|
-
return
|
|
1427
|
+
return (0, es_toolkit_compat.upperFirst)((0, es_toolkit_compat.camelCase)(value));
|
|
1431
1428
|
}
|
|
1432
1429
|
|
|
1433
1430
|
//#endregion
|
|
@@ -1444,7 +1441,7 @@ var SchemaUtils = class {
|
|
|
1444
1441
|
this.schemaWalker = schemaWalker;
|
|
1445
1442
|
}
|
|
1446
1443
|
getRequiredProperties = (schema) => {
|
|
1447
|
-
return
|
|
1444
|
+
return (0, es_toolkit.uniq)(schema && Array.isArray(schema.required) && schema.required || []);
|
|
1448
1445
|
};
|
|
1449
1446
|
isRefSchema = (schema) => {
|
|
1450
1447
|
return !!schema?.$ref;
|
|
@@ -1463,15 +1460,15 @@ var SchemaUtils = class {
|
|
|
1463
1460
|
if (!this.isRefSchema(schema)) return null;
|
|
1464
1461
|
return this.schemaComponentsMap.get(schema.$ref);
|
|
1465
1462
|
};
|
|
1466
|
-
isPropertyRequired = (name
|
|
1463
|
+
isPropertyRequired = (name, propertySchema, rootSchema) => {
|
|
1467
1464
|
if (propertySchema["x-omitempty"] === false) return true;
|
|
1468
|
-
const isRequired = typeof propertySchema.required === "boolean" ? !!propertySchema.required : Array.isArray(rootSchema.required) ? rootSchema.required.includes(name
|
|
1465
|
+
const isRequired = typeof propertySchema.required === "boolean" ? !!propertySchema.required : Array.isArray(rootSchema.required) ? rootSchema.required.includes(name) : !!rootSchema.required;
|
|
1469
1466
|
if (this.config.convertedFromSwagger2) return typeof propertySchema.nullable === this.config.Ts.Keyword.Undefined ? isRequired : !propertySchema.nullable;
|
|
1470
1467
|
return isRequired;
|
|
1471
1468
|
};
|
|
1472
1469
|
isNullMissingInType = (schema, type) => {
|
|
1473
1470
|
const { nullable, type: schemaType } = schema || {};
|
|
1474
|
-
return (nullable || !!
|
|
1471
|
+
return (nullable || !!(0, es_toolkit_compat.get)(schema, "x-nullable") || schemaType === this.config.Ts.Keyword.Null) && typeof type === "string" && !type.includes(` ${this.config.Ts.Keyword.Null}`) && !type.includes(`${this.config.Ts.Keyword.Null} `);
|
|
1475
1472
|
};
|
|
1476
1473
|
safeAddNullToType = (schema, type) => {
|
|
1477
1474
|
if (this.isNullMissingInType(schema, type)) return this.config.Ts.UnionType([type, this.config.Ts.Keyword.Null]);
|
|
@@ -1479,13 +1476,13 @@ var SchemaUtils = class {
|
|
|
1479
1476
|
};
|
|
1480
1477
|
getSchemaPrimitiveType = (rawSchema) => {
|
|
1481
1478
|
const schema = rawSchema || {};
|
|
1482
|
-
if (schema.type) return
|
|
1479
|
+
if (schema.type) return (0, es_toolkit_compat.camelCase)(schema.type);
|
|
1483
1480
|
if (schema.enum) {
|
|
1484
1481
|
const enumFieldType = typeof schema.enum[0];
|
|
1485
1482
|
if (enumFieldType === this.config.Ts.Keyword.Undefined) return;
|
|
1486
|
-
return
|
|
1483
|
+
return (0, es_toolkit_compat.camelCase)(enumFieldType);
|
|
1487
1484
|
}
|
|
1488
|
-
if (
|
|
1485
|
+
if (Object.keys(schema.properties || {}).length) return SCHEMA_TYPES$1.OBJECT;
|
|
1489
1486
|
if (schema.items) return SCHEMA_TYPES$1.ARRAY;
|
|
1490
1487
|
return null;
|
|
1491
1488
|
};
|
|
@@ -1498,10 +1495,10 @@ var SchemaUtils = class {
|
|
|
1498
1495
|
};
|
|
1499
1496
|
makeAddRequiredToChildSchema = (parentSchema, childSchema) => {
|
|
1500
1497
|
if (!childSchema) return childSchema;
|
|
1501
|
-
const required =
|
|
1498
|
+
const required = (0, es_toolkit.uniq)([...this.getRequiredProperties(parentSchema), ...this.getRequiredProperties(childSchema)]);
|
|
1502
1499
|
const refData = this.getSchemaRefType(childSchema);
|
|
1503
1500
|
if (refData) {
|
|
1504
|
-
const existedRequiredKeys =
|
|
1501
|
+
const existedRequiredKeys = Object.keys(refData.rawTypeData?.properties || {}).filter((key) => required.includes(key));
|
|
1505
1502
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1506
1503
|
return {
|
|
1507
1504
|
...childSchema,
|
|
@@ -1509,17 +1506,17 @@ var SchemaUtils = class {
|
|
|
1509
1506
|
};
|
|
1510
1507
|
}
|
|
1511
1508
|
if (childSchema.properties) {
|
|
1512
|
-
const existedRequiredKeys =
|
|
1509
|
+
const existedRequiredKeys = Object.keys(childSchema.properties).filter((key) => required.includes(key));
|
|
1513
1510
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1514
1511
|
return {
|
|
1515
|
-
required:
|
|
1512
|
+
required: (0, es_toolkit.uniq)([...this.getRequiredProperties(childSchema), ...existedRequiredKeys]),
|
|
1516
1513
|
...childSchema
|
|
1517
1514
|
};
|
|
1518
1515
|
}
|
|
1519
1516
|
return childSchema;
|
|
1520
1517
|
};
|
|
1521
1518
|
filterSchemaContents = (contents, filterFn) => {
|
|
1522
|
-
return
|
|
1519
|
+
return (0, es_toolkit.uniq)(contents.filter((type) => filterFn(type)));
|
|
1523
1520
|
};
|
|
1524
1521
|
resolveTypeName = (typeName, { suffixes, resolver, prefixes, shouldReserve = true }) => {
|
|
1525
1522
|
if (resolver) return this.config.componentTypeNameResolver.resolve([], (reserved) => {
|
|
@@ -1535,10 +1532,10 @@ var SchemaUtils = class {
|
|
|
1535
1532
|
return SCHEMA_TYPES$1.COMPLEX_UNKNOWN;
|
|
1536
1533
|
};
|
|
1537
1534
|
getInternalSchemaType = (schema) => {
|
|
1538
|
-
if (
|
|
1535
|
+
if (schema.enum && schema.enum.length > 0 || this.getEnumNames(schema) && this.getEnumNames(schema).length > 0) return SCHEMA_TYPES$1.ENUM;
|
|
1539
1536
|
if (schema.discriminator) return SCHEMA_TYPES$1.DISCRIMINATOR;
|
|
1540
1537
|
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES$1.COMPLEX;
|
|
1541
|
-
if (
|
|
1538
|
+
if (schema.properties && Object.keys(schema.properties).length > 0) return SCHEMA_TYPES$1.OBJECT;
|
|
1542
1539
|
if (schema.type === SCHEMA_TYPES$1.ARRAY) return SCHEMA_TYPES$1.ARRAY;
|
|
1543
1540
|
return SCHEMA_TYPES$1.PRIMITIVE;
|
|
1544
1541
|
};
|
|
@@ -1551,7 +1548,7 @@ var SchemaUtils = class {
|
|
|
1551
1548
|
else {
|
|
1552
1549
|
const primitiveType = this.getSchemaPrimitiveType(schema);
|
|
1553
1550
|
if (primitiveType == null) return this.config.Ts.Keyword.Any;
|
|
1554
|
-
const typeAlias =
|
|
1551
|
+
const typeAlias = (0, es_toolkit_compat.get)(this.config.primitiveTypes, [primitiveType, schema.format]) || (0, es_toolkit_compat.get)(this.config.primitiveTypes, [primitiveType, "$default"]) || this.config.primitiveTypes[primitiveType];
|
|
1555
1552
|
if (typeof typeAlias === "function") resultType = typeAlias(schema, this);
|
|
1556
1553
|
else resultType = typeAlias || primitiveType;
|
|
1557
1554
|
}
|
|
@@ -1559,9 +1556,9 @@ var SchemaUtils = class {
|
|
|
1559
1556
|
return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, resultType));
|
|
1560
1557
|
};
|
|
1561
1558
|
buildTypeNameFromPath = (schemaPath) => {
|
|
1562
|
-
schemaPath =
|
|
1559
|
+
schemaPath = (0, es_toolkit.uniq)((0, es_toolkit.compact)(schemaPath || []));
|
|
1563
1560
|
if (!schemaPath || !schemaPath[0]) return null;
|
|
1564
|
-
return pascalCase(
|
|
1561
|
+
return pascalCase((0, es_toolkit.uniq)([schemaPath[0], schemaPath[schemaPath.length - 1]]).join("_"));
|
|
1565
1562
|
};
|
|
1566
1563
|
isConstantSchema(schema) {
|
|
1567
1564
|
return "const" in schema;
|
|
@@ -1604,7 +1601,7 @@ var SchemaParserFabric = class {
|
|
|
1604
1601
|
schemaPath
|
|
1605
1602
|
});
|
|
1606
1603
|
};
|
|
1607
|
-
createSchema = ({ content, linkedSchema = {}, linkedComponent, schemaPath
|
|
1604
|
+
createSchema = ({ content, linkedSchema = {}, linkedComponent, schemaPath, ...otherSchemaProps }) => {
|
|
1608
1605
|
const parser = this.createSchemaParser({
|
|
1609
1606
|
schema: linkedComponent || linkedSchema,
|
|
1610
1607
|
schemaPath
|
|
@@ -1652,8 +1649,7 @@ var SchemaParserFabric = class {
|
|
|
1652
1649
|
|
|
1653
1650
|
//#endregion
|
|
1654
1651
|
//#region src/util/id.ts
|
|
1655
|
-
const
|
|
1656
|
-
const generateId = nanoid.customAlphabet(ALPHABET, 12);
|
|
1652
|
+
const generateId = () => node_crypto.randomUUID();
|
|
1657
1653
|
|
|
1658
1654
|
//#endregion
|
|
1659
1655
|
//#region src/schema-routes/util/specific-arg-name-resolver.ts
|
|
@@ -1698,7 +1694,7 @@ var SchemaRoutes = class {
|
|
|
1698
1694
|
this.typeNameFormatter = typeNameFormatter;
|
|
1699
1695
|
this.schemaComponentsMap = schemaComponentsMap;
|
|
1700
1696
|
this.templatesWorker = templatesWorker;
|
|
1701
|
-
this.FORM_DATA_TYPES =
|
|
1697
|
+
this.FORM_DATA_TYPES = (0, es_toolkit.uniq)([this.schemaUtils.getSchemaType({
|
|
1702
1698
|
type: "string",
|
|
1703
1699
|
format: "file"
|
|
1704
1700
|
}), this.schemaUtils.getSchemaType({
|
|
@@ -1706,49 +1702,50 @@ var SchemaRoutes = class {
|
|
|
1706
1702
|
format: "binary"
|
|
1707
1703
|
})]);
|
|
1708
1704
|
}
|
|
1709
|
-
createRequestsMap = (
|
|
1710
|
-
const parameters =
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1705
|
+
createRequestsMap = (routesByMethod) => {
|
|
1706
|
+
const parameters = (0, es_toolkit_compat.get)(routesByMethod, "parameters");
|
|
1707
|
+
const result = {};
|
|
1708
|
+
for (const [method, requestInfo] of Object.entries(routesByMethod)) {
|
|
1709
|
+
if (method.startsWith("x-") || ["parameters", "$ref"].includes(method)) continue;
|
|
1710
|
+
result[method] = {
|
|
1714
1711
|
...requestInfo,
|
|
1715
|
-
parameters:
|
|
1712
|
+
parameters: (0, es_toolkit.compact)([...parameters || [], ...requestInfo.parameters || []])
|
|
1716
1713
|
};
|
|
1717
|
-
|
|
1718
|
-
|
|
1714
|
+
}
|
|
1715
|
+
return result;
|
|
1719
1716
|
};
|
|
1720
|
-
parseRouteName = (
|
|
1721
|
-
const routeName = this.config.hooks.onPreBuildRoutePath(
|
|
1717
|
+
parseRouteName = (rawRoute) => {
|
|
1718
|
+
const routeName = this.config.hooks.onPreBuildRoutePath(rawRoute) || rawRoute;
|
|
1722
1719
|
const pathParamMatches = (routeName || "").match(/({[\w[\\\]^`][-_.\w]*})|(:[\w[\\\]^`][-_.\w]*:?)/g);
|
|
1723
|
-
const pathParams =
|
|
1720
|
+
const pathParams = [];
|
|
1721
|
+
for (const match of pathParamMatches || []) {
|
|
1724
1722
|
const paramName = match.replace(/\{|\}|:/g, "");
|
|
1725
|
-
if (!paramName)
|
|
1723
|
+
if (!paramName) continue;
|
|
1726
1724
|
if (paramName.includes("-")) consola.consola.warn("wrong path param name", paramName);
|
|
1727
|
-
pathParams
|
|
1725
|
+
pathParams.push({
|
|
1728
1726
|
$match: match,
|
|
1729
|
-
name:
|
|
1727
|
+
name: (0, es_toolkit_compat.camelCase)(paramName),
|
|
1730
1728
|
required: true,
|
|
1731
1729
|
type: "string",
|
|
1732
1730
|
description: "",
|
|
1733
1731
|
schema: { type: "string" },
|
|
1734
1732
|
in: "path"
|
|
1735
1733
|
});
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
return fixedRoute$1.replace(pathParam.$match, `\${${insertion}}`);
|
|
1734
|
+
}
|
|
1735
|
+
let fixedRoute = pathParams.reduce((fixedRoute, pathParam, i, arr) => {
|
|
1736
|
+
const insertion = this.config.hooks.onInsertPathParam(pathParam.name, i, arr, fixedRoute) || pathParam.name;
|
|
1737
|
+
return fixedRoute.replace(pathParam.$match, `\${${insertion}}`);
|
|
1741
1738
|
}, routeName || "");
|
|
1742
1739
|
const queryParamMatches = fixedRoute.match(/(\{\?.*\})/g);
|
|
1743
1740
|
const queryParams = [];
|
|
1744
1741
|
if (queryParamMatches?.length) {
|
|
1745
1742
|
for (const match of queryParamMatches) fixedRoute = fixedRoute.replace(match, "");
|
|
1746
|
-
const paramNames =
|
|
1743
|
+
const paramNames = (0, es_toolkit.uniq)(queryParamMatches.join(",").replace(/(\{\?)|(\})|\s/g, "").split(","));
|
|
1747
1744
|
for (const paramName of paramNames) {
|
|
1748
|
-
if (paramName.includes("-")) consola.consola.warn("wrong query param name", paramName);
|
|
1745
|
+
if (typeof paramName === "string" && paramName.includes("-")) consola.consola.warn("wrong query param name", paramName);
|
|
1749
1746
|
queryParams.push({
|
|
1750
1747
|
$match: paramName,
|
|
1751
|
-
name:
|
|
1748
|
+
name: typeof paramName === "string" ? (0, es_toolkit_compat.camelCase)(paramName) : (0, es_toolkit_compat.camelCase)(String(paramName)),
|
|
1752
1749
|
required: true,
|
|
1753
1750
|
type: "string",
|
|
1754
1751
|
description: "",
|
|
@@ -1758,7 +1755,7 @@ var SchemaRoutes = class {
|
|
|
1758
1755
|
}
|
|
1759
1756
|
}
|
|
1760
1757
|
const result = {
|
|
1761
|
-
originalRoute:
|
|
1758
|
+
originalRoute: rawRoute || "",
|
|
1762
1759
|
route: fixedRoute,
|
|
1763
1760
|
pathParams,
|
|
1764
1761
|
queryParams
|
|
@@ -1775,7 +1772,7 @@ var SchemaRoutes = class {
|
|
|
1775
1772
|
formData: [],
|
|
1776
1773
|
cookie: []
|
|
1777
1774
|
};
|
|
1778
|
-
|
|
1775
|
+
for (const parameter of parameters || []) {
|
|
1779
1776
|
const refTypeInfo = this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);
|
|
1780
1777
|
let routeParam = null;
|
|
1781
1778
|
if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
|
|
@@ -1786,7 +1783,7 @@ var SchemaRoutes = class {
|
|
|
1786
1783
|
};
|
|
1787
1784
|
if (parameter?.required && !routeParam.required) routeParam.required = parameter.required;
|
|
1788
1785
|
} else {
|
|
1789
|
-
if (!parameter.in)
|
|
1786
|
+
if (!parameter.in) continue;
|
|
1790
1787
|
if (!routeParams[parameter.in]) routeParams[parameter.in] = [];
|
|
1791
1788
|
routeParam = {
|
|
1792
1789
|
...parameter,
|
|
@@ -1794,16 +1791,19 @@ var SchemaRoutes = class {
|
|
|
1794
1791
|
};
|
|
1795
1792
|
}
|
|
1796
1793
|
if (routeParam.in === "path") {
|
|
1797
|
-
if (!routeParam.name)
|
|
1798
|
-
routeParam.name =
|
|
1794
|
+
if (!routeParam.name) continue;
|
|
1795
|
+
routeParam.name = (0, es_toolkit_compat.camelCase)(routeParam.name);
|
|
1799
1796
|
}
|
|
1800
|
-
|
|
1801
|
-
}
|
|
1797
|
+
routeParams[routeParam.in].push(routeParam);
|
|
1798
|
+
}
|
|
1802
1799
|
for (const pathParam of pathParamsFromRouteName) if (!routeParams.path.some((parameter) => parameter.name === pathParam.name)) routeParams.path.push(pathParam);
|
|
1803
1800
|
for (const queryParam of queryParamsFromRouteName) if (!routeParams.query.some((parameter) => parameter.name === queryParam.name)) routeParams.query.push(queryParam);
|
|
1804
1801
|
return routeParams;
|
|
1805
1802
|
};
|
|
1806
|
-
getContentTypes = (requestInfo, extraContentTypes) =>
|
|
1803
|
+
getContentTypes = (requestInfo, extraContentTypes) => {
|
|
1804
|
+
const requestInfoArray = Array.isArray(requestInfo) ? requestInfo : Object.values(requestInfo || {});
|
|
1805
|
+
return (0, es_toolkit.uniq)((0, es_toolkit.compact)([...extraContentTypes || [], ...(0, es_toolkit.flattenDeep)(requestInfoArray.map((requestInfoData) => requestInfoData && Object.keys(requestInfoData?.content || {})))]));
|
|
1806
|
+
};
|
|
1807
1807
|
getContentKind = (contentTypes) => {
|
|
1808
1808
|
if (contentTypes.includes("application/vnd.api+json")) return CONTENT_KIND.JSON_API;
|
|
1809
1809
|
if (contentTypes.some((contentType) => contentType.startsWith("application/json")) || contentTypes.some((contentType) => contentType.endsWith("+json"))) return CONTENT_KIND.JSON;
|
|
@@ -1815,7 +1815,7 @@ var SchemaRoutes = class {
|
|
|
1815
1815
|
};
|
|
1816
1816
|
isSuccessStatus = (status) => this.config.defaultResponseAsSuccess && status === "default" || +status >= this.config.successResponseStatusRange[0] && +status <= this.config.successResponseStatusRange[1] || status === "2xx";
|
|
1817
1817
|
getSchemaFromRequestType = (requestInfo) => {
|
|
1818
|
-
const content =
|
|
1818
|
+
const content = (0, es_toolkit_compat.get)(requestInfo, "content");
|
|
1819
1819
|
if (!content) return null;
|
|
1820
1820
|
for (const dataType in content) if (content[dataType]?.schema) return {
|
|
1821
1821
|
...content[dataType].schema,
|
|
@@ -1829,13 +1829,13 @@ var SchemaRoutes = class {
|
|
|
1829
1829
|
if (schema) {
|
|
1830
1830
|
const content = this.schemaParserFabric.getInlineParseContent(schema, typeName, [operationId]);
|
|
1831
1831
|
const foundedSchemaByName = parsedSchemas.find((parsedSchema) => this.typeNameFormatter.format(parsedSchema.name) === content);
|
|
1832
|
-
const foundSchemaByContent = parsedSchemas.find((parsedSchema) =>
|
|
1832
|
+
const foundSchemaByContent = parsedSchemas.find((parsedSchema) => (0, es_toolkit.isEqual)(parsedSchema.content, content));
|
|
1833
1833
|
const foundSchema = foundedSchemaByName || foundSchemaByContent;
|
|
1834
1834
|
return foundSchema ? this.typeNameFormatter.format(foundSchema.name) : content;
|
|
1835
1835
|
}
|
|
1836
1836
|
if (refTypeInfo) {
|
|
1837
1837
|
const typeNameWithoutOpId = refTypeInfo.typeName.replace(operationId, "");
|
|
1838
|
-
if (parsedSchemas.find((schema
|
|
1838
|
+
if (parsedSchemas.find((schema) => schema.name === typeNameWithoutOpId)) return this.typeNameFormatter.format(typeNameWithoutOpId);
|
|
1839
1839
|
switch (refTypeInfo.componentName) {
|
|
1840
1840
|
case "schemas": return this.typeNameFormatter.format(refTypeInfo.typeName);
|
|
1841
1841
|
case "responses":
|
|
@@ -1845,23 +1845,27 @@ var SchemaRoutes = class {
|
|
|
1845
1845
|
}
|
|
1846
1846
|
return defaultType || this.config.Ts.Keyword.Any;
|
|
1847
1847
|
};
|
|
1848
|
-
getRequestInfoTypes = ({ requestInfos, parsedSchemas, operationId, defaultType }) =>
|
|
1849
|
-
const
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1848
|
+
getRequestInfoTypes = ({ requestInfos, parsedSchemas, operationId, defaultType }) => {
|
|
1849
|
+
const result = [];
|
|
1850
|
+
for (const [status, requestInfo] of Object.entries(requestInfos || {})) {
|
|
1851
|
+
const contentTypes = this.getContentTypes([requestInfo], operationId);
|
|
1852
|
+
result.push({
|
|
1853
|
+
...requestInfo || {},
|
|
1854
|
+
contentTypes,
|
|
1855
|
+
contentKind: this.getContentKind(contentTypes),
|
|
1856
|
+
type: this.schemaParserFabric.schemaUtils.safeAddNullToType(requestInfo, this.getTypeFromRequestInfo({
|
|
1857
|
+
requestInfo,
|
|
1858
|
+
parsedSchemas,
|
|
1859
|
+
operationId,
|
|
1860
|
+
defaultType
|
|
1861
|
+
})),
|
|
1862
|
+
description: this.schemaParserFabric.schemaFormatters.formatDescription(requestInfo.description || "", true),
|
|
1863
|
+
status: Number.isNaN(+status) ? status : +status,
|
|
1864
|
+
isSuccess: this.isSuccessStatus(status)
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
return result;
|
|
1868
|
+
};
|
|
1865
1869
|
getResponseBodyInfo = (routeInfo, parsedSchemas) => {
|
|
1866
1870
|
const { produces, operationId, responses } = routeInfo;
|
|
1867
1871
|
const contentTypes = this.getContentTypes(responses, [...produces || [], routeInfo["x-accepts"]]);
|
|
@@ -1970,13 +1974,12 @@ var SchemaRoutes = class {
|
|
|
1970
1974
|
};
|
|
1971
1975
|
return acc;
|
|
1972
1976
|
}, {});
|
|
1973
|
-
const fixedQueryParams =
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
}, {});
|
|
1977
|
+
const fixedQueryParams = {};
|
|
1978
|
+
const queryObjectProperties = (0, es_toolkit_compat.get)(queryObjectSchema, "properties") || {};
|
|
1979
|
+
for (const [name, property] of Object.entries(queryObjectProperties)) if (name && typeof property === "object") fixedQueryParams[name] = {
|
|
1980
|
+
...property,
|
|
1981
|
+
in: "query"
|
|
1982
|
+
};
|
|
1980
1983
|
const schema = {
|
|
1981
1984
|
...queryObjectSchema,
|
|
1982
1985
|
properties: {
|
|
@@ -2019,7 +2022,7 @@ var SchemaRoutes = class {
|
|
|
2019
2022
|
successResponse.schema.contentKind = contentKind;
|
|
2020
2023
|
if (successResponse.schema.typeData) successResponse.schema.typeData.isExtractedResponseBody = true;
|
|
2021
2024
|
successResponse.type = this.schemaParserFabric.getInlineParseContent({ $ref: successResponse.schema.$ref });
|
|
2022
|
-
if (idx > -1)
|
|
2025
|
+
if (idx > -1) Object.assign(responseBodyInfo.responses[idx], {
|
|
2023
2026
|
...successResponse.schema,
|
|
2024
2027
|
type: successResponse.type
|
|
2025
2028
|
});
|
|
@@ -2032,18 +2035,18 @@ var SchemaRoutes = class {
|
|
|
2032
2035
|
suffixes: this.config.extractingOptions.responseErrorSuffix,
|
|
2033
2036
|
resolver: this.config.extractingOptions.responseErrorNameResolver
|
|
2034
2037
|
});
|
|
2035
|
-
const errorSchemas = responseBodyInfo.error.schemas.map(this.getSchemaFromRequestType)
|
|
2038
|
+
const errorSchemas = (0, es_toolkit.compact)(responseBodyInfo.error.schemas.map(this.getSchemaFromRequestType));
|
|
2036
2039
|
if (!errorSchemas.length) return;
|
|
2037
2040
|
const schema = this.schemaParserFabric.parseSchema({
|
|
2038
2041
|
oneOf: errorSchemas,
|
|
2039
|
-
title: errorSchemas.map((schema
|
|
2040
|
-
description: errorSchemas.map((schema
|
|
2042
|
+
title: (0, es_toolkit.compact)(errorSchemas.map((schema) => schema.title)).join(" "),
|
|
2043
|
+
description: (0, es_toolkit.compact)(errorSchemas.map((schema) => schema.description)).join("\n")
|
|
2041
2044
|
}, null, [routeInfo.operationId]);
|
|
2042
2045
|
const component = this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef([
|
|
2043
2046
|
"components",
|
|
2044
2047
|
"schemas",
|
|
2045
2048
|
typeName
|
|
2046
|
-
]),
|
|
2049
|
+
]), schema);
|
|
2047
2050
|
responseBodyInfo.error.schemas = [component];
|
|
2048
2051
|
if (component.typeData) component.typeData.isExtractedResponseError = true;
|
|
2049
2052
|
responseBodyInfo.error.type = this.typeNameFormatter.format(component.typeName);
|
|
@@ -2071,11 +2074,11 @@ var SchemaRoutes = class {
|
|
|
2071
2074
|
parseRouteInfo = (rawRouteName, routeInfo, method, usageSchema, parsedSchemas) => {
|
|
2072
2075
|
const { security: globalSecurity } = usageSchema;
|
|
2073
2076
|
const { moduleNameIndex, moduleNameFirstTag, extractRequestParams } = this.config;
|
|
2074
|
-
const { operationId, requestBody, security, parameters, summary, description
|
|
2077
|
+
const { operationId, requestBody, security, parameters, summary, description, tags, responses, requestBodyName, produces, consumes, ...otherInfo } = routeInfo;
|
|
2075
2078
|
const { route, pathParams: pathParamsFromRouteName, queryParams: queryParamsFromRouteName } = this.parseRouteName(rawRouteName);
|
|
2076
2079
|
const routeId = generateId();
|
|
2077
2080
|
const firstTag = tags && tags.length > 0 ? tags[0] : null;
|
|
2078
|
-
const moduleName = moduleNameFirstTag && firstTag ?
|
|
2081
|
+
const moduleName = moduleNameFirstTag && firstTag ? (0, es_toolkit_compat.camelCase)(firstTag) : (0, es_toolkit_compat.camelCase)((0, es_toolkit.compact)(route.split("/"))[moduleNameIndex] || "");
|
|
2079
2082
|
let hasSecurity = !!globalSecurity?.length;
|
|
2080
2083
|
if (security) hasSecurity = security.length > 0;
|
|
2081
2084
|
const routeParams = this.getRouteParams(routeInfo, pathParamsFromRouteName, queryParamsFromRouteName);
|
|
@@ -2095,7 +2098,7 @@ var SchemaRoutes = class {
|
|
|
2095
2098
|
route: rawRouteName,
|
|
2096
2099
|
moduleName,
|
|
2097
2100
|
responsesTypes: responseBodyInfo.responses,
|
|
2098
|
-
description
|
|
2101
|
+
description,
|
|
2099
2102
|
tags,
|
|
2100
2103
|
summary,
|
|
2101
2104
|
responses,
|
|
@@ -2192,7 +2195,7 @@ var SchemaRoutes = class {
|
|
|
2192
2195
|
};
|
|
2193
2196
|
attachSchema = ({ usageSchema, parsedSchemas }) => {
|
|
2194
2197
|
this.config.routeNameDuplicatesMap.clear();
|
|
2195
|
-
const pathsEntries =
|
|
2198
|
+
const pathsEntries = Object.entries(usageSchema.paths || {});
|
|
2196
2199
|
for (const [rawRouteName, routeInfoByMethodsMap] of pathsEntries) {
|
|
2197
2200
|
const routeInfosMap = this.createRequestsMap(routeInfoByMethodsMap);
|
|
2198
2201
|
for (const [method, routeInfo] of Object.entries(routeInfosMap)) {
|
|
@@ -2216,37 +2219,36 @@ var SchemaRoutes = class {
|
|
|
2216
2219
|
} else modules.$outOfModule.push(route);
|
|
2217
2220
|
return modules;
|
|
2218
2221
|
}, { $outOfModule: [] });
|
|
2219
|
-
const routeGroups =
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2222
|
+
const routeGroups = {
|
|
2223
|
+
outOfModule: void 0,
|
|
2224
|
+
combined: void 0
|
|
2225
|
+
};
|
|
2226
|
+
for (const [moduleName, routesGroup] of Object.entries(groupedRoutes)) if (moduleName === "$outOfModule") routeGroups.outOfModule = routesGroup;
|
|
2227
|
+
else {
|
|
2228
|
+
if (!routeGroups.combined) routeGroups.combined = [];
|
|
2229
|
+
routeGroups.combined.push({
|
|
2230
|
+
moduleName,
|
|
2231
|
+
routes: routesGroup.map((route) => {
|
|
2232
|
+
const { original: originalName, usage: usageName } = route.routeName;
|
|
2233
|
+
if (routesGroup.length > 1 && usageName !== originalName && !routesGroup.some(({ routeName, id }) => id !== route.id && originalName === routeName.original)) return {
|
|
2234
|
+
...route,
|
|
2235
|
+
routeName: {
|
|
2236
|
+
...route.routeName,
|
|
2237
|
+
usage: originalName
|
|
2238
|
+
}
|
|
2239
|
+
};
|
|
2240
|
+
return route;
|
|
2241
|
+
})
|
|
2242
|
+
});
|
|
2243
|
+
}
|
|
2240
2244
|
if (this.config.sortRoutes) {
|
|
2241
2245
|
if (routeGroups.outOfModule) routeGroups.outOfModule = this.sortRoutes(routeGroups.outOfModule);
|
|
2242
|
-
if (routeGroups.combined)
|
|
2243
|
-
routeGroup.routes = this.sortRoutes(routeGroup.routes);
|
|
2244
|
-
});
|
|
2246
|
+
if (routeGroups.combined) for (const routeGroup of routeGroups.combined) routeGroup.routes = this.sortRoutes(routeGroup.routes);
|
|
2245
2247
|
}
|
|
2246
2248
|
return routeGroups;
|
|
2247
2249
|
};
|
|
2248
2250
|
sortRoutes = (routes) => {
|
|
2249
|
-
return
|
|
2251
|
+
return routes.slice().sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
|
|
2250
2252
|
};
|
|
2251
2253
|
};
|
|
2252
2254
|
|
|
@@ -2261,8 +2263,8 @@ var SchemaWalker = class {
|
|
|
2261
2263
|
this.config = config;
|
|
2262
2264
|
this.swaggerSchemaResolver = swaggerSchemaResolver;
|
|
2263
2265
|
}
|
|
2264
|
-
addSchema = (name
|
|
2265
|
-
this.schemas.set(name
|
|
2266
|
+
addSchema = (name, schema) => {
|
|
2267
|
+
this.schemas.set(name, structuredClone(schema));
|
|
2266
2268
|
};
|
|
2267
2269
|
_isLocalRef = (ref) => {
|
|
2268
2270
|
return ref.startsWith("#");
|
|
@@ -2271,8 +2273,7 @@ var SchemaWalker = class {
|
|
|
2271
2273
|
return ref.startsWith("http://") || ref.startsWith("https://");
|
|
2272
2274
|
};
|
|
2273
2275
|
_getRefDataFromSchema = (schema, ref) => {
|
|
2274
|
-
const
|
|
2275
|
-
const refData = lodash.default.get(schema, path$1);
|
|
2276
|
+
const refData = (0, es_toolkit_compat.get)(schema, ref.replace("#", "").split("/"));
|
|
2276
2277
|
if (refData) this.caches.set(ref, refData);
|
|
2277
2278
|
return refData;
|
|
2278
2279
|
};
|
|
@@ -2285,14 +2286,14 @@ var Request = class {
|
|
|
2285
2286
|
constructor(config) {
|
|
2286
2287
|
this.config = config;
|
|
2287
2288
|
}
|
|
2288
|
-
async download({ url
|
|
2289
|
+
async download({ url, authToken, ...options }) {
|
|
2289
2290
|
const requestOptions = {};
|
|
2290
2291
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2291
|
-
|
|
2292
|
+
(0, es_toolkit.merge)((0, es_toolkit.merge)(requestOptions, options), this.config.requestOptions || {});
|
|
2292
2293
|
try {
|
|
2293
|
-
return await (await fetch(url
|
|
2294
|
+
return await (await fetch(url, requestOptions)).text();
|
|
2294
2295
|
} catch (error) {
|
|
2295
|
-
const message = `error while fetching data from URL "${url
|
|
2296
|
+
const message = `error while fetching data from URL "${url}"`;
|
|
2296
2297
|
consola.consola.error(message, error);
|
|
2297
2298
|
return message;
|
|
2298
2299
|
}
|
|
@@ -2311,21 +2312,21 @@ var SwaggerSchemaResolver = class {
|
|
|
2311
2312
|
this.request = new Request(config);
|
|
2312
2313
|
}
|
|
2313
2314
|
async create() {
|
|
2314
|
-
const { spec, patch, input, url
|
|
2315
|
+
const { spec, patch, input, url, authorizationToken } = this.config;
|
|
2315
2316
|
if (spec) return await this.convertSwaggerObject(spec, { patch });
|
|
2316
|
-
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url
|
|
2317
|
+
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url, authorizationToken);
|
|
2317
2318
|
const swaggerSchemaObject = this.processSwaggerSchemaFile(swaggerSchemaFile);
|
|
2318
2319
|
return await this.convertSwaggerObject(swaggerSchemaObject, { patch });
|
|
2319
2320
|
}
|
|
2320
2321
|
convertSwaggerObject(swaggerSchema, converterOptions) {
|
|
2321
2322
|
return new Promise((resolve) => {
|
|
2322
2323
|
const result = structuredClone(swaggerSchema);
|
|
2323
|
-
result.info =
|
|
2324
|
+
result.info = (0, es_toolkit.merge)({
|
|
2324
2325
|
title: "No title",
|
|
2325
2326
|
version: ""
|
|
2326
|
-
}, result.info);
|
|
2327
|
+
}, result.info || {});
|
|
2327
2328
|
if (!Object.hasOwn(result, "openapi")) {
|
|
2328
|
-
result.paths =
|
|
2329
|
+
result.paths = (0, es_toolkit.merge)({}, result.paths || {});
|
|
2329
2330
|
swagger2openapi.convertObj(result, {
|
|
2330
2331
|
...converterOptions,
|
|
2331
2332
|
resolveInternal: true,
|
|
@@ -2333,7 +2334,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2333
2334
|
refSiblings: "preserve",
|
|
2334
2335
|
rbname: "requestBodyName"
|
|
2335
2336
|
}, (err, options) => {
|
|
2336
|
-
const parsedSwaggerSchema =
|
|
2337
|
+
const parsedSwaggerSchema = (0, es_toolkit_compat.get)(err, "options.openapi") ?? (0, es_toolkit_compat.get)(options, "openapi");
|
|
2337
2338
|
if (!parsedSwaggerSchema && err) throw err;
|
|
2338
2339
|
this.config.update({ convertedFromSwagger2: true });
|
|
2339
2340
|
resolve({
|
|
@@ -2368,23 +2369,21 @@ var SwaggerSchemaResolver = class {
|
|
|
2368
2369
|
}
|
|
2369
2370
|
}
|
|
2370
2371
|
fixSwaggerSchema({ usageSchema, originalSchema }) {
|
|
2371
|
-
const usagePaths =
|
|
2372
|
-
const originalPaths =
|
|
2373
|
-
|
|
2374
|
-
const originalPathObject =
|
|
2375
|
-
|
|
2376
|
-
const originalRouteInfo =
|
|
2377
|
-
const usageRouteParams =
|
|
2378
|
-
const originalRouteParams =
|
|
2372
|
+
const usagePaths = (0, es_toolkit_compat.get)(usageSchema, "paths") || {};
|
|
2373
|
+
const originalPaths = (0, es_toolkit_compat.get)(originalSchema, "paths") || {};
|
|
2374
|
+
for (const [route, usagePathObject] of Object.entries(usagePaths)) {
|
|
2375
|
+
const originalPathObject = (0, es_toolkit_compat.get)(originalPaths, route) || {};
|
|
2376
|
+
for (const [methodName, usageRouteInfo] of Object.entries(usagePathObject)) {
|
|
2377
|
+
const originalRouteInfo = (0, es_toolkit_compat.get)(originalPathObject, methodName) || {};
|
|
2378
|
+
const usageRouteParams = (0, es_toolkit_compat.get)(usageRouteInfo, "parameters") || [];
|
|
2379
|
+
const originalRouteParams = (0, es_toolkit_compat.get)(originalRouteInfo, "parameters") || [];
|
|
2379
2380
|
if (typeof usageRouteInfo === "object") {
|
|
2380
|
-
usageRouteInfo.consumes =
|
|
2381
|
-
usageRouteInfo.produces =
|
|
2381
|
+
usageRouteInfo.consumes = (0, es_toolkit.uniq)((0, es_toolkit.compact)([...usageRouteInfo.consumes || [], ...originalRouteInfo.consumes || []]));
|
|
2382
|
+
usageRouteInfo.produces = (0, es_toolkit.uniq)((0, es_toolkit.compact)([...usageRouteInfo.produces || [], ...originalRouteInfo.produces || []]));
|
|
2382
2383
|
}
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
});
|
|
2387
|
-
});
|
|
2384
|
+
for (const originalRouteParam of originalRouteParams) if (!usageRouteParams.find((param) => originalRouteParam.in === param.in && originalRouteParam.name === param.name)) usageRouteParams.push(originalRouteParam);
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2388
2387
|
}
|
|
2389
2388
|
};
|
|
2390
2389
|
|
|
@@ -2404,10 +2403,10 @@ var TemplatesWorker = class {
|
|
|
2404
2403
|
if (this.config.silent) consola.consola.level = 0;
|
|
2405
2404
|
}
|
|
2406
2405
|
getTemplatePaths = (config) => {
|
|
2407
|
-
const __dirname
|
|
2408
|
-
const baseTemplatesPath = node_path.resolve(__dirname
|
|
2409
|
-
const defaultTemplatesPath = node_path.resolve(__dirname
|
|
2410
|
-
const modularTemplatesPath = node_path.resolve(__dirname
|
|
2406
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath(require("url").pathToFileURL(__filename).href));
|
|
2407
|
+
const baseTemplatesPath = node_path.resolve(__dirname, "../templates/base");
|
|
2408
|
+
const defaultTemplatesPath = node_path.resolve(__dirname, "../templates/default");
|
|
2409
|
+
const modularTemplatesPath = node_path.resolve(__dirname, "../templates/modular");
|
|
2411
2410
|
return {
|
|
2412
2411
|
base: baseTemplatesPath,
|
|
2413
2412
|
default: defaultTemplatesPath,
|
|
@@ -2416,7 +2415,7 @@ var TemplatesWorker = class {
|
|
|
2416
2415
|
custom: config.templates && node_path.resolve(process.cwd(), config.templates)
|
|
2417
2416
|
};
|
|
2418
2417
|
};
|
|
2419
|
-
cropExtension = (path
|
|
2418
|
+
cropExtension = (path) => this.config.templateExtensions.reduce((path, ext) => path.endsWith(ext) ? path.replace(ext, "") : path, path);
|
|
2420
2419
|
getTemplateFullPath = (path_, fileName) => {
|
|
2421
2420
|
const raw = node_path.resolve(path_, "./", this.cropExtension(fileName));
|
|
2422
2421
|
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
@@ -2425,39 +2424,39 @@ var TemplatesWorker = class {
|
|
|
2425
2424
|
if (packageOrPath.startsWith("./") || packageOrPath.startsWith("../")) return require$1(node_path.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2426
2425
|
return require$1(packageOrPath);
|
|
2427
2426
|
};
|
|
2428
|
-
getTemplate = (name
|
|
2427
|
+
getTemplate = (name, fileName, path) => {
|
|
2429
2428
|
const { templatePaths } = this.config;
|
|
2430
|
-
if (path
|
|
2429
|
+
if (path) return this.fileSystem.getFileContent(path);
|
|
2431
2430
|
if (!fileName) return "";
|
|
2432
2431
|
const customFullPath = templatePaths.custom && this.getTemplateFullPath(templatePaths.custom, fileName);
|
|
2433
2432
|
let fileContent = customFullPath && this.fileSystem.getFileContent(customFullPath);
|
|
2434
2433
|
if (fileContent) {
|
|
2435
|
-
consola.consola.info(`"${name
|
|
2434
|
+
consola.consola.info(`"${name.toLowerCase()}" template found in "${templatePaths.custom}"`);
|
|
2436
2435
|
return fileContent;
|
|
2437
2436
|
}
|
|
2438
2437
|
const baseFullPath = this.getTemplateFullPath(templatePaths.base, fileName);
|
|
2439
2438
|
if (baseFullPath) fileContent = this.fileSystem.getFileContent(baseFullPath);
|
|
2440
|
-
else if (templatePaths.custom) consola.consola.warn("Code generator will use the default template:", `"${name
|
|
2441
|
-
else consola.consola.info(`Code generator will use the default template for "${name
|
|
2439
|
+
else if (templatePaths.custom) consola.consola.warn("Code generator will use the default template:", `"${name.toLowerCase()}"`, "template not found in", `"${templatePaths.custom}"`);
|
|
2440
|
+
else consola.consola.info(`Code generator will use the default template for "${name.toLowerCase()}"`);
|
|
2442
2441
|
const originalFullPath = this.getTemplateFullPath(templatePaths.original, fileName);
|
|
2443
2442
|
if (originalFullPath) fileContent = this.fileSystem.getFileContent(originalFullPath);
|
|
2444
2443
|
return fileContent;
|
|
2445
2444
|
};
|
|
2446
2445
|
getTemplates = ({ templatePaths }) => {
|
|
2447
2446
|
if (templatePaths.custom) consola.consola.info(`try to read templates from directory "${templatePaths.custom}"`);
|
|
2448
|
-
return
|
|
2447
|
+
return this.config.templateInfos.reduce((acc, { name, fileName }) => ({
|
|
2449
2448
|
...acc,
|
|
2450
|
-
[name
|
|
2449
|
+
[name]: this.getTemplate(name, fileName)
|
|
2451
2450
|
}), {});
|
|
2452
2451
|
};
|
|
2453
|
-
findTemplateWithExt = (path
|
|
2454
|
-
const raw = this.cropExtension(path
|
|
2452
|
+
findTemplateWithExt = (path) => {
|
|
2453
|
+
const raw = this.cropExtension(path);
|
|
2455
2454
|
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2456
2455
|
};
|
|
2457
2456
|
getTemplateContent = (path_) => {
|
|
2458
|
-
const foundTemplatePathKey =
|
|
2457
|
+
const foundTemplatePathKey = Object.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
2459
2458
|
if (foundTemplatePathKey) {
|
|
2460
|
-
const rawPath = node_path.resolve(path_.replace(`@${foundTemplatePathKey}`,
|
|
2459
|
+
const rawPath = node_path.resolve(path_.replace(`@${foundTemplatePathKey}`, (0, es_toolkit_compat.get)(this.config.templatePaths, foundTemplatePathKey)));
|
|
2461
2460
|
const fixedPath = this.findTemplateWithExt(rawPath);
|
|
2462
2461
|
if (fixedPath) return this.fileSystem.getFileContent(fixedPath);
|
|
2463
2462
|
}
|
|
@@ -2472,7 +2471,7 @@ var TemplatesWorker = class {
|
|
|
2472
2471
|
return eta$1.render(eta$1.compile(template, { async: false }), {
|
|
2473
2472
|
...this.getRenderTemplateData(),
|
|
2474
2473
|
...configuration
|
|
2475
|
-
}, { includeFile: (path
|
|
2474
|
+
}, { includeFile: (path, configuration) => this.renderTemplate(this.getTemplateContent(path), configuration) });
|
|
2476
2475
|
};
|
|
2477
2476
|
};
|
|
2478
2477
|
|
|
@@ -2539,51 +2538,50 @@ var TypeNameFormatter = class {
|
|
|
2539
2538
|
constructor(config) {
|
|
2540
2539
|
this.config = config;
|
|
2541
2540
|
}
|
|
2542
|
-
format = (name
|
|
2541
|
+
format = (name, options = {}) => {
|
|
2543
2542
|
const schemaType = options.type ?? "type-name";
|
|
2544
2543
|
const typePrefix = schemaType === "enum-key" ? this.config.enumKeyPrefix : this.config.typePrefix;
|
|
2545
2544
|
const typeSuffix = schemaType === "enum-key" ? this.config.enumKeySuffix : this.config.typeSuffix;
|
|
2546
|
-
const hashKey = `${typePrefix}_${name
|
|
2547
|
-
if (typeof name
|
|
2548
|
-
consola.consola.warn("wrong model name", name
|
|
2549
|
-
return name
|
|
2545
|
+
const hashKey = `${typePrefix}_${name}_${typeSuffix}`;
|
|
2546
|
+
if (typeof name !== "string") {
|
|
2547
|
+
consola.consola.warn("wrong model name", name);
|
|
2548
|
+
return name;
|
|
2550
2549
|
}
|
|
2551
|
-
if (/^(?!\d)([A-Z0-9_]{1,})$/g.test(name
|
|
2550
|
+
if (/^(?!\d)([A-Z0-9_]{1,})$/g.test(name)) return (0, es_toolkit.compact)([
|
|
2552
2551
|
typePrefix,
|
|
2553
|
-
name
|
|
2552
|
+
name,
|
|
2554
2553
|
typeSuffix
|
|
2555
2554
|
]).join("_");
|
|
2556
2555
|
if (this.formattedModelNamesMap.has(hashKey)) return this.formattedModelNamesMap.get(hashKey);
|
|
2557
|
-
const
|
|
2558
|
-
const
|
|
2559
|
-
const formattedResultName = this.config.hooks.onFormatTypeName(formattedName, name$1, schemaType) || formattedName;
|
|
2556
|
+
const formattedName = (0, es_toolkit_compat.startCase)(`${typePrefix}_${this.fixModelName(name, { type: schemaType })}_${typeSuffix}`).replace(/\s/g, "");
|
|
2557
|
+
const formattedResultName = this.config.hooks.onFormatTypeName(formattedName, name, schemaType) || formattedName;
|
|
2560
2558
|
this.formattedModelNamesMap.set(hashKey, formattedResultName);
|
|
2561
2559
|
return formattedResultName;
|
|
2562
2560
|
};
|
|
2563
|
-
isValidName = (name
|
|
2564
|
-
fixModelName = (name
|
|
2565
|
-
if (!this.isValidName(name
|
|
2566
|
-
if (!/^[a-zA-Z_$]/g.test(name
|
|
2567
|
-
if (name
|
|
2568
|
-
if (name
|
|
2561
|
+
isValidName = (name) => /^([A-Za-z$_]{1,})$/g.test(name);
|
|
2562
|
+
fixModelName = (name, options) => {
|
|
2563
|
+
if (!this.isValidName(name)) {
|
|
2564
|
+
if (!/^[a-zA-Z_$]/g.test(name)) return `${options.type === "enum-key" ? this.config.fixInvalidEnumKeyPrefix : this.config.fixInvalidTypeNamePrefix} ${name}`;
|
|
2565
|
+
if (name.includes(".")) return name.replace(/Exclude_keyof[A-Za-z]+/g, () => "ExcludeKeys").replace(/%22~AND~%22/g, "And").replace(/%22~OR~%22/g, "Or").replace(/(\.?%22)|\./g, "_").replace(/__+$/, "");
|
|
2566
|
+
if (name.includes("-")) return (0, es_toolkit_compat.startCase)(name).replace(/ /g, "");
|
|
2569
2567
|
}
|
|
2570
|
-
return name
|
|
2568
|
+
return name;
|
|
2571
2569
|
};
|
|
2572
2570
|
};
|
|
2573
2571
|
|
|
2574
2572
|
//#endregion
|
|
2575
2573
|
//#region src/util/file-system.ts
|
|
2576
2574
|
var FileSystem = class {
|
|
2577
|
-
getFileContent = (path
|
|
2578
|
-
return node_fs.readFileSync(path
|
|
2575
|
+
getFileContent = (path) => {
|
|
2576
|
+
return node_fs.readFileSync(path, { encoding: "utf8" });
|
|
2579
2577
|
};
|
|
2580
|
-
readDir = (path
|
|
2581
|
-
return node_fs.readdirSync(path
|
|
2578
|
+
readDir = (path) => {
|
|
2579
|
+
return node_fs.readdirSync(path);
|
|
2582
2580
|
};
|
|
2583
|
-
pathIsDir = (path
|
|
2584
|
-
if (!path
|
|
2581
|
+
pathIsDir = (path) => {
|
|
2582
|
+
if (!path) return false;
|
|
2585
2583
|
try {
|
|
2586
|
-
return node_fs.statSync(path
|
|
2584
|
+
return node_fs.statSync(path).isDirectory();
|
|
2587
2585
|
} catch (e) {
|
|
2588
2586
|
return false;
|
|
2589
2587
|
}
|
|
@@ -2593,36 +2591,45 @@ var FileSystem = class {
|
|
|
2593
2591
|
if (fileNameParts.length > 1) fileNameParts.pop();
|
|
2594
2592
|
return fileNameParts.join(".");
|
|
2595
2593
|
};
|
|
2596
|
-
removeDir = (path
|
|
2594
|
+
removeDir = (path) => {
|
|
2597
2595
|
try {
|
|
2598
|
-
if (typeof node_fs.rmSync === "function") node_fs.rmSync(path
|
|
2599
|
-
else node_fs.rmdirSync(path
|
|
2596
|
+
if (typeof node_fs.rmSync === "function") node_fs.rmSync(path, { recursive: true });
|
|
2597
|
+
else node_fs.rmdirSync(path, { recursive: true });
|
|
2600
2598
|
} catch (e) {
|
|
2601
2599
|
consola.consola.debug("failed to remove dir", e);
|
|
2602
2600
|
}
|
|
2603
2601
|
};
|
|
2604
|
-
createDir = (path
|
|
2602
|
+
createDir = (path) => {
|
|
2605
2603
|
try {
|
|
2606
|
-
node_fs.mkdirSync(path
|
|
2604
|
+
node_fs.mkdirSync(path, { recursive: true });
|
|
2607
2605
|
} catch (e) {
|
|
2608
2606
|
consola.consola.debug("failed to create dir", e);
|
|
2609
2607
|
}
|
|
2610
2608
|
};
|
|
2611
|
-
cleanDir = (path
|
|
2612
|
-
this.removeDir(path
|
|
2613
|
-
this.createDir(path
|
|
2609
|
+
cleanDir = (path) => {
|
|
2610
|
+
this.removeDir(path);
|
|
2611
|
+
this.createDir(path);
|
|
2614
2612
|
};
|
|
2615
|
-
pathIsExist = (path
|
|
2616
|
-
return !!path
|
|
2613
|
+
pathIsExist = (path) => {
|
|
2614
|
+
return !!path && node_fs.existsSync(path);
|
|
2617
2615
|
};
|
|
2618
2616
|
createFile = ({ path: path_, fileName, content, withPrefix }) => {
|
|
2619
|
-
const __dirname
|
|
2620
|
-
const absolutePath = node_path.resolve(__dirname
|
|
2617
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath(require("url").pathToFileURL(__filename).href));
|
|
2618
|
+
const absolutePath = node_path.resolve(__dirname, path_, `./${fileName}`);
|
|
2621
2619
|
const fileContent = `${withPrefix ? FILE_PREFIX : ""}${content}`;
|
|
2622
2620
|
return node_fs.writeFileSync(absolutePath, fileContent);
|
|
2623
2621
|
};
|
|
2624
2622
|
};
|
|
2625
2623
|
|
|
2624
|
+
//#endregion
|
|
2625
|
+
//#region src/util/lodash-compat.ts
|
|
2626
|
+
function createLodashCompat() {
|
|
2627
|
+
return {
|
|
2628
|
+
...es_toolkit,
|
|
2629
|
+
...es_toolkit_compat
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2626
2633
|
//#endregion
|
|
2627
2634
|
//#region src/code-gen-process.ts
|
|
2628
2635
|
const PATCHABLE_INSTANCES = [
|
|
@@ -2677,16 +2684,14 @@ var CodeGenProcess = class {
|
|
|
2677
2684
|
if (this.config.swaggerSchema) swagger.usageSchema = this.config.swaggerSchema;
|
|
2678
2685
|
if (this.config.originalSchema) swagger.originalSchema = this.config.originalSchema;
|
|
2679
2686
|
this.schemaComponentsMap.clear();
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
]), rawTypeData);
|
|
2686
|
-
}));
|
|
2687
|
+
for (const [componentName, component] of Object.entries(swagger.usageSchema.components || {})) for (const [typeName, rawTypeData] of Object.entries(component)) this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef([
|
|
2688
|
+
"components",
|
|
2689
|
+
componentName,
|
|
2690
|
+
typeName
|
|
2691
|
+
]), rawTypeData);
|
|
2687
2692
|
this.schemaComponentsMap.discriminatorsFirst();
|
|
2688
2693
|
this.schemaComponentsMap.enumsFirst();
|
|
2689
|
-
const parsedSchemas = this.schemaComponentsMap.filter(
|
|
2694
|
+
const parsedSchemas = this.schemaComponentsMap.filter((0, es_toolkit.compact)(["schemas", this.config.extractResponses && "responses"])).map((schemaComponent) => {
|
|
2690
2695
|
const parsed = this.schemaParserFabric.parseSchema(schemaComponent.rawTypeData, schemaComponent.typeName);
|
|
2691
2696
|
schemaComponent.typeData = parsed;
|
|
2692
2697
|
return parsed;
|
|
@@ -2744,7 +2749,7 @@ var CodeGenProcess = class {
|
|
|
2744
2749
|
utils: {
|
|
2745
2750
|
Ts: this.config.Ts,
|
|
2746
2751
|
formatDescription: this.schemaParserFabric.schemaFormatters.formatDescription,
|
|
2747
|
-
internalCase,
|
|
2752
|
+
internalCase: es_toolkit_compat.camelCase,
|
|
2748
2753
|
classNameCase: pascalCase,
|
|
2749
2754
|
pascalCase,
|
|
2750
2755
|
getInlineParseContent: this.schemaParserFabric.getInlineParseContent,
|
|
@@ -2761,7 +2766,7 @@ var CodeGenProcess = class {
|
|
|
2761
2766
|
return ` * ${line}${eol ? "\n" : ""}`;
|
|
2762
2767
|
},
|
|
2763
2768
|
NameResolver,
|
|
2764
|
-
_:
|
|
2769
|
+
_: createLodashCompat(),
|
|
2765
2770
|
require: this.templatesWorker.requireFnFromTemplate
|
|
2766
2771
|
},
|
|
2767
2772
|
config: this.config
|
|
@@ -2770,7 +2775,7 @@ var CodeGenProcess = class {
|
|
|
2770
2775
|
collectModelTypes = () => {
|
|
2771
2776
|
const components = this.schemaComponentsMap.getComponents();
|
|
2772
2777
|
let modelTypes = [];
|
|
2773
|
-
const modelTypeComponents =
|
|
2778
|
+
const modelTypeComponents = (0, es_toolkit.compact)(["schemas", this.config.extractResponses && "responses"]);
|
|
2774
2779
|
const getSchemaComponentsCount = () => this.schemaComponentsMap.filter(...modelTypeComponents).length;
|
|
2775
2780
|
let schemaComponentsCount = getSchemaComponentsCount();
|
|
2776
2781
|
let processedCount = 0;
|
|
@@ -2792,14 +2797,14 @@ var CodeGenProcess = class {
|
|
|
2792
2797
|
if (!typeInfo.typeData) typeInfo.typeData = this.schemaParserFabric.parseSchema(typeInfo.rawTypeData, typeInfo.typeName);
|
|
2793
2798
|
const rawTypeData = typeInfo.typeData;
|
|
2794
2799
|
const typeData = this.schemaParserFabric.schemaFormatters.base[rawTypeData.type] ? this.schemaParserFabric.schemaFormatters.base[rawTypeData.type](rawTypeData) : rawTypeData;
|
|
2795
|
-
const { typeIdentifier, name: originalName, content, description
|
|
2796
|
-
const name
|
|
2797
|
-
if (name
|
|
2800
|
+
const { typeIdentifier, name: originalName, content, description } = typeData;
|
|
2801
|
+
const name = this.typeNameFormatter.format(originalName);
|
|
2802
|
+
if (name === null) return null;
|
|
2798
2803
|
const preparedModelType = {
|
|
2799
2804
|
...typeData,
|
|
2800
2805
|
typeIdentifier,
|
|
2801
|
-
name
|
|
2802
|
-
description
|
|
2806
|
+
name,
|
|
2807
|
+
description,
|
|
2803
2808
|
$content: rawTypeData.content,
|
|
2804
2809
|
rawContent: rawTypeData.content,
|
|
2805
2810
|
content,
|
|
@@ -2811,7 +2816,7 @@ var CodeGenProcess = class {
|
|
|
2811
2816
|
generateOutputFiles = async ({ configuration }) => {
|
|
2812
2817
|
const { modular, templatesToRender } = this.config;
|
|
2813
2818
|
const output = modular ? await this.createMultipleFileInfos(templatesToRender, configuration) : await this.createSingleFileInfo(templatesToRender, configuration);
|
|
2814
|
-
if (
|
|
2819
|
+
if (configuration.extraTemplates?.length) for (const extraTemplate of configuration.extraTemplates) {
|
|
2815
2820
|
const content = this.templatesWorker.renderTemplate(this.fileSystem.getFileContent(extraTemplate.path), configuration);
|
|
2816
2821
|
output.push(...await this.createOutputFileInfo(configuration, extraTemplate.name, content));
|
|
2817
2822
|
}
|
|
@@ -2861,7 +2866,7 @@ var CodeGenProcess = class {
|
|
|
2861
2866
|
};
|
|
2862
2867
|
createSingleFileInfo = async (templatesToRender, configuration) => {
|
|
2863
2868
|
const { generateRouteTypes, generateClient } = configuration.config;
|
|
2864
|
-
return await this.createOutputFileInfo(configuration, configuration.fileName,
|
|
2869
|
+
return await this.createOutputFileInfo(configuration, configuration.fileName, (0, es_toolkit.compact)([
|
|
2865
2870
|
this.templatesWorker.renderTemplate(templatesToRender.dataContracts, configuration),
|
|
2866
2871
|
generateRouteTypes && this.templatesWorker.renderTemplate(templatesToRender.routeTypes, configuration),
|
|
2867
2872
|
generateClient && this.templatesWorker.renderTemplate(templatesToRender.httpClient, configuration),
|
|
@@ -2897,21 +2902,21 @@ var CodeGenProcess = class {
|
|
|
2897
2902
|
createApiConfig = (swaggerSchema) => {
|
|
2898
2903
|
const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
|
|
2899
2904
|
const server = servers?.[0] || { url: "" };
|
|
2900
|
-
const { title = "No title", version
|
|
2905
|
+
const { title = "No title", version } = info || {};
|
|
2901
2906
|
const { url: serverUrl } = server;
|
|
2902
2907
|
return {
|
|
2903
2908
|
info: info || {},
|
|
2904
2909
|
servers: servers || [],
|
|
2905
2910
|
basePath,
|
|
2906
2911
|
host,
|
|
2907
|
-
externalDocs:
|
|
2912
|
+
externalDocs: (0, es_toolkit.merge)({
|
|
2908
2913
|
url: "",
|
|
2909
2914
|
description: ""
|
|
2910
|
-
}, externalDocs),
|
|
2911
|
-
tags:
|
|
2915
|
+
}, externalDocs || {}),
|
|
2916
|
+
tags: (0, es_toolkit.compact)(tags || []),
|
|
2912
2917
|
baseUrl: serverUrl,
|
|
2913
2918
|
title,
|
|
2914
|
-
version
|
|
2919
|
+
version
|
|
2915
2920
|
};
|
|
2916
2921
|
};
|
|
2917
2922
|
injectClassInstance = (key, value) => {
|
|
@@ -2922,28 +2927,28 @@ var CodeGenProcess = class {
|
|
|
2922
2927
|
|
|
2923
2928
|
//#endregion
|
|
2924
2929
|
//#region types/index.ts
|
|
2925
|
-
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind
|
|
2926
|
-
RequestContentKind
|
|
2927
|
-
RequestContentKind
|
|
2928
|
-
RequestContentKind
|
|
2929
|
-
RequestContentKind
|
|
2930
|
-
RequestContentKind
|
|
2931
|
-
RequestContentKind
|
|
2932
|
-
return RequestContentKind
|
|
2930
|
+
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind) {
|
|
2931
|
+
RequestContentKind["JSON"] = "JSON";
|
|
2932
|
+
RequestContentKind["URL_ENCODED"] = "URL_ENCODED";
|
|
2933
|
+
RequestContentKind["FORM_DATA"] = "FORM_DATA";
|
|
2934
|
+
RequestContentKind["IMAGE"] = "IMAGE";
|
|
2935
|
+
RequestContentKind["OTHER"] = "OTHER";
|
|
2936
|
+
RequestContentKind["TEXT"] = "TEXT";
|
|
2937
|
+
return RequestContentKind;
|
|
2933
2938
|
}({});
|
|
2934
|
-
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES
|
|
2935
|
-
SCHEMA_TYPES
|
|
2936
|
-
SCHEMA_TYPES
|
|
2937
|
-
SCHEMA_TYPES
|
|
2938
|
-
SCHEMA_TYPES
|
|
2939
|
-
SCHEMA_TYPES
|
|
2940
|
-
SCHEMA_TYPES
|
|
2941
|
-
SCHEMA_TYPES
|
|
2942
|
-
SCHEMA_TYPES
|
|
2943
|
-
SCHEMA_TYPES
|
|
2944
|
-
SCHEMA_TYPES
|
|
2945
|
-
SCHEMA_TYPES
|
|
2946
|
-
return SCHEMA_TYPES
|
|
2939
|
+
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES) {
|
|
2940
|
+
SCHEMA_TYPES["ARRAY"] = "array";
|
|
2941
|
+
SCHEMA_TYPES["OBJECT"] = "object";
|
|
2942
|
+
SCHEMA_TYPES["ENUM"] = "enum";
|
|
2943
|
+
SCHEMA_TYPES["REF"] = "$ref";
|
|
2944
|
+
SCHEMA_TYPES["PRIMITIVE"] = "primitive";
|
|
2945
|
+
SCHEMA_TYPES["COMPLEX"] = "complex";
|
|
2946
|
+
SCHEMA_TYPES["COMPLEX_ONE_OF"] = "oneOf";
|
|
2947
|
+
SCHEMA_TYPES["COMPLEX_ANY_OF"] = "anyOf";
|
|
2948
|
+
SCHEMA_TYPES["COMPLEX_ALL_OF"] = "allOf";
|
|
2949
|
+
SCHEMA_TYPES["COMPLEX_NOT"] = "not";
|
|
2950
|
+
SCHEMA_TYPES["COMPLEX_UNKNOWN"] = "__unknown";
|
|
2951
|
+
return SCHEMA_TYPES;
|
|
2947
2952
|
}({});
|
|
2948
2953
|
|
|
2949
2954
|
//#endregion
|
|
@@ -2961,7 +2966,7 @@ var TemplatesGenConfig = class {
|
|
|
2961
2966
|
this.update(config);
|
|
2962
2967
|
}
|
|
2963
2968
|
update = (update) => {
|
|
2964
|
-
|
|
2969
|
+
Object.assign(this, update);
|
|
2965
2970
|
};
|
|
2966
2971
|
};
|
|
2967
2972
|
|
|
@@ -3075,14 +3080,6 @@ async function generateTemplates(config) {
|
|
|
3075
3080
|
return await new TemplatesGenProcess(config).start();
|
|
3076
3081
|
}
|
|
3077
3082
|
|
|
3078
|
-
//#endregion
|
|
3079
|
-
//#region src/index.ts
|
|
3080
|
-
async function generateApi(config) {
|
|
3081
|
-
if (config.debug) consola.consola.level = Number.MAX_SAFE_INTEGER;
|
|
3082
|
-
if (config.silent) consola.consola.level = 0;
|
|
3083
|
-
return await new CodeGenProcess(config).start();
|
|
3084
|
-
}
|
|
3085
|
-
|
|
3086
3083
|
//#endregion
|
|
3087
3084
|
Object.defineProperty(exports, 'CodeGenConfig', {
|
|
3088
3085
|
enumerable: true,
|
|
@@ -3090,6 +3087,12 @@ Object.defineProperty(exports, 'CodeGenConfig', {
|
|
|
3090
3087
|
return CodeGenConfig;
|
|
3091
3088
|
}
|
|
3092
3089
|
});
|
|
3090
|
+
Object.defineProperty(exports, 'CodeGenProcess', {
|
|
3091
|
+
enumerable: true,
|
|
3092
|
+
get: function () {
|
|
3093
|
+
return CodeGenProcess;
|
|
3094
|
+
}
|
|
3095
|
+
});
|
|
3093
3096
|
Object.defineProperty(exports, 'HTTP_CLIENT', {
|
|
3094
3097
|
enumerable: true,
|
|
3095
3098
|
get: function () {
|
|
@@ -3132,12 +3135,6 @@ Object.defineProperty(exports, 'description', {
|
|
|
3132
3135
|
return description;
|
|
3133
3136
|
}
|
|
3134
3137
|
});
|
|
3135
|
-
Object.defineProperty(exports, 'generateApi', {
|
|
3136
|
-
enumerable: true,
|
|
3137
|
-
get: function () {
|
|
3138
|
-
return generateApi;
|
|
3139
|
-
}
|
|
3140
|
-
});
|
|
3141
3138
|
Object.defineProperty(exports, 'generateTemplates', {
|
|
3142
3139
|
enumerable: true,
|
|
3143
3140
|
get: function () {
|
|
@@ -3156,4 +3153,4 @@ Object.defineProperty(exports, 'version', {
|
|
|
3156
3153
|
return version;
|
|
3157
3154
|
}
|
|
3158
3155
|
});
|
|
3159
|
-
//# sourceMappingURL=
|
|
3156
|
+
//# sourceMappingURL=generate-templates-wjE78AWV.cjs.map
|