swagger-typescript-api 13.2.16 → 13.2.18
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-DWf638kx.cjs → generate-templates-C4JBmSNw.cjs} +377 -359
- package/dist/generate-templates-C4JBmSNw.cjs.map +1 -0
- package/dist/{src-D-LZ3PGk.js → generate-templates-DGQlyLhe.mjs} +349 -337
- package/dist/generate-templates-DGQlyLhe.mjs.map +1 -0
- package/dist/index.cjs +17 -6
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +179 -289
- package/dist/index.d.cts.map +1 -1
- package/dist/{index.d.ts → index.d.mts} +179 -290
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +24 -28
- package/templates/base/data-contract-jsdoc.ejs +16 -16
- package/templates/base/object-field-jsdoc.ejs +8 -8
- package/templates/base/route-docs.ejs +7 -7
- package/templates/default/api.ejs +11 -11
- 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.18";
|
|
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,
|
|
@@ -290,8 +297,9 @@ const SCHEMA_TYPES$1 = {
|
|
|
290
297
|
const objectAssign = (target, updater) => {
|
|
291
298
|
if (!updater) return;
|
|
292
299
|
const update = typeof updater === "function" ? updater(target) : updater;
|
|
293
|
-
|
|
294
|
-
Object.
|
|
300
|
+
if (!update) return;
|
|
301
|
+
const undefinedKeys = Object.entries(update).filter(([, value]) => value === void 0).map(([key]) => key);
|
|
302
|
+
(0, es_toolkit.merge)(target, update);
|
|
295
303
|
for (const key of undefinedKeys) target[key] = void 0;
|
|
296
304
|
};
|
|
297
305
|
|
|
@@ -495,11 +503,11 @@ var CodeGenConfig = class {
|
|
|
495
503
|
BooleanValue: (content) => `${content}`,
|
|
496
504
|
NumberValue: (content) => `${content}`,
|
|
497
505
|
NullValue: () => "null",
|
|
498
|
-
UnionType: (contents) =>
|
|
506
|
+
UnionType: (contents) => (0, es_toolkit.uniq)(contents).join(` ${this.Ts.Keyword.Union} `),
|
|
499
507
|
ExpressionGroup: (content) => content ? `(${content})` : "",
|
|
500
|
-
IntersectionType: (contents) =>
|
|
508
|
+
IntersectionType: (contents) => (0, es_toolkit.uniq)(contents).join(` ${this.Ts.Keyword.Intersection} `),
|
|
501
509
|
RecordType: (key, value) => this.Ts.TypeWithGeneric(this.Ts.Keyword.Record, [key, value]),
|
|
502
|
-
TypeField: ({ readonly, key, optional, value }) =>
|
|
510
|
+
TypeField: ({ readonly, key, optional, value }) => (0, es_toolkit.compact)([
|
|
503
511
|
readonly && "readonly ",
|
|
504
512
|
key,
|
|
505
513
|
optional && "?",
|
|
@@ -509,12 +517,12 @@ var CodeGenConfig = class {
|
|
|
509
517
|
InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
|
|
510
518
|
EnumUsageKey: (enumStruct, key) => `${enumStruct}.${key}`,
|
|
511
519
|
EnumField: (key, value) => `${key} = ${value}`,
|
|
512
|
-
EnumFieldDescription: (description
|
|
513
|
-
if (description
|
|
520
|
+
EnumFieldDescription: (description) => {
|
|
521
|
+
if (description) return ` /** ${description} */`;
|
|
514
522
|
else return "";
|
|
515
523
|
},
|
|
516
|
-
EnumFieldsWrapper: (contents) =>
|
|
517
|
-
return [this.Ts.EnumFieldDescription(description
|
|
524
|
+
EnumFieldsWrapper: (contents) => contents.map(({ key, value, description }) => {
|
|
525
|
+
return (0, es_toolkit.compact)([this.Ts.EnumFieldDescription(description), ` ${this.Ts.EnumField(key, value)}`]).join("\n");
|
|
518
526
|
}).join(",\n"),
|
|
519
527
|
ObjectWrapper: (content) => `{\n${content}\n}`,
|
|
520
528
|
MultilineComment: (contents, formatFn) => [...contents.length === 1 ? [`/** ${contents[0]} */`] : [
|
|
@@ -604,13 +612,13 @@ var CodeGenConfig = class {
|
|
|
604
612
|
}
|
|
605
613
|
];
|
|
606
614
|
templateExtensions = [".eta", ".ejs"];
|
|
607
|
-
constructor({ codeGenConstructs, primitiveTypeConstructs, constants, templateInfos, hooks
|
|
615
|
+
constructor({ codeGenConstructs, primitiveTypeConstructs, constants, templateInfos, hooks, ...otherConfig }) {
|
|
608
616
|
objectAssign(this.Ts, codeGenConstructs);
|
|
609
617
|
objectAssign(this.primitiveTypes, primitiveTypeConstructs);
|
|
610
618
|
this.defaultResponseType = this.Ts.Keyword.Void;
|
|
611
619
|
this.update({
|
|
612
620
|
...otherConfig,
|
|
613
|
-
hooks:
|
|
621
|
+
hooks: (0, es_toolkit.merge)(this.hooks, hooks || {}),
|
|
614
622
|
constants: {
|
|
615
623
|
...constants_exports,
|
|
616
624
|
...constants
|
|
@@ -706,10 +714,14 @@ var SchemaFormatters = class {
|
|
|
706
714
|
$content: parsedSchema.content,
|
|
707
715
|
content: this.config.Ts.UnionType(parsedSchema.content.map(({ value }) => value))
|
|
708
716
|
};
|
|
717
|
+
const escapedContent = parsedSchema.content.map((item) => ({
|
|
718
|
+
...item,
|
|
719
|
+
description: item.description ? this.escapeJSDocContent(item.description) : ""
|
|
720
|
+
}));
|
|
709
721
|
return {
|
|
710
722
|
...parsedSchema,
|
|
711
723
|
$content: parsedSchema.content,
|
|
712
|
-
content: this.config.Ts.EnumFieldsWrapper(
|
|
724
|
+
content: this.config.Ts.EnumFieldsWrapper(escapedContent)
|
|
713
725
|
};
|
|
714
726
|
},
|
|
715
727
|
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
@@ -731,7 +743,7 @@ var SchemaFormatters = class {
|
|
|
731
743
|
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
732
744
|
return {
|
|
733
745
|
...parsedSchema,
|
|
734
|
-
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType(
|
|
746
|
+
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
747
|
};
|
|
736
748
|
},
|
|
737
749
|
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
@@ -748,14 +760,19 @@ var SchemaFormatters = class {
|
|
|
748
760
|
}
|
|
749
761
|
};
|
|
750
762
|
formatSchema = (parsedSchema, formatType = "base") => {
|
|
751
|
-
const schemaType =
|
|
752
|
-
return
|
|
763
|
+
const schemaType = (0, es_toolkit_compat.get)(parsedSchema, ["schemaType"]) || (0, es_toolkit_compat.get)(parsedSchema, ["$parsed", "schemaType"]);
|
|
764
|
+
return (0, es_toolkit_compat.get)(this, [formatType, schemaType])?.(parsedSchema) || parsedSchema;
|
|
753
765
|
};
|
|
754
|
-
|
|
755
|
-
if (
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
766
|
+
escapeJSDocContent = (content) => {
|
|
767
|
+
if (content === void 0) return "";
|
|
768
|
+
return (typeof content === "string" ? content : String(content)).replace(/\*\//g, "*\\/");
|
|
769
|
+
};
|
|
770
|
+
formatDescription = (description, inline) => {
|
|
771
|
+
if (!description) return "";
|
|
772
|
+
const escapedDescription = this.escapeJSDocContent(description);
|
|
773
|
+
if (!escapedDescription.includes("\n")) return escapedDescription;
|
|
774
|
+
if (inline) return (0, es_toolkit.compact)(escapedDescription.split(/\n/g).map((part) => part.trim())).join(" ");
|
|
775
|
+
return escapedDescription.replace(/\n$/g, "");
|
|
759
776
|
};
|
|
760
777
|
formatObjectContent = (content) => {
|
|
761
778
|
const fields = [];
|
|
@@ -816,7 +833,7 @@ var MonoSchemaParser = class {
|
|
|
816
833
|
var ArraySchemaParser = class extends MonoSchemaParser {
|
|
817
834
|
parse() {
|
|
818
835
|
let contentType;
|
|
819
|
-
const { type, description
|
|
836
|
+
const { type, description, items } = this.schema || {};
|
|
820
837
|
if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) {
|
|
821
838
|
const tupleContent = [];
|
|
822
839
|
for (const item of items) tupleContent.push(this.schemaParserFabric.createSchemaParser({
|
|
@@ -839,7 +856,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
839
856
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
840
857
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
841
858
|
name: this.typeName,
|
|
842
|
-
description: this.schemaFormatters.formatDescription(description
|
|
859
|
+
description: this.schemaFormatters.formatDescription(description),
|
|
843
860
|
content: this.schemaUtils.safeAddNullToType(this.schema, contentType)
|
|
844
861
|
};
|
|
845
862
|
}
|
|
@@ -850,7 +867,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
850
867
|
var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
851
868
|
parse() {
|
|
852
869
|
const complexType = this.schemaUtils.getComplexType(this.schema);
|
|
853
|
-
const simpleSchema =
|
|
870
|
+
const simpleSchema = (0, es_toolkit.omit)(this.schema, Object.keys(this.schemaParser._complexSchemaParsers));
|
|
854
871
|
const complexSchemaContent = this.schemaParser._complexSchemaParsers[complexType](this.schema);
|
|
855
872
|
return {
|
|
856
873
|
...typeof this.schema === "object" ? this.schema : {},
|
|
@@ -860,8 +877,8 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
860
877
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
861
878
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
862
879
|
name: this.typeName,
|
|
863
|
-
description: this.schemaFormatters.formatDescription(this.schema.description ||
|
|
864
|
-
content: this.config.Ts.IntersectionType(
|
|
880
|
+
description: this.schemaFormatters.formatDescription(this.schema.description || (0, es_toolkit.compact)((this.schema[complexType] || []).map((item) => item?.description))[0] || ""),
|
|
881
|
+
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
882
|
schema: simpleSchema,
|
|
866
883
|
schemaPath: this.schemaPath
|
|
867
884
|
}).getInlineParseContent())])) || this.config.Ts.Keyword.Any
|
|
@@ -874,7 +891,7 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
874
891
|
var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
875
892
|
parse() {
|
|
876
893
|
const ts = this.config.Ts;
|
|
877
|
-
const { discriminator
|
|
894
|
+
const { discriminator, ...noDiscriminatorSchema } = this.schema;
|
|
878
895
|
if (!discriminator.mapping) return this.schemaParserFabric.createSchemaParser({
|
|
879
896
|
schema: noDiscriminatorSchema,
|
|
880
897
|
typeName: this.typeName,
|
|
@@ -886,7 +903,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
886
903
|
skipMappingType,
|
|
887
904
|
abstractSchemaStruct
|
|
888
905
|
});
|
|
889
|
-
const schemaContent = ts.IntersectionType([abstractSchemaStruct?.content, discriminatorSchemaStruct?.content]
|
|
906
|
+
const schemaContent = ts.IntersectionType((0, es_toolkit.compact)([abstractSchemaStruct?.content, discriminatorSchemaStruct?.content]));
|
|
890
907
|
return {
|
|
891
908
|
...typeof this.schema === "object" ? this.schema : {},
|
|
892
909
|
$schemaPath: this.schemaPath.slice(),
|
|
@@ -907,7 +924,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
907
924
|
this.typeName
|
|
908
925
|
]);
|
|
909
926
|
const { discriminator } = this.schema;
|
|
910
|
-
const mappingEntries =
|
|
927
|
+
const mappingEntries = Object.entries(discriminator.mapping || {});
|
|
911
928
|
const ableToCreateMappingType = !skipMappingType && !!(abstractSchemaStruct?.typeName && mappingEntries.length);
|
|
912
929
|
const mappingContents = [];
|
|
913
930
|
let mappingTypeName;
|
|
@@ -967,22 +984,24 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
967
984
|
};
|
|
968
985
|
createMappingPropertySchemaEnumKeys = ({ abstractSchemaStruct, discPropertyName }) => {
|
|
969
986
|
const ts = this.config.Ts;
|
|
970
|
-
|
|
971
|
-
let mappingPropertySchema =
|
|
987
|
+
const mappingPropertySchemaEnumKeysMap = {};
|
|
988
|
+
let mappingPropertySchema = (0, es_toolkit_compat.get)(abstractSchemaStruct?.component?.rawTypeData, ["properties", discPropertyName]);
|
|
972
989
|
if (this.schemaUtils.isRefSchema(mappingPropertySchema)) mappingPropertySchema = this.schemaUtils.getSchemaRefType(mappingPropertySchema);
|
|
973
990
|
const parsedEnum = mappingPropertySchema?.rawTypeData?.$parsed;
|
|
974
|
-
if (parsedEnum?.type === SCHEMA_TYPES$1.ENUM)
|
|
975
|
-
const
|
|
976
|
-
|
|
977
|
-
const
|
|
978
|
-
if (
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
991
|
+
if (parsedEnum?.type === SCHEMA_TYPES$1.ENUM) {
|
|
992
|
+
const enumEntries = (parsedEnum.enum || []).map((key, index) => [key, index]);
|
|
993
|
+
for (const [key, index] of enumEntries) {
|
|
994
|
+
const enumContent = parsedEnum.content?.[index];
|
|
995
|
+
if (this.config.generateUnionEnums) {
|
|
996
|
+
const literalValue = enumContent?.value ?? (key !== void 0 ? ts.StringValue(key) : void 0);
|
|
997
|
+
if (literalValue !== void 0) mappingPropertySchemaEnumKeysMap[key] = literalValue;
|
|
998
|
+
} else if (parsedEnum.typeName && enumContent?.key) mappingPropertySchemaEnumKeysMap[key] = ts.EnumUsageKey(parsedEnum.typeName, enumContent.key);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
982
1001
|
return mappingPropertySchemaEnumKeysMap;
|
|
983
1002
|
};
|
|
984
1003
|
mutateMappingDependentSchema = ({ discPropertyName, abstractSchemaStruct, mappingSchema, refPath, mappingPropertySchemaEnumKeysMap }) => {
|
|
985
|
-
const complexSchemaKeys =
|
|
1004
|
+
const complexSchemaKeys = Object.keys(this.schemaParser._complexSchemaParsers);
|
|
986
1005
|
if (mappingSchema.$ref && abstractSchemaStruct?.component?.$ref) {
|
|
987
1006
|
const mappingRefSchema = this.schemaUtils.getSchemaRefType(mappingSchema)?.rawTypeData;
|
|
988
1007
|
if (mappingRefSchema) {
|
|
@@ -1001,11 +1020,11 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1001
1020
|
}
|
|
1002
1021
|
};
|
|
1003
1022
|
createAbstractSchemaStruct = () => {
|
|
1004
|
-
const { discriminator
|
|
1005
|
-
const complexSchemaKeys =
|
|
1006
|
-
const schema =
|
|
1023
|
+
const { discriminator, ...noDiscriminatorSchema } = this.schema;
|
|
1024
|
+
const complexSchemaKeys = Object.keys(this.schemaParser._complexSchemaParsers);
|
|
1025
|
+
const schema = (0, es_toolkit.omit)(structuredClone(noDiscriminatorSchema), complexSchemaKeys);
|
|
1007
1026
|
const schemaIsAny = this.schemaParserFabric.getInlineParseContent(structuredClone(schema)) === this.config.Ts.Keyword.Any;
|
|
1008
|
-
if (!
|
|
1027
|
+
if (!Object.keys(schema).length || schemaIsAny) return null;
|
|
1009
1028
|
const typeName = this.schemaUtils.resolveTypeName(this.typeName, {
|
|
1010
1029
|
prefixes: this.config.extractingOptions.discriminatorAbstractPrefix,
|
|
1011
1030
|
resolver: this.config.extractingOptions.discriminatorAbstractResolver
|
|
@@ -1074,9 +1093,9 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1074
1093
|
const refType = this.schemaUtils.getSchemaRefType(this.schema);
|
|
1075
1094
|
const $ref = refType?.$ref || null;
|
|
1076
1095
|
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
|
|
1096
|
+
if (Array.isArray(this.schema.enum) && Array.isArray(this.schema.enum[0])) return this.schemaParserFabric.parseSchema({ oneOf: this.schema.enum.map((enumNames) => ({
|
|
1078
1097
|
type: "array",
|
|
1079
|
-
items: enumNames
|
|
1098
|
+
items: enumNames.map((enumName) => ({
|
|
1080
1099
|
type: "string",
|
|
1081
1100
|
enum: [enumName]
|
|
1082
1101
|
}))
|
|
@@ -1101,8 +1120,8 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1101
1120
|
default: return this.config.Ts.StringValue(value);
|
|
1102
1121
|
}
|
|
1103
1122
|
};
|
|
1104
|
-
if (Array.isArray(enumNames) &&
|
|
1105
|
-
const enumValue =
|
|
1123
|
+
if (Array.isArray(enumNames) && enumNames.length > 0) content = enumNames.map((enumName, index) => {
|
|
1124
|
+
const enumValue = (0, es_toolkit_compat.get)(this.schema.enum, index);
|
|
1106
1125
|
const formattedKey = this.formatEnumKey({
|
|
1107
1126
|
key: enumName,
|
|
1108
1127
|
value: enumValue
|
|
@@ -1170,21 +1189,24 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1170
1189
|
}
|
|
1171
1190
|
getObjectSchemaContent = (schema) => {
|
|
1172
1191
|
const { properties, additionalProperties } = schema || {};
|
|
1173
|
-
const propertiesContent =
|
|
1174
|
-
|
|
1175
|
-
const
|
|
1192
|
+
const propertiesContent = [];
|
|
1193
|
+
for (const [name, property] of Object.entries(properties || {})) {
|
|
1194
|
+
const required = this.schemaUtils.isPropertyRequired(name, property, schema);
|
|
1195
|
+
const rawTypeData = (0, es_toolkit_compat.get)(this.schemaUtils.getSchemaRefType(property), "rawTypeData", {});
|
|
1176
1196
|
const nullable = !!(rawTypeData.nullable || property.nullable);
|
|
1177
|
-
const fieldName = this.typeNameFormatter.isValidName(name
|
|
1197
|
+
const fieldName = this.typeNameFormatter.isValidName(name) ? name : this.config.Ts.StringValue(name);
|
|
1178
1198
|
const fieldValue = this.schemaParserFabric.createSchemaParser({
|
|
1179
1199
|
schema: property,
|
|
1180
|
-
schemaPath: [...this.schemaPath, name
|
|
1200
|
+
schemaPath: [...this.schemaPath, name]
|
|
1181
1201
|
}).getInlineParseContent();
|
|
1182
1202
|
const readOnly = property.readOnly;
|
|
1183
|
-
|
|
1203
|
+
const complexType = this.schemaUtils.getComplexType(property);
|
|
1204
|
+
const rawDataComplexType = this.schemaUtils.getComplexType(rawTypeData);
|
|
1205
|
+
propertiesContent.push({
|
|
1184
1206
|
...property,
|
|
1185
1207
|
$$raw: property,
|
|
1186
1208
|
title: property.title,
|
|
1187
|
-
description: property.description ||
|
|
1209
|
+
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
1210
|
isRequired: required,
|
|
1189
1211
|
isNullable: nullable,
|
|
1190
1212
|
name: fieldName,
|
|
@@ -1195,8 +1217,8 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1195
1217
|
key: fieldName,
|
|
1196
1218
|
value: fieldValue
|
|
1197
1219
|
})
|
|
1198
|
-
};
|
|
1199
|
-
}
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1200
1222
|
if (additionalProperties) {
|
|
1201
1223
|
const propertyNamesSchema = this.schemaUtils.getSchemaPropertyNamesSchema(schema);
|
|
1202
1224
|
let interfaceKeysContent;
|
|
@@ -1221,7 +1243,7 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1221
1243
|
var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
1222
1244
|
parse() {
|
|
1223
1245
|
let contentType = null;
|
|
1224
|
-
const { additionalProperties, type, description
|
|
1246
|
+
const { additionalProperties, type, description, items } = this.schema || {};
|
|
1225
1247
|
if (type === this.config.Ts.Keyword.Object && additionalProperties) {
|
|
1226
1248
|
const propertyNamesSchema = this.schemaUtils.getSchemaPropertyNamesSchema(this.schema);
|
|
1227
1249
|
let recordKeysContent;
|
|
@@ -1240,7 +1262,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1240
1262
|
}
|
|
1241
1263
|
if (Array.isArray(type) && type.length) contentType = this.schemaParser._complexSchemaParsers.oneOf({
|
|
1242
1264
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1243
|
-
oneOf: type.map((type
|
|
1265
|
+
oneOf: type.map((type) => ({ type }))
|
|
1244
1266
|
});
|
|
1245
1267
|
if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1246
1268
|
schema: item,
|
|
@@ -1254,7 +1276,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1254
1276
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1255
1277
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
1256
1278
|
name: this.typeName,
|
|
1257
|
-
description: this.schemaFormatters.formatDescription(description
|
|
1279
|
+
description: this.schemaFormatters.formatDescription(description),
|
|
1258
1280
|
content: type === this.config.Ts.Keyword.Null ? type : contentType || this.schemaUtils.getSchemaType(this.schema)
|
|
1259
1281
|
};
|
|
1260
1282
|
}
|
|
@@ -1317,7 +1339,7 @@ var SchemaParser = class {
|
|
|
1317
1339
|
schemaWalker;
|
|
1318
1340
|
typeName;
|
|
1319
1341
|
schema;
|
|
1320
|
-
schemaPath
|
|
1342
|
+
schemaPath;
|
|
1321
1343
|
constructor(schemaParserFabric, { typeName, schema, schemaPath } = {}) {
|
|
1322
1344
|
this.schemaParserFabric = schemaParserFabric;
|
|
1323
1345
|
this.config = schemaParserFabric.config;
|
|
@@ -1389,7 +1411,7 @@ var SchemaParser = class {
|
|
|
1389
1411
|
}
|
|
1390
1412
|
schemaType = this.schemaUtils.getInternalSchemaType(this.schema);
|
|
1391
1413
|
this.schemaPath.push(this.typeName);
|
|
1392
|
-
|
|
1414
|
+
(0, es_toolkit.merge)(this.schema, this.config.hooks.onPreParseSchema(this.schema, this.typeName, schemaType) || {});
|
|
1393
1415
|
parsedSchema = this._baseSchemaParsers[schemaType](this.schema, this.typeName);
|
|
1394
1416
|
this.schema.$parsed = this.config.hooks.onParseSchema(this.schema, parsedSchema) || parsedSchema;
|
|
1395
1417
|
if (this.config.sortTypes && Array.isArray(this.schema.$parsed?.content)) this.schema.$parsed.content = this.schema.$parsed.content.sort(sortByProperty("name"));
|
|
@@ -1406,28 +1428,23 @@ var SchemaParser = class {
|
|
|
1406
1428
|
return this.schemaFormatters.formatSchema(parsedSchema, "base").content;
|
|
1407
1429
|
};
|
|
1408
1430
|
extractSchemaFromResponseStruct = (responseStruct) => {
|
|
1409
|
-
const { content
|
|
1410
|
-
const firstResponse =
|
|
1411
|
-
const firstSchema =
|
|
1431
|
+
const { content, ...extras } = responseStruct;
|
|
1432
|
+
const firstResponse = Object.values(content || {})[0];
|
|
1433
|
+
const firstSchema = (0, es_toolkit_compat.get)(firstResponse, "schema");
|
|
1412
1434
|
if (!firstSchema) return;
|
|
1435
|
+
const { schema: _, ...restResponse } = firstResponse || {};
|
|
1413
1436
|
return {
|
|
1414
1437
|
...extras,
|
|
1415
|
-
...
|
|
1438
|
+
...restResponse,
|
|
1416
1439
|
...firstSchema
|
|
1417
1440
|
};
|
|
1418
1441
|
};
|
|
1419
1442
|
};
|
|
1420
1443
|
|
|
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
1444
|
//#endregion
|
|
1428
1445
|
//#region src/util/pascal-case.ts
|
|
1429
1446
|
function pascalCase(value) {
|
|
1430
|
-
return
|
|
1447
|
+
return (0, es_toolkit_compat.upperFirst)((0, es_toolkit_compat.camelCase)(value));
|
|
1431
1448
|
}
|
|
1432
1449
|
|
|
1433
1450
|
//#endregion
|
|
@@ -1444,7 +1461,7 @@ var SchemaUtils = class {
|
|
|
1444
1461
|
this.schemaWalker = schemaWalker;
|
|
1445
1462
|
}
|
|
1446
1463
|
getRequiredProperties = (schema) => {
|
|
1447
|
-
return
|
|
1464
|
+
return (0, es_toolkit.uniq)(schema && Array.isArray(schema.required) && schema.required || []);
|
|
1448
1465
|
};
|
|
1449
1466
|
isRefSchema = (schema) => {
|
|
1450
1467
|
return !!schema?.$ref;
|
|
@@ -1463,15 +1480,15 @@ var SchemaUtils = class {
|
|
|
1463
1480
|
if (!this.isRefSchema(schema)) return null;
|
|
1464
1481
|
return this.schemaComponentsMap.get(schema.$ref);
|
|
1465
1482
|
};
|
|
1466
|
-
isPropertyRequired = (name
|
|
1483
|
+
isPropertyRequired = (name, propertySchema, rootSchema) => {
|
|
1467
1484
|
if (propertySchema["x-omitempty"] === false) return true;
|
|
1468
|
-
const isRequired = typeof propertySchema.required === "boolean" ? !!propertySchema.required : Array.isArray(rootSchema.required) ? rootSchema.required.includes(name
|
|
1485
|
+
const isRequired = typeof propertySchema.required === "boolean" ? !!propertySchema.required : Array.isArray(rootSchema.required) ? rootSchema.required.includes(name) : !!rootSchema.required;
|
|
1469
1486
|
if (this.config.convertedFromSwagger2) return typeof propertySchema.nullable === this.config.Ts.Keyword.Undefined ? isRequired : !propertySchema.nullable;
|
|
1470
1487
|
return isRequired;
|
|
1471
1488
|
};
|
|
1472
1489
|
isNullMissingInType = (schema, type) => {
|
|
1473
1490
|
const { nullable, type: schemaType } = schema || {};
|
|
1474
|
-
return (nullable || !!
|
|
1491
|
+
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
1492
|
};
|
|
1476
1493
|
safeAddNullToType = (schema, type) => {
|
|
1477
1494
|
if (this.isNullMissingInType(schema, type)) return this.config.Ts.UnionType([type, this.config.Ts.Keyword.Null]);
|
|
@@ -1479,13 +1496,13 @@ var SchemaUtils = class {
|
|
|
1479
1496
|
};
|
|
1480
1497
|
getSchemaPrimitiveType = (rawSchema) => {
|
|
1481
1498
|
const schema = rawSchema || {};
|
|
1482
|
-
if (schema.type) return
|
|
1499
|
+
if (schema.type) return (0, es_toolkit_compat.camelCase)(schema.type);
|
|
1483
1500
|
if (schema.enum) {
|
|
1484
1501
|
const enumFieldType = typeof schema.enum[0];
|
|
1485
1502
|
if (enumFieldType === this.config.Ts.Keyword.Undefined) return;
|
|
1486
|
-
return
|
|
1503
|
+
return (0, es_toolkit_compat.camelCase)(enumFieldType);
|
|
1487
1504
|
}
|
|
1488
|
-
if (
|
|
1505
|
+
if (Object.keys(schema.properties || {}).length) return SCHEMA_TYPES$1.OBJECT;
|
|
1489
1506
|
if (schema.items) return SCHEMA_TYPES$1.ARRAY;
|
|
1490
1507
|
return null;
|
|
1491
1508
|
};
|
|
@@ -1498,10 +1515,10 @@ var SchemaUtils = class {
|
|
|
1498
1515
|
};
|
|
1499
1516
|
makeAddRequiredToChildSchema = (parentSchema, childSchema) => {
|
|
1500
1517
|
if (!childSchema) return childSchema;
|
|
1501
|
-
const required =
|
|
1518
|
+
const required = (0, es_toolkit.uniq)([...this.getRequiredProperties(parentSchema), ...this.getRequiredProperties(childSchema)]);
|
|
1502
1519
|
const refData = this.getSchemaRefType(childSchema);
|
|
1503
1520
|
if (refData) {
|
|
1504
|
-
const existedRequiredKeys =
|
|
1521
|
+
const existedRequiredKeys = Object.keys(refData.rawTypeData?.properties || {}).filter((key) => required.includes(key));
|
|
1505
1522
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1506
1523
|
return {
|
|
1507
1524
|
...childSchema,
|
|
@@ -1509,17 +1526,17 @@ var SchemaUtils = class {
|
|
|
1509
1526
|
};
|
|
1510
1527
|
}
|
|
1511
1528
|
if (childSchema.properties) {
|
|
1512
|
-
const existedRequiredKeys =
|
|
1529
|
+
const existedRequiredKeys = Object.keys(childSchema.properties).filter((key) => required.includes(key));
|
|
1513
1530
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1514
1531
|
return {
|
|
1515
|
-
required:
|
|
1532
|
+
required: (0, es_toolkit.uniq)([...this.getRequiredProperties(childSchema), ...existedRequiredKeys]),
|
|
1516
1533
|
...childSchema
|
|
1517
1534
|
};
|
|
1518
1535
|
}
|
|
1519
1536
|
return childSchema;
|
|
1520
1537
|
};
|
|
1521
1538
|
filterSchemaContents = (contents, filterFn) => {
|
|
1522
|
-
return
|
|
1539
|
+
return (0, es_toolkit.uniq)(contents.filter((type) => filterFn(type)));
|
|
1523
1540
|
};
|
|
1524
1541
|
resolveTypeName = (typeName, { suffixes, resolver, prefixes, shouldReserve = true }) => {
|
|
1525
1542
|
if (resolver) return this.config.componentTypeNameResolver.resolve([], (reserved) => {
|
|
@@ -1535,10 +1552,10 @@ var SchemaUtils = class {
|
|
|
1535
1552
|
return SCHEMA_TYPES$1.COMPLEX_UNKNOWN;
|
|
1536
1553
|
};
|
|
1537
1554
|
getInternalSchemaType = (schema) => {
|
|
1538
|
-
if (
|
|
1555
|
+
if (schema.enum && schema.enum.length > 0 || this.getEnumNames(schema) && this.getEnumNames(schema).length > 0) return SCHEMA_TYPES$1.ENUM;
|
|
1539
1556
|
if (schema.discriminator) return SCHEMA_TYPES$1.DISCRIMINATOR;
|
|
1540
1557
|
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES$1.COMPLEX;
|
|
1541
|
-
if (
|
|
1558
|
+
if (schema.properties && Object.keys(schema.properties).length > 0) return SCHEMA_TYPES$1.OBJECT;
|
|
1542
1559
|
if (schema.type === SCHEMA_TYPES$1.ARRAY) return SCHEMA_TYPES$1.ARRAY;
|
|
1543
1560
|
return SCHEMA_TYPES$1.PRIMITIVE;
|
|
1544
1561
|
};
|
|
@@ -1551,7 +1568,7 @@ var SchemaUtils = class {
|
|
|
1551
1568
|
else {
|
|
1552
1569
|
const primitiveType = this.getSchemaPrimitiveType(schema);
|
|
1553
1570
|
if (primitiveType == null) return this.config.Ts.Keyword.Any;
|
|
1554
|
-
const typeAlias =
|
|
1571
|
+
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
1572
|
if (typeof typeAlias === "function") resultType = typeAlias(schema, this);
|
|
1556
1573
|
else resultType = typeAlias || primitiveType;
|
|
1557
1574
|
}
|
|
@@ -1559,9 +1576,9 @@ var SchemaUtils = class {
|
|
|
1559
1576
|
return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, resultType));
|
|
1560
1577
|
};
|
|
1561
1578
|
buildTypeNameFromPath = (schemaPath) => {
|
|
1562
|
-
schemaPath =
|
|
1579
|
+
schemaPath = (0, es_toolkit.uniq)((0, es_toolkit.compact)(schemaPath || []));
|
|
1563
1580
|
if (!schemaPath || !schemaPath[0]) return null;
|
|
1564
|
-
return pascalCase(
|
|
1581
|
+
return pascalCase((0, es_toolkit.uniq)([schemaPath[0], schemaPath[schemaPath.length - 1]]).join("_"));
|
|
1565
1582
|
};
|
|
1566
1583
|
isConstantSchema(schema) {
|
|
1567
1584
|
return "const" in schema;
|
|
@@ -1604,7 +1621,7 @@ var SchemaParserFabric = class {
|
|
|
1604
1621
|
schemaPath
|
|
1605
1622
|
});
|
|
1606
1623
|
};
|
|
1607
|
-
createSchema = ({ content, linkedSchema = {}, linkedComponent, schemaPath
|
|
1624
|
+
createSchema = ({ content, linkedSchema = {}, linkedComponent, schemaPath, ...otherSchemaProps }) => {
|
|
1608
1625
|
const parser = this.createSchemaParser({
|
|
1609
1626
|
schema: linkedComponent || linkedSchema,
|
|
1610
1627
|
schemaPath
|
|
@@ -1652,8 +1669,7 @@ var SchemaParserFabric = class {
|
|
|
1652
1669
|
|
|
1653
1670
|
//#endregion
|
|
1654
1671
|
//#region src/util/id.ts
|
|
1655
|
-
const
|
|
1656
|
-
const generateId = nanoid.customAlphabet(ALPHABET, 12);
|
|
1672
|
+
const generateId = () => node_crypto.randomUUID();
|
|
1657
1673
|
|
|
1658
1674
|
//#endregion
|
|
1659
1675
|
//#region src/schema-routes/util/specific-arg-name-resolver.ts
|
|
@@ -1698,7 +1714,7 @@ var SchemaRoutes = class {
|
|
|
1698
1714
|
this.typeNameFormatter = typeNameFormatter;
|
|
1699
1715
|
this.schemaComponentsMap = schemaComponentsMap;
|
|
1700
1716
|
this.templatesWorker = templatesWorker;
|
|
1701
|
-
this.FORM_DATA_TYPES =
|
|
1717
|
+
this.FORM_DATA_TYPES = (0, es_toolkit.uniq)([this.schemaUtils.getSchemaType({
|
|
1702
1718
|
type: "string",
|
|
1703
1719
|
format: "file"
|
|
1704
1720
|
}), this.schemaUtils.getSchemaType({
|
|
@@ -1706,49 +1722,50 @@ var SchemaRoutes = class {
|
|
|
1706
1722
|
format: "binary"
|
|
1707
1723
|
})]);
|
|
1708
1724
|
}
|
|
1709
|
-
createRequestsMap = (
|
|
1710
|
-
const parameters =
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1725
|
+
createRequestsMap = (routesByMethod) => {
|
|
1726
|
+
const parameters = (0, es_toolkit_compat.get)(routesByMethod, "parameters");
|
|
1727
|
+
const result = {};
|
|
1728
|
+
for (const [method, requestInfo] of Object.entries(routesByMethod)) {
|
|
1729
|
+
if (method.startsWith("x-") || ["parameters", "$ref"].includes(method)) continue;
|
|
1730
|
+
result[method] = {
|
|
1714
1731
|
...requestInfo,
|
|
1715
|
-
parameters:
|
|
1732
|
+
parameters: (0, es_toolkit.compact)([...parameters || [], ...requestInfo.parameters || []])
|
|
1716
1733
|
};
|
|
1717
|
-
|
|
1718
|
-
|
|
1734
|
+
}
|
|
1735
|
+
return result;
|
|
1719
1736
|
};
|
|
1720
|
-
parseRouteName = (
|
|
1721
|
-
const routeName = this.config.hooks.onPreBuildRoutePath(
|
|
1737
|
+
parseRouteName = (rawRoute) => {
|
|
1738
|
+
const routeName = this.config.hooks.onPreBuildRoutePath(rawRoute) || rawRoute;
|
|
1722
1739
|
const pathParamMatches = (routeName || "").match(/({[\w[\\\]^`][-_.\w]*})|(:[\w[\\\]^`][-_.\w]*:?)/g);
|
|
1723
|
-
const pathParams =
|
|
1740
|
+
const pathParams = [];
|
|
1741
|
+
for (const match of pathParamMatches || []) {
|
|
1724
1742
|
const paramName = match.replace(/\{|\}|:/g, "");
|
|
1725
|
-
if (!paramName)
|
|
1743
|
+
if (!paramName) continue;
|
|
1726
1744
|
if (paramName.includes("-")) consola.consola.warn("wrong path param name", paramName);
|
|
1727
|
-
pathParams
|
|
1745
|
+
pathParams.push({
|
|
1728
1746
|
$match: match,
|
|
1729
|
-
name:
|
|
1747
|
+
name: (0, es_toolkit_compat.camelCase)(paramName),
|
|
1730
1748
|
required: true,
|
|
1731
1749
|
type: "string",
|
|
1732
1750
|
description: "",
|
|
1733
1751
|
schema: { type: "string" },
|
|
1734
1752
|
in: "path"
|
|
1735
1753
|
});
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
return fixedRoute$1.replace(pathParam.$match, `\${${insertion}}`);
|
|
1754
|
+
}
|
|
1755
|
+
let fixedRoute = pathParams.reduce((fixedRoute, pathParam, i, arr) => {
|
|
1756
|
+
const insertion = this.config.hooks.onInsertPathParam(pathParam.name, i, arr, fixedRoute) || pathParam.name;
|
|
1757
|
+
return fixedRoute.replace(pathParam.$match, `\${${insertion}}`);
|
|
1741
1758
|
}, routeName || "");
|
|
1742
1759
|
const queryParamMatches = fixedRoute.match(/(\{\?.*\})/g);
|
|
1743
1760
|
const queryParams = [];
|
|
1744
1761
|
if (queryParamMatches?.length) {
|
|
1745
1762
|
for (const match of queryParamMatches) fixedRoute = fixedRoute.replace(match, "");
|
|
1746
|
-
const paramNames =
|
|
1763
|
+
const paramNames = (0, es_toolkit.uniq)(queryParamMatches.join(",").replace(/(\{\?)|(\})|\s/g, "").split(","));
|
|
1747
1764
|
for (const paramName of paramNames) {
|
|
1748
|
-
if (paramName.includes("-")) consola.consola.warn("wrong query param name", paramName);
|
|
1765
|
+
if (typeof paramName === "string" && paramName.includes("-")) consola.consola.warn("wrong query param name", paramName);
|
|
1749
1766
|
queryParams.push({
|
|
1750
1767
|
$match: paramName,
|
|
1751
|
-
name:
|
|
1768
|
+
name: typeof paramName === "string" ? (0, es_toolkit_compat.camelCase)(paramName) : (0, es_toolkit_compat.camelCase)(String(paramName)),
|
|
1752
1769
|
required: true,
|
|
1753
1770
|
type: "string",
|
|
1754
1771
|
description: "",
|
|
@@ -1758,7 +1775,7 @@ var SchemaRoutes = class {
|
|
|
1758
1775
|
}
|
|
1759
1776
|
}
|
|
1760
1777
|
const result = {
|
|
1761
|
-
originalRoute:
|
|
1778
|
+
originalRoute: rawRoute || "",
|
|
1762
1779
|
route: fixedRoute,
|
|
1763
1780
|
pathParams,
|
|
1764
1781
|
queryParams
|
|
@@ -1775,7 +1792,7 @@ var SchemaRoutes = class {
|
|
|
1775
1792
|
formData: [],
|
|
1776
1793
|
cookie: []
|
|
1777
1794
|
};
|
|
1778
|
-
|
|
1795
|
+
for (const parameter of parameters || []) {
|
|
1779
1796
|
const refTypeInfo = this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);
|
|
1780
1797
|
let routeParam = null;
|
|
1781
1798
|
if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
|
|
@@ -1786,7 +1803,7 @@ var SchemaRoutes = class {
|
|
|
1786
1803
|
};
|
|
1787
1804
|
if (parameter?.required && !routeParam.required) routeParam.required = parameter.required;
|
|
1788
1805
|
} else {
|
|
1789
|
-
if (!parameter.in)
|
|
1806
|
+
if (!parameter.in) continue;
|
|
1790
1807
|
if (!routeParams[parameter.in]) routeParams[parameter.in] = [];
|
|
1791
1808
|
routeParam = {
|
|
1792
1809
|
...parameter,
|
|
@@ -1794,16 +1811,19 @@ var SchemaRoutes = class {
|
|
|
1794
1811
|
};
|
|
1795
1812
|
}
|
|
1796
1813
|
if (routeParam.in === "path") {
|
|
1797
|
-
if (!routeParam.name)
|
|
1798
|
-
routeParam.name =
|
|
1814
|
+
if (!routeParam.name) continue;
|
|
1815
|
+
routeParam.name = (0, es_toolkit_compat.camelCase)(routeParam.name);
|
|
1799
1816
|
}
|
|
1800
|
-
|
|
1801
|
-
}
|
|
1817
|
+
routeParams[routeParam.in].push(routeParam);
|
|
1818
|
+
}
|
|
1802
1819
|
for (const pathParam of pathParamsFromRouteName) if (!routeParams.path.some((parameter) => parameter.name === pathParam.name)) routeParams.path.push(pathParam);
|
|
1803
1820
|
for (const queryParam of queryParamsFromRouteName) if (!routeParams.query.some((parameter) => parameter.name === queryParam.name)) routeParams.query.push(queryParam);
|
|
1804
1821
|
return routeParams;
|
|
1805
1822
|
};
|
|
1806
|
-
getContentTypes = (requestInfo, extraContentTypes) =>
|
|
1823
|
+
getContentTypes = (requestInfo, extraContentTypes) => {
|
|
1824
|
+
const requestInfoArray = Array.isArray(requestInfo) ? requestInfo : Object.values(requestInfo || {});
|
|
1825
|
+
return (0, es_toolkit.uniq)((0, es_toolkit.compact)([...extraContentTypes || [], ...(0, es_toolkit.flattenDeep)(requestInfoArray.map((requestInfoData) => requestInfoData && Object.keys(requestInfoData?.content || {})))]));
|
|
1826
|
+
};
|
|
1807
1827
|
getContentKind = (contentTypes) => {
|
|
1808
1828
|
if (contentTypes.includes("application/vnd.api+json")) return CONTENT_KIND.JSON_API;
|
|
1809
1829
|
if (contentTypes.some((contentType) => contentType.startsWith("application/json")) || contentTypes.some((contentType) => contentType.endsWith("+json"))) return CONTENT_KIND.JSON;
|
|
@@ -1815,7 +1835,7 @@ var SchemaRoutes = class {
|
|
|
1815
1835
|
};
|
|
1816
1836
|
isSuccessStatus = (status) => this.config.defaultResponseAsSuccess && status === "default" || +status >= this.config.successResponseStatusRange[0] && +status <= this.config.successResponseStatusRange[1] || status === "2xx";
|
|
1817
1837
|
getSchemaFromRequestType = (requestInfo) => {
|
|
1818
|
-
const content =
|
|
1838
|
+
const content = (0, es_toolkit_compat.get)(requestInfo, "content");
|
|
1819
1839
|
if (!content) return null;
|
|
1820
1840
|
for (const dataType in content) if (content[dataType]?.schema) return {
|
|
1821
1841
|
...content[dataType].schema,
|
|
@@ -1829,13 +1849,13 @@ var SchemaRoutes = class {
|
|
|
1829
1849
|
if (schema) {
|
|
1830
1850
|
const content = this.schemaParserFabric.getInlineParseContent(schema, typeName, [operationId]);
|
|
1831
1851
|
const foundedSchemaByName = parsedSchemas.find((parsedSchema) => this.typeNameFormatter.format(parsedSchema.name) === content);
|
|
1832
|
-
const foundSchemaByContent = parsedSchemas.find((parsedSchema) =>
|
|
1852
|
+
const foundSchemaByContent = parsedSchemas.find((parsedSchema) => (0, es_toolkit.isEqual)(parsedSchema.content, content));
|
|
1833
1853
|
const foundSchema = foundedSchemaByName || foundSchemaByContent;
|
|
1834
1854
|
return foundSchema ? this.typeNameFormatter.format(foundSchema.name) : content;
|
|
1835
1855
|
}
|
|
1836
1856
|
if (refTypeInfo) {
|
|
1837
1857
|
const typeNameWithoutOpId = refTypeInfo.typeName.replace(operationId, "");
|
|
1838
|
-
if (parsedSchemas.find((schema
|
|
1858
|
+
if (parsedSchemas.find((schema) => schema.name === typeNameWithoutOpId)) return this.typeNameFormatter.format(typeNameWithoutOpId);
|
|
1839
1859
|
switch (refTypeInfo.componentName) {
|
|
1840
1860
|
case "schemas": return this.typeNameFormatter.format(refTypeInfo.typeName);
|
|
1841
1861
|
case "responses":
|
|
@@ -1845,23 +1865,27 @@ var SchemaRoutes = class {
|
|
|
1845
1865
|
}
|
|
1846
1866
|
return defaultType || this.config.Ts.Keyword.Any;
|
|
1847
1867
|
};
|
|
1848
|
-
getRequestInfoTypes = ({ requestInfos, parsedSchemas, operationId, defaultType }) =>
|
|
1849
|
-
const
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1868
|
+
getRequestInfoTypes = ({ requestInfos, parsedSchemas, operationId, defaultType }) => {
|
|
1869
|
+
const result = [];
|
|
1870
|
+
for (const [status, requestInfo] of Object.entries(requestInfos || {})) {
|
|
1871
|
+
const contentTypes = this.getContentTypes([requestInfo], operationId);
|
|
1872
|
+
result.push({
|
|
1873
|
+
...requestInfo || {},
|
|
1874
|
+
contentTypes,
|
|
1875
|
+
contentKind: this.getContentKind(contentTypes),
|
|
1876
|
+
type: this.schemaParserFabric.schemaUtils.safeAddNullToType(requestInfo, this.getTypeFromRequestInfo({
|
|
1877
|
+
requestInfo,
|
|
1878
|
+
parsedSchemas,
|
|
1879
|
+
operationId,
|
|
1880
|
+
defaultType
|
|
1881
|
+
})),
|
|
1882
|
+
description: this.schemaParserFabric.schemaFormatters.formatDescription(requestInfo.description || "", true),
|
|
1883
|
+
status: Number.isNaN(+status) ? status : +status,
|
|
1884
|
+
isSuccess: this.isSuccessStatus(status)
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
return result;
|
|
1888
|
+
};
|
|
1865
1889
|
getResponseBodyInfo = (routeInfo, parsedSchemas) => {
|
|
1866
1890
|
const { produces, operationId, responses } = routeInfo;
|
|
1867
1891
|
const contentTypes = this.getContentTypes(responses, [...produces || [], routeInfo["x-accepts"]]);
|
|
@@ -1970,13 +1994,12 @@ var SchemaRoutes = class {
|
|
|
1970
1994
|
};
|
|
1971
1995
|
return acc;
|
|
1972
1996
|
}, {});
|
|
1973
|
-
const fixedQueryParams =
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
}, {});
|
|
1997
|
+
const fixedQueryParams = {};
|
|
1998
|
+
const queryObjectProperties = (0, es_toolkit_compat.get)(queryObjectSchema, "properties") || {};
|
|
1999
|
+
for (const [name, property] of Object.entries(queryObjectProperties)) if (name && typeof property === "object") fixedQueryParams[name] = {
|
|
2000
|
+
...property,
|
|
2001
|
+
in: "query"
|
|
2002
|
+
};
|
|
1980
2003
|
const schema = {
|
|
1981
2004
|
...queryObjectSchema,
|
|
1982
2005
|
properties: {
|
|
@@ -2019,7 +2042,7 @@ var SchemaRoutes = class {
|
|
|
2019
2042
|
successResponse.schema.contentKind = contentKind;
|
|
2020
2043
|
if (successResponse.schema.typeData) successResponse.schema.typeData.isExtractedResponseBody = true;
|
|
2021
2044
|
successResponse.type = this.schemaParserFabric.getInlineParseContent({ $ref: successResponse.schema.$ref });
|
|
2022
|
-
if (idx > -1)
|
|
2045
|
+
if (idx > -1) Object.assign(responseBodyInfo.responses[idx], {
|
|
2023
2046
|
...successResponse.schema,
|
|
2024
2047
|
type: successResponse.type
|
|
2025
2048
|
});
|
|
@@ -2032,18 +2055,18 @@ var SchemaRoutes = class {
|
|
|
2032
2055
|
suffixes: this.config.extractingOptions.responseErrorSuffix,
|
|
2033
2056
|
resolver: this.config.extractingOptions.responseErrorNameResolver
|
|
2034
2057
|
});
|
|
2035
|
-
const errorSchemas = responseBodyInfo.error.schemas.map(this.getSchemaFromRequestType)
|
|
2058
|
+
const errorSchemas = (0, es_toolkit.compact)(responseBodyInfo.error.schemas.map(this.getSchemaFromRequestType));
|
|
2036
2059
|
if (!errorSchemas.length) return;
|
|
2037
2060
|
const schema = this.schemaParserFabric.parseSchema({
|
|
2038
2061
|
oneOf: errorSchemas,
|
|
2039
|
-
title: errorSchemas.map((schema
|
|
2040
|
-
description: errorSchemas.map((schema
|
|
2062
|
+
title: (0, es_toolkit.compact)(errorSchemas.map((schema) => schema.title)).join(" "),
|
|
2063
|
+
description: (0, es_toolkit.compact)(errorSchemas.map((schema) => schema.description)).join("\n")
|
|
2041
2064
|
}, null, [routeInfo.operationId]);
|
|
2042
2065
|
const component = this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef([
|
|
2043
2066
|
"components",
|
|
2044
2067
|
"schemas",
|
|
2045
2068
|
typeName
|
|
2046
|
-
]),
|
|
2069
|
+
]), schema);
|
|
2047
2070
|
responseBodyInfo.error.schemas = [component];
|
|
2048
2071
|
if (component.typeData) component.typeData.isExtractedResponseError = true;
|
|
2049
2072
|
responseBodyInfo.error.type = this.typeNameFormatter.format(component.typeName);
|
|
@@ -2071,11 +2094,11 @@ var SchemaRoutes = class {
|
|
|
2071
2094
|
parseRouteInfo = (rawRouteName, routeInfo, method, usageSchema, parsedSchemas) => {
|
|
2072
2095
|
const { security: globalSecurity } = usageSchema;
|
|
2073
2096
|
const { moduleNameIndex, moduleNameFirstTag, extractRequestParams } = this.config;
|
|
2074
|
-
const { operationId, requestBody, security, parameters, summary, description
|
|
2097
|
+
const { operationId, requestBody, security, parameters, summary, description, tags, responses, requestBodyName, produces, consumes, ...otherInfo } = routeInfo;
|
|
2075
2098
|
const { route, pathParams: pathParamsFromRouteName, queryParams: queryParamsFromRouteName } = this.parseRouteName(rawRouteName);
|
|
2076
2099
|
const routeId = generateId();
|
|
2077
2100
|
const firstTag = tags && tags.length > 0 ? tags[0] : null;
|
|
2078
|
-
const moduleName = moduleNameFirstTag && firstTag ?
|
|
2101
|
+
const moduleName = moduleNameFirstTag && firstTag ? (0, es_toolkit_compat.camelCase)(firstTag) : (0, es_toolkit_compat.camelCase)((0, es_toolkit.compact)(route.split("/"))[moduleNameIndex] || "");
|
|
2079
2102
|
let hasSecurity = !!globalSecurity?.length;
|
|
2080
2103
|
if (security) hasSecurity = security.length > 0;
|
|
2081
2104
|
const routeParams = this.getRouteParams(routeInfo, pathParamsFromRouteName, queryParamsFromRouteName);
|
|
@@ -2095,7 +2118,7 @@ var SchemaRoutes = class {
|
|
|
2095
2118
|
route: rawRouteName,
|
|
2096
2119
|
moduleName,
|
|
2097
2120
|
responsesTypes: responseBodyInfo.responses,
|
|
2098
|
-
description
|
|
2121
|
+
description,
|
|
2099
2122
|
tags,
|
|
2100
2123
|
summary,
|
|
2101
2124
|
responses,
|
|
@@ -2192,7 +2215,7 @@ var SchemaRoutes = class {
|
|
|
2192
2215
|
};
|
|
2193
2216
|
attachSchema = ({ usageSchema, parsedSchemas }) => {
|
|
2194
2217
|
this.config.routeNameDuplicatesMap.clear();
|
|
2195
|
-
const pathsEntries =
|
|
2218
|
+
const pathsEntries = Object.entries(usageSchema.paths || {});
|
|
2196
2219
|
for (const [rawRouteName, routeInfoByMethodsMap] of pathsEntries) {
|
|
2197
2220
|
const routeInfosMap = this.createRequestsMap(routeInfoByMethodsMap);
|
|
2198
2221
|
for (const [method, routeInfo] of Object.entries(routeInfosMap)) {
|
|
@@ -2216,37 +2239,36 @@ var SchemaRoutes = class {
|
|
|
2216
2239
|
} else modules.$outOfModule.push(route);
|
|
2217
2240
|
return modules;
|
|
2218
2241
|
}, { $outOfModule: [] });
|
|
2219
|
-
const routeGroups =
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2242
|
+
const routeGroups = {
|
|
2243
|
+
outOfModule: void 0,
|
|
2244
|
+
combined: void 0
|
|
2245
|
+
};
|
|
2246
|
+
for (const [moduleName, routesGroup] of Object.entries(groupedRoutes)) if (moduleName === "$outOfModule") routeGroups.outOfModule = routesGroup;
|
|
2247
|
+
else {
|
|
2248
|
+
if (!routeGroups.combined) routeGroups.combined = [];
|
|
2249
|
+
routeGroups.combined.push({
|
|
2250
|
+
moduleName,
|
|
2251
|
+
routes: routesGroup.map((route) => {
|
|
2252
|
+
const { original: originalName, usage: usageName } = route.routeName;
|
|
2253
|
+
if (routesGroup.length > 1 && usageName !== originalName && !routesGroup.some(({ routeName, id }) => id !== route.id && originalName === routeName.original)) return {
|
|
2254
|
+
...route,
|
|
2255
|
+
routeName: {
|
|
2256
|
+
...route.routeName,
|
|
2257
|
+
usage: originalName
|
|
2258
|
+
}
|
|
2259
|
+
};
|
|
2260
|
+
return route;
|
|
2261
|
+
})
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2240
2264
|
if (this.config.sortRoutes) {
|
|
2241
2265
|
if (routeGroups.outOfModule) routeGroups.outOfModule = this.sortRoutes(routeGroups.outOfModule);
|
|
2242
|
-
if (routeGroups.combined)
|
|
2243
|
-
routeGroup.routes = this.sortRoutes(routeGroup.routes);
|
|
2244
|
-
});
|
|
2266
|
+
if (routeGroups.combined) for (const routeGroup of routeGroups.combined) routeGroup.routes = this.sortRoutes(routeGroup.routes);
|
|
2245
2267
|
}
|
|
2246
2268
|
return routeGroups;
|
|
2247
2269
|
};
|
|
2248
2270
|
sortRoutes = (routes) => {
|
|
2249
|
-
return
|
|
2271
|
+
return routes.slice().sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
|
|
2250
2272
|
};
|
|
2251
2273
|
};
|
|
2252
2274
|
|
|
@@ -2261,8 +2283,8 @@ var SchemaWalker = class {
|
|
|
2261
2283
|
this.config = config;
|
|
2262
2284
|
this.swaggerSchemaResolver = swaggerSchemaResolver;
|
|
2263
2285
|
}
|
|
2264
|
-
addSchema = (name
|
|
2265
|
-
this.schemas.set(name
|
|
2286
|
+
addSchema = (name, schema) => {
|
|
2287
|
+
this.schemas.set(name, structuredClone(schema));
|
|
2266
2288
|
};
|
|
2267
2289
|
_isLocalRef = (ref) => {
|
|
2268
2290
|
return ref.startsWith("#");
|
|
@@ -2271,8 +2293,7 @@ var SchemaWalker = class {
|
|
|
2271
2293
|
return ref.startsWith("http://") || ref.startsWith("https://");
|
|
2272
2294
|
};
|
|
2273
2295
|
_getRefDataFromSchema = (schema, ref) => {
|
|
2274
|
-
const
|
|
2275
|
-
const refData = lodash.default.get(schema, path$1);
|
|
2296
|
+
const refData = (0, es_toolkit_compat.get)(schema, ref.replace("#", "").split("/"));
|
|
2276
2297
|
if (refData) this.caches.set(ref, refData);
|
|
2277
2298
|
return refData;
|
|
2278
2299
|
};
|
|
@@ -2285,14 +2306,14 @@ var Request = class {
|
|
|
2285
2306
|
constructor(config) {
|
|
2286
2307
|
this.config = config;
|
|
2287
2308
|
}
|
|
2288
|
-
async download({ url
|
|
2309
|
+
async download({ url, authToken, ...options }) {
|
|
2289
2310
|
const requestOptions = {};
|
|
2290
2311
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2291
|
-
|
|
2312
|
+
(0, es_toolkit.merge)((0, es_toolkit.merge)(requestOptions, options), this.config.requestOptions || {});
|
|
2292
2313
|
try {
|
|
2293
|
-
return await (await fetch(url
|
|
2314
|
+
return await (await fetch(url, requestOptions)).text();
|
|
2294
2315
|
} catch (error) {
|
|
2295
|
-
const message = `error while fetching data from URL "${url
|
|
2316
|
+
const message = `error while fetching data from URL "${url}"`;
|
|
2296
2317
|
consola.consola.error(message, error);
|
|
2297
2318
|
return message;
|
|
2298
2319
|
}
|
|
@@ -2311,21 +2332,21 @@ var SwaggerSchemaResolver = class {
|
|
|
2311
2332
|
this.request = new Request(config);
|
|
2312
2333
|
}
|
|
2313
2334
|
async create() {
|
|
2314
|
-
const { spec, patch, input, url
|
|
2335
|
+
const { spec, patch, input, url, authorizationToken } = this.config;
|
|
2315
2336
|
if (spec) return await this.convertSwaggerObject(spec, { patch });
|
|
2316
|
-
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url
|
|
2337
|
+
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url, authorizationToken);
|
|
2317
2338
|
const swaggerSchemaObject = this.processSwaggerSchemaFile(swaggerSchemaFile);
|
|
2318
2339
|
return await this.convertSwaggerObject(swaggerSchemaObject, { patch });
|
|
2319
2340
|
}
|
|
2320
2341
|
convertSwaggerObject(swaggerSchema, converterOptions) {
|
|
2321
2342
|
return new Promise((resolve) => {
|
|
2322
2343
|
const result = structuredClone(swaggerSchema);
|
|
2323
|
-
result.info =
|
|
2344
|
+
result.info = (0, es_toolkit.merge)({
|
|
2324
2345
|
title: "No title",
|
|
2325
2346
|
version: ""
|
|
2326
|
-
}, result.info);
|
|
2347
|
+
}, result.info || {});
|
|
2327
2348
|
if (!Object.hasOwn(result, "openapi")) {
|
|
2328
|
-
result.paths =
|
|
2349
|
+
result.paths = (0, es_toolkit.merge)({}, result.paths || {});
|
|
2329
2350
|
swagger2openapi.convertObj(result, {
|
|
2330
2351
|
...converterOptions,
|
|
2331
2352
|
resolveInternal: true,
|
|
@@ -2333,7 +2354,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2333
2354
|
refSiblings: "preserve",
|
|
2334
2355
|
rbname: "requestBodyName"
|
|
2335
2356
|
}, (err, options) => {
|
|
2336
|
-
const parsedSwaggerSchema =
|
|
2357
|
+
const parsedSwaggerSchema = (0, es_toolkit_compat.get)(err, "options.openapi") ?? (0, es_toolkit_compat.get)(options, "openapi");
|
|
2337
2358
|
if (!parsedSwaggerSchema && err) throw err;
|
|
2338
2359
|
this.config.update({ convertedFromSwagger2: true });
|
|
2339
2360
|
resolve({
|
|
@@ -2368,23 +2389,21 @@ var SwaggerSchemaResolver = class {
|
|
|
2368
2389
|
}
|
|
2369
2390
|
}
|
|
2370
2391
|
fixSwaggerSchema({ usageSchema, originalSchema }) {
|
|
2371
|
-
const usagePaths =
|
|
2372
|
-
const originalPaths =
|
|
2373
|
-
|
|
2374
|
-
const originalPathObject =
|
|
2375
|
-
|
|
2376
|
-
const originalRouteInfo =
|
|
2377
|
-
const usageRouteParams =
|
|
2378
|
-
const originalRouteParams =
|
|
2392
|
+
const usagePaths = (0, es_toolkit_compat.get)(usageSchema, "paths") || {};
|
|
2393
|
+
const originalPaths = (0, es_toolkit_compat.get)(originalSchema, "paths") || {};
|
|
2394
|
+
for (const [route, usagePathObject] of Object.entries(usagePaths)) {
|
|
2395
|
+
const originalPathObject = (0, es_toolkit_compat.get)(originalPaths, route) || {};
|
|
2396
|
+
for (const [methodName, usageRouteInfo] of Object.entries(usagePathObject)) {
|
|
2397
|
+
const originalRouteInfo = (0, es_toolkit_compat.get)(originalPathObject, methodName) || {};
|
|
2398
|
+
const usageRouteParams = (0, es_toolkit_compat.get)(usageRouteInfo, "parameters") || [];
|
|
2399
|
+
const originalRouteParams = (0, es_toolkit_compat.get)(originalRouteInfo, "parameters") || [];
|
|
2379
2400
|
if (typeof usageRouteInfo === "object") {
|
|
2380
|
-
usageRouteInfo.consumes =
|
|
2381
|
-
usageRouteInfo.produces =
|
|
2401
|
+
usageRouteInfo.consumes = (0, es_toolkit.uniq)((0, es_toolkit.compact)([...usageRouteInfo.consumes || [], ...originalRouteInfo.consumes || []]));
|
|
2402
|
+
usageRouteInfo.produces = (0, es_toolkit.uniq)((0, es_toolkit.compact)([...usageRouteInfo.produces || [], ...originalRouteInfo.produces || []]));
|
|
2382
2403
|
}
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
});
|
|
2387
|
-
});
|
|
2404
|
+
for (const originalRouteParam of originalRouteParams) if (!usageRouteParams.find((param) => originalRouteParam.in === param.in && originalRouteParam.name === param.name)) usageRouteParams.push(originalRouteParam);
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2388
2407
|
}
|
|
2389
2408
|
};
|
|
2390
2409
|
|
|
@@ -2404,10 +2423,10 @@ var TemplatesWorker = class {
|
|
|
2404
2423
|
if (this.config.silent) consola.consola.level = 0;
|
|
2405
2424
|
}
|
|
2406
2425
|
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
|
|
2426
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath(require("url").pathToFileURL(__filename).href));
|
|
2427
|
+
const baseTemplatesPath = node_path.resolve(__dirname, "../templates/base");
|
|
2428
|
+
const defaultTemplatesPath = node_path.resolve(__dirname, "../templates/default");
|
|
2429
|
+
const modularTemplatesPath = node_path.resolve(__dirname, "../templates/modular");
|
|
2411
2430
|
return {
|
|
2412
2431
|
base: baseTemplatesPath,
|
|
2413
2432
|
default: defaultTemplatesPath,
|
|
@@ -2416,7 +2435,7 @@ var TemplatesWorker = class {
|
|
|
2416
2435
|
custom: config.templates && node_path.resolve(process.cwd(), config.templates)
|
|
2417
2436
|
};
|
|
2418
2437
|
};
|
|
2419
|
-
cropExtension = (path
|
|
2438
|
+
cropExtension = (path) => this.config.templateExtensions.reduce((path, ext) => path.endsWith(ext) ? path.replace(ext, "") : path, path);
|
|
2420
2439
|
getTemplateFullPath = (path_, fileName) => {
|
|
2421
2440
|
const raw = node_path.resolve(path_, "./", this.cropExtension(fileName));
|
|
2422
2441
|
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
@@ -2425,39 +2444,39 @@ var TemplatesWorker = class {
|
|
|
2425
2444
|
if (packageOrPath.startsWith("./") || packageOrPath.startsWith("../")) return require$1(node_path.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2426
2445
|
return require$1(packageOrPath);
|
|
2427
2446
|
};
|
|
2428
|
-
getTemplate = (name
|
|
2447
|
+
getTemplate = (name, fileName, path) => {
|
|
2429
2448
|
const { templatePaths } = this.config;
|
|
2430
|
-
if (path
|
|
2449
|
+
if (path) return this.fileSystem.getFileContent(path);
|
|
2431
2450
|
if (!fileName) return "";
|
|
2432
2451
|
const customFullPath = templatePaths.custom && this.getTemplateFullPath(templatePaths.custom, fileName);
|
|
2433
2452
|
let fileContent = customFullPath && this.fileSystem.getFileContent(customFullPath);
|
|
2434
2453
|
if (fileContent) {
|
|
2435
|
-
consola.consola.info(`"${name
|
|
2454
|
+
consola.consola.info(`"${name.toLowerCase()}" template found in "${templatePaths.custom}"`);
|
|
2436
2455
|
return fileContent;
|
|
2437
2456
|
}
|
|
2438
2457
|
const baseFullPath = this.getTemplateFullPath(templatePaths.base, fileName);
|
|
2439
2458
|
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
|
|
2459
|
+
else if (templatePaths.custom) consola.consola.warn("Code generator will use the default template:", `"${name.toLowerCase()}"`, "template not found in", `"${templatePaths.custom}"`);
|
|
2460
|
+
else consola.consola.info(`Code generator will use the default template for "${name.toLowerCase()}"`);
|
|
2442
2461
|
const originalFullPath = this.getTemplateFullPath(templatePaths.original, fileName);
|
|
2443
2462
|
if (originalFullPath) fileContent = this.fileSystem.getFileContent(originalFullPath);
|
|
2444
2463
|
return fileContent;
|
|
2445
2464
|
};
|
|
2446
2465
|
getTemplates = ({ templatePaths }) => {
|
|
2447
2466
|
if (templatePaths.custom) consola.consola.info(`try to read templates from directory "${templatePaths.custom}"`);
|
|
2448
|
-
return
|
|
2467
|
+
return this.config.templateInfos.reduce((acc, { name, fileName }) => ({
|
|
2449
2468
|
...acc,
|
|
2450
|
-
[name
|
|
2469
|
+
[name]: this.getTemplate(name, fileName)
|
|
2451
2470
|
}), {});
|
|
2452
2471
|
};
|
|
2453
|
-
findTemplateWithExt = (path
|
|
2454
|
-
const raw = this.cropExtension(path
|
|
2472
|
+
findTemplateWithExt = (path) => {
|
|
2473
|
+
const raw = this.cropExtension(path);
|
|
2455
2474
|
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2456
2475
|
};
|
|
2457
2476
|
getTemplateContent = (path_) => {
|
|
2458
|
-
const foundTemplatePathKey =
|
|
2477
|
+
const foundTemplatePathKey = Object.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
2459
2478
|
if (foundTemplatePathKey) {
|
|
2460
|
-
const rawPath = node_path.resolve(path_.replace(`@${foundTemplatePathKey}`,
|
|
2479
|
+
const rawPath = node_path.resolve(path_.replace(`@${foundTemplatePathKey}`, (0, es_toolkit_compat.get)(this.config.templatePaths, foundTemplatePathKey)));
|
|
2461
2480
|
const fixedPath = this.findTemplateWithExt(rawPath);
|
|
2462
2481
|
if (fixedPath) return this.fileSystem.getFileContent(fixedPath);
|
|
2463
2482
|
}
|
|
@@ -2472,7 +2491,7 @@ var TemplatesWorker = class {
|
|
|
2472
2491
|
return eta$1.render(eta$1.compile(template, { async: false }), {
|
|
2473
2492
|
...this.getRenderTemplateData(),
|
|
2474
2493
|
...configuration
|
|
2475
|
-
}, { includeFile: (path
|
|
2494
|
+
}, { includeFile: (path, configuration) => this.renderTemplate(this.getTemplateContent(path), configuration) });
|
|
2476
2495
|
};
|
|
2477
2496
|
};
|
|
2478
2497
|
|
|
@@ -2539,51 +2558,50 @@ var TypeNameFormatter = class {
|
|
|
2539
2558
|
constructor(config) {
|
|
2540
2559
|
this.config = config;
|
|
2541
2560
|
}
|
|
2542
|
-
format = (name
|
|
2561
|
+
format = (name, options = {}) => {
|
|
2543
2562
|
const schemaType = options.type ?? "type-name";
|
|
2544
2563
|
const typePrefix = schemaType === "enum-key" ? this.config.enumKeyPrefix : this.config.typePrefix;
|
|
2545
2564
|
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
|
|
2565
|
+
const hashKey = `${typePrefix}_${name}_${typeSuffix}`;
|
|
2566
|
+
if (typeof name !== "string") {
|
|
2567
|
+
consola.consola.warn("wrong model name", name);
|
|
2568
|
+
return name;
|
|
2550
2569
|
}
|
|
2551
|
-
if (/^(?!\d)([A-Z0-9_]{1,})$/g.test(name
|
|
2570
|
+
if (/^(?!\d)([A-Z0-9_]{1,})$/g.test(name)) return (0, es_toolkit.compact)([
|
|
2552
2571
|
typePrefix,
|
|
2553
|
-
name
|
|
2572
|
+
name,
|
|
2554
2573
|
typeSuffix
|
|
2555
2574
|
]).join("_");
|
|
2556
2575
|
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;
|
|
2576
|
+
const formattedName = (0, es_toolkit_compat.startCase)(`${typePrefix}_${this.fixModelName(name, { type: schemaType })}_${typeSuffix}`).replace(/\s/g, "");
|
|
2577
|
+
const formattedResultName = this.config.hooks.onFormatTypeName(formattedName, name, schemaType) || formattedName;
|
|
2560
2578
|
this.formattedModelNamesMap.set(hashKey, formattedResultName);
|
|
2561
2579
|
return formattedResultName;
|
|
2562
2580
|
};
|
|
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
|
|
2581
|
+
isValidName = (name) => /^([A-Za-z$_]{1,})$/g.test(name);
|
|
2582
|
+
fixModelName = (name, options) => {
|
|
2583
|
+
if (!this.isValidName(name)) {
|
|
2584
|
+
if (!/^[a-zA-Z_$]/g.test(name)) return `${options.type === "enum-key" ? this.config.fixInvalidEnumKeyPrefix : this.config.fixInvalidTypeNamePrefix} ${name}`;
|
|
2585
|
+
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(/__+$/, "");
|
|
2586
|
+
if (name.includes("-")) return (0, es_toolkit_compat.startCase)(name).replace(/ /g, "");
|
|
2569
2587
|
}
|
|
2570
|
-
return name
|
|
2588
|
+
return name;
|
|
2571
2589
|
};
|
|
2572
2590
|
};
|
|
2573
2591
|
|
|
2574
2592
|
//#endregion
|
|
2575
2593
|
//#region src/util/file-system.ts
|
|
2576
2594
|
var FileSystem = class {
|
|
2577
|
-
getFileContent = (path
|
|
2578
|
-
return node_fs.readFileSync(path
|
|
2595
|
+
getFileContent = (path) => {
|
|
2596
|
+
return node_fs.readFileSync(path, { encoding: "utf8" });
|
|
2579
2597
|
};
|
|
2580
|
-
readDir = (path
|
|
2581
|
-
return node_fs.readdirSync(path
|
|
2598
|
+
readDir = (path) => {
|
|
2599
|
+
return node_fs.readdirSync(path);
|
|
2582
2600
|
};
|
|
2583
|
-
pathIsDir = (path
|
|
2584
|
-
if (!path
|
|
2601
|
+
pathIsDir = (path) => {
|
|
2602
|
+
if (!path) return false;
|
|
2585
2603
|
try {
|
|
2586
|
-
return node_fs.statSync(path
|
|
2604
|
+
return node_fs.statSync(path).isDirectory();
|
|
2587
2605
|
} catch (e) {
|
|
2588
2606
|
return false;
|
|
2589
2607
|
}
|
|
@@ -2593,36 +2611,45 @@ var FileSystem = class {
|
|
|
2593
2611
|
if (fileNameParts.length > 1) fileNameParts.pop();
|
|
2594
2612
|
return fileNameParts.join(".");
|
|
2595
2613
|
};
|
|
2596
|
-
removeDir = (path
|
|
2614
|
+
removeDir = (path) => {
|
|
2597
2615
|
try {
|
|
2598
|
-
if (typeof node_fs.rmSync === "function") node_fs.rmSync(path
|
|
2599
|
-
else node_fs.rmdirSync(path
|
|
2616
|
+
if (typeof node_fs.rmSync === "function") node_fs.rmSync(path, { recursive: true });
|
|
2617
|
+
else node_fs.rmdirSync(path, { recursive: true });
|
|
2600
2618
|
} catch (e) {
|
|
2601
2619
|
consola.consola.debug("failed to remove dir", e);
|
|
2602
2620
|
}
|
|
2603
2621
|
};
|
|
2604
|
-
createDir = (path
|
|
2622
|
+
createDir = (path) => {
|
|
2605
2623
|
try {
|
|
2606
|
-
node_fs.mkdirSync(path
|
|
2624
|
+
node_fs.mkdirSync(path, { recursive: true });
|
|
2607
2625
|
} catch (e) {
|
|
2608
2626
|
consola.consola.debug("failed to create dir", e);
|
|
2609
2627
|
}
|
|
2610
2628
|
};
|
|
2611
|
-
cleanDir = (path
|
|
2612
|
-
this.removeDir(path
|
|
2613
|
-
this.createDir(path
|
|
2629
|
+
cleanDir = (path) => {
|
|
2630
|
+
this.removeDir(path);
|
|
2631
|
+
this.createDir(path);
|
|
2614
2632
|
};
|
|
2615
|
-
pathIsExist = (path
|
|
2616
|
-
return !!path
|
|
2633
|
+
pathIsExist = (path) => {
|
|
2634
|
+
return !!path && node_fs.existsSync(path);
|
|
2617
2635
|
};
|
|
2618
2636
|
createFile = ({ path: path_, fileName, content, withPrefix }) => {
|
|
2619
|
-
const __dirname
|
|
2620
|
-
const absolutePath = node_path.resolve(__dirname
|
|
2637
|
+
const __dirname = node_path.dirname(node_url.fileURLToPath(require("url").pathToFileURL(__filename).href));
|
|
2638
|
+
const absolutePath = node_path.resolve(__dirname, path_, `./${fileName}`);
|
|
2621
2639
|
const fileContent = `${withPrefix ? FILE_PREFIX : ""}${content}`;
|
|
2622
2640
|
return node_fs.writeFileSync(absolutePath, fileContent);
|
|
2623
2641
|
};
|
|
2624
2642
|
};
|
|
2625
2643
|
|
|
2644
|
+
//#endregion
|
|
2645
|
+
//#region src/util/lodash-compat.ts
|
|
2646
|
+
function createLodashCompat() {
|
|
2647
|
+
return {
|
|
2648
|
+
...es_toolkit,
|
|
2649
|
+
...es_toolkit_compat
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2626
2653
|
//#endregion
|
|
2627
2654
|
//#region src/code-gen-process.ts
|
|
2628
2655
|
const PATCHABLE_INSTANCES = [
|
|
@@ -2677,16 +2704,14 @@ var CodeGenProcess = class {
|
|
|
2677
2704
|
if (this.config.swaggerSchema) swagger.usageSchema = this.config.swaggerSchema;
|
|
2678
2705
|
if (this.config.originalSchema) swagger.originalSchema = this.config.originalSchema;
|
|
2679
2706
|
this.schemaComponentsMap.clear();
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
]), rawTypeData);
|
|
2686
|
-
}));
|
|
2707
|
+
for (const [componentName, component] of Object.entries(swagger.usageSchema.components || {})) for (const [typeName, rawTypeData] of Object.entries(component)) this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef([
|
|
2708
|
+
"components",
|
|
2709
|
+
componentName,
|
|
2710
|
+
typeName
|
|
2711
|
+
]), rawTypeData);
|
|
2687
2712
|
this.schemaComponentsMap.discriminatorsFirst();
|
|
2688
2713
|
this.schemaComponentsMap.enumsFirst();
|
|
2689
|
-
const parsedSchemas = this.schemaComponentsMap.filter(
|
|
2714
|
+
const parsedSchemas = this.schemaComponentsMap.filter((0, es_toolkit.compact)(["schemas", this.config.extractResponses && "responses"])).map((schemaComponent) => {
|
|
2690
2715
|
const parsed = this.schemaParserFabric.parseSchema(schemaComponent.rawTypeData, schemaComponent.typeName);
|
|
2691
2716
|
schemaComponent.typeData = parsed;
|
|
2692
2717
|
return parsed;
|
|
@@ -2744,7 +2769,8 @@ var CodeGenProcess = class {
|
|
|
2744
2769
|
utils: {
|
|
2745
2770
|
Ts: this.config.Ts,
|
|
2746
2771
|
formatDescription: this.schemaParserFabric.schemaFormatters.formatDescription,
|
|
2747
|
-
|
|
2772
|
+
escapeJSDocContent: this.schemaParserFabric.schemaFormatters.escapeJSDocContent,
|
|
2773
|
+
internalCase: es_toolkit_compat.camelCase,
|
|
2748
2774
|
classNameCase: pascalCase,
|
|
2749
2775
|
pascalCase,
|
|
2750
2776
|
getInlineParseContent: this.schemaParserFabric.getInlineParseContent,
|
|
@@ -2761,7 +2787,7 @@ var CodeGenProcess = class {
|
|
|
2761
2787
|
return ` * ${line}${eol ? "\n" : ""}`;
|
|
2762
2788
|
},
|
|
2763
2789
|
NameResolver,
|
|
2764
|
-
_:
|
|
2790
|
+
_: createLodashCompat(),
|
|
2765
2791
|
require: this.templatesWorker.requireFnFromTemplate
|
|
2766
2792
|
},
|
|
2767
2793
|
config: this.config
|
|
@@ -2770,7 +2796,7 @@ var CodeGenProcess = class {
|
|
|
2770
2796
|
collectModelTypes = () => {
|
|
2771
2797
|
const components = this.schemaComponentsMap.getComponents();
|
|
2772
2798
|
let modelTypes = [];
|
|
2773
|
-
const modelTypeComponents =
|
|
2799
|
+
const modelTypeComponents = (0, es_toolkit.compact)(["schemas", this.config.extractResponses && "responses"]);
|
|
2774
2800
|
const getSchemaComponentsCount = () => this.schemaComponentsMap.filter(...modelTypeComponents).length;
|
|
2775
2801
|
let schemaComponentsCount = getSchemaComponentsCount();
|
|
2776
2802
|
let processedCount = 0;
|
|
@@ -2792,14 +2818,14 @@ var CodeGenProcess = class {
|
|
|
2792
2818
|
if (!typeInfo.typeData) typeInfo.typeData = this.schemaParserFabric.parseSchema(typeInfo.rawTypeData, typeInfo.typeName);
|
|
2793
2819
|
const rawTypeData = typeInfo.typeData;
|
|
2794
2820
|
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
|
|
2821
|
+
const { typeIdentifier, name: originalName, content, description } = typeData;
|
|
2822
|
+
const name = this.typeNameFormatter.format(originalName);
|
|
2823
|
+
if (name === null) return null;
|
|
2798
2824
|
const preparedModelType = {
|
|
2799
2825
|
...typeData,
|
|
2800
2826
|
typeIdentifier,
|
|
2801
|
-
name
|
|
2802
|
-
description
|
|
2827
|
+
name,
|
|
2828
|
+
description,
|
|
2803
2829
|
$content: rawTypeData.content,
|
|
2804
2830
|
rawContent: rawTypeData.content,
|
|
2805
2831
|
content,
|
|
@@ -2811,7 +2837,7 @@ var CodeGenProcess = class {
|
|
|
2811
2837
|
generateOutputFiles = async ({ configuration }) => {
|
|
2812
2838
|
const { modular, templatesToRender } = this.config;
|
|
2813
2839
|
const output = modular ? await this.createMultipleFileInfos(templatesToRender, configuration) : await this.createSingleFileInfo(templatesToRender, configuration);
|
|
2814
|
-
if (
|
|
2840
|
+
if (configuration.extraTemplates?.length) for (const extraTemplate of configuration.extraTemplates) {
|
|
2815
2841
|
const content = this.templatesWorker.renderTemplate(this.fileSystem.getFileContent(extraTemplate.path), configuration);
|
|
2816
2842
|
output.push(...await this.createOutputFileInfo(configuration, extraTemplate.name, content));
|
|
2817
2843
|
}
|
|
@@ -2861,7 +2887,7 @@ var CodeGenProcess = class {
|
|
|
2861
2887
|
};
|
|
2862
2888
|
createSingleFileInfo = async (templatesToRender, configuration) => {
|
|
2863
2889
|
const { generateRouteTypes, generateClient } = configuration.config;
|
|
2864
|
-
return await this.createOutputFileInfo(configuration, configuration.fileName,
|
|
2890
|
+
return await this.createOutputFileInfo(configuration, configuration.fileName, (0, es_toolkit.compact)([
|
|
2865
2891
|
this.templatesWorker.renderTemplate(templatesToRender.dataContracts, configuration),
|
|
2866
2892
|
generateRouteTypes && this.templatesWorker.renderTemplate(templatesToRender.routeTypes, configuration),
|
|
2867
2893
|
generateClient && this.templatesWorker.renderTemplate(templatesToRender.httpClient, configuration),
|
|
@@ -2897,21 +2923,21 @@ var CodeGenProcess = class {
|
|
|
2897
2923
|
createApiConfig = (swaggerSchema) => {
|
|
2898
2924
|
const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
|
|
2899
2925
|
const server = servers?.[0] || { url: "" };
|
|
2900
|
-
const { title = "No title", version
|
|
2926
|
+
const { title = "No title", version } = info || {};
|
|
2901
2927
|
const { url: serverUrl } = server;
|
|
2902
2928
|
return {
|
|
2903
2929
|
info: info || {},
|
|
2904
2930
|
servers: servers || [],
|
|
2905
2931
|
basePath,
|
|
2906
2932
|
host,
|
|
2907
|
-
externalDocs:
|
|
2933
|
+
externalDocs: (0, es_toolkit.merge)({
|
|
2908
2934
|
url: "",
|
|
2909
2935
|
description: ""
|
|
2910
|
-
}, externalDocs),
|
|
2911
|
-
tags:
|
|
2936
|
+
}, externalDocs || {}),
|
|
2937
|
+
tags: (0, es_toolkit.compact)(tags || []),
|
|
2912
2938
|
baseUrl: serverUrl,
|
|
2913
2939
|
title,
|
|
2914
|
-
version
|
|
2940
|
+
version
|
|
2915
2941
|
};
|
|
2916
2942
|
};
|
|
2917
2943
|
injectClassInstance = (key, value) => {
|
|
@@ -2922,28 +2948,28 @@ var CodeGenProcess = class {
|
|
|
2922
2948
|
|
|
2923
2949
|
//#endregion
|
|
2924
2950
|
//#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
|
|
2951
|
+
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind) {
|
|
2952
|
+
RequestContentKind["JSON"] = "JSON";
|
|
2953
|
+
RequestContentKind["URL_ENCODED"] = "URL_ENCODED";
|
|
2954
|
+
RequestContentKind["FORM_DATA"] = "FORM_DATA";
|
|
2955
|
+
RequestContentKind["IMAGE"] = "IMAGE";
|
|
2956
|
+
RequestContentKind["OTHER"] = "OTHER";
|
|
2957
|
+
RequestContentKind["TEXT"] = "TEXT";
|
|
2958
|
+
return RequestContentKind;
|
|
2933
2959
|
}({});
|
|
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
|
|
2960
|
+
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES) {
|
|
2961
|
+
SCHEMA_TYPES["ARRAY"] = "array";
|
|
2962
|
+
SCHEMA_TYPES["OBJECT"] = "object";
|
|
2963
|
+
SCHEMA_TYPES["ENUM"] = "enum";
|
|
2964
|
+
SCHEMA_TYPES["REF"] = "$ref";
|
|
2965
|
+
SCHEMA_TYPES["PRIMITIVE"] = "primitive";
|
|
2966
|
+
SCHEMA_TYPES["COMPLEX"] = "complex";
|
|
2967
|
+
SCHEMA_TYPES["COMPLEX_ONE_OF"] = "oneOf";
|
|
2968
|
+
SCHEMA_TYPES["COMPLEX_ANY_OF"] = "anyOf";
|
|
2969
|
+
SCHEMA_TYPES["COMPLEX_ALL_OF"] = "allOf";
|
|
2970
|
+
SCHEMA_TYPES["COMPLEX_NOT"] = "not";
|
|
2971
|
+
SCHEMA_TYPES["COMPLEX_UNKNOWN"] = "__unknown";
|
|
2972
|
+
return SCHEMA_TYPES;
|
|
2947
2973
|
}({});
|
|
2948
2974
|
|
|
2949
2975
|
//#endregion
|
|
@@ -3075,14 +3101,6 @@ async function generateTemplates(config) {
|
|
|
3075
3101
|
return await new TemplatesGenProcess(config).start();
|
|
3076
3102
|
}
|
|
3077
3103
|
|
|
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
3104
|
//#endregion
|
|
3087
3105
|
Object.defineProperty(exports, 'CodeGenConfig', {
|
|
3088
3106
|
enumerable: true,
|
|
@@ -3090,6 +3108,12 @@ Object.defineProperty(exports, 'CodeGenConfig', {
|
|
|
3090
3108
|
return CodeGenConfig;
|
|
3091
3109
|
}
|
|
3092
3110
|
});
|
|
3111
|
+
Object.defineProperty(exports, 'CodeGenProcess', {
|
|
3112
|
+
enumerable: true,
|
|
3113
|
+
get: function () {
|
|
3114
|
+
return CodeGenProcess;
|
|
3115
|
+
}
|
|
3116
|
+
});
|
|
3093
3117
|
Object.defineProperty(exports, 'HTTP_CLIENT', {
|
|
3094
3118
|
enumerable: true,
|
|
3095
3119
|
get: function () {
|
|
@@ -3132,12 +3156,6 @@ Object.defineProperty(exports, 'description', {
|
|
|
3132
3156
|
return description;
|
|
3133
3157
|
}
|
|
3134
3158
|
});
|
|
3135
|
-
Object.defineProperty(exports, 'generateApi', {
|
|
3136
|
-
enumerable: true,
|
|
3137
|
-
get: function () {
|
|
3138
|
-
return generateApi;
|
|
3139
|
-
}
|
|
3140
|
-
});
|
|
3141
3159
|
Object.defineProperty(exports, 'generateTemplates', {
|
|
3142
3160
|
enumerable: true,
|
|
3143
3161
|
get: function () {
|
|
@@ -3156,4 +3174,4 @@ Object.defineProperty(exports, 'version', {
|
|
|
3156
3174
|
return version;
|
|
3157
3175
|
}
|
|
3158
3176
|
});
|
|
3159
|
-
//# sourceMappingURL=
|
|
3177
|
+
//# sourceMappingURL=generate-templates-C4JBmSNw.cjs.map
|