swagger-typescript-api 13.2.9 → 13.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/{chunk-Cl8Af3a2.js → chunk-CTAAG5j7.js} +3 -1
- package/dist/cli.cjs +7 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -2
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/lib.cjs +3 -1
- package/dist/lib.d.cts +32 -5
- package/dist/lib.d.ts +32 -5
- package/dist/lib.js +2 -2
- package/dist/{src-BGOGeWR6.js → src-BRCAbt5v.js} +156 -183
- package/dist/src-BRCAbt5v.js.map +1 -0
- package/dist/{src-B-cU8h_Y.cjs → src-D2FYrO2h.cjs} +192 -193
- package/dist/src-D2FYrO2h.cjs.map +1 -0
- package/package.json +11 -11
- package/templates/base/http-clients/fetch-http-client.ejs +2 -1
- package/dist/src-B-cU8h_Y.cjs.map +0 -1
- package/dist/src-BGOGeWR6.js.map +0 -1
|
@@ -5,11 +5,13 @@ 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 __export = (
|
|
8
|
+
var __export = (all) => {
|
|
9
|
+
let target = {};
|
|
9
10
|
for (var name$1 in all) __defProp(target, name$1, {
|
|
10
11
|
get: all[name$1],
|
|
11
12
|
enumerable: true
|
|
12
13
|
});
|
|
14
|
+
return target;
|
|
13
15
|
};
|
|
14
16
|
var __copyProps = (to, from, except, desc) => {
|
|
15
17
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
@@ -27,18 +29,30 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
29
|
}) : target, mod));
|
|
28
30
|
|
|
29
31
|
//#endregion
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
let consola = require("consola");
|
|
33
|
+
consola = __toESM(consola);
|
|
34
|
+
let lodash = require("lodash");
|
|
35
|
+
lodash = __toESM(lodash);
|
|
36
|
+
let typescript = require("typescript");
|
|
37
|
+
typescript = __toESM(typescript);
|
|
38
|
+
let node_path = require("node:path");
|
|
39
|
+
node_path = __toESM(node_path);
|
|
40
|
+
let __biomejs_js_api = require("@biomejs/js-api");
|
|
41
|
+
__biomejs_js_api = __toESM(__biomejs_js_api);
|
|
42
|
+
let nanoid = require("nanoid");
|
|
43
|
+
nanoid = __toESM(nanoid);
|
|
44
|
+
let js_yaml = require("js-yaml");
|
|
45
|
+
js_yaml = __toESM(js_yaml);
|
|
46
|
+
let swagger2openapi = require("swagger2openapi");
|
|
47
|
+
swagger2openapi = __toESM(swagger2openapi);
|
|
48
|
+
let node_module = require("node:module");
|
|
49
|
+
node_module = __toESM(node_module);
|
|
50
|
+
let node_url = require("node:url");
|
|
51
|
+
node_url = __toESM(node_url);
|
|
52
|
+
let eta = require("eta");
|
|
53
|
+
eta = __toESM(eta);
|
|
54
|
+
let node_fs = require("node:fs");
|
|
55
|
+
node_fs = __toESM(node_fs);
|
|
42
56
|
|
|
43
57
|
//#region src/code-formatter.ts
|
|
44
58
|
var CodeFormatter = class {
|
|
@@ -49,8 +63,7 @@ var CodeFormatter = class {
|
|
|
49
63
|
removeUnusedImports = (content) => {
|
|
50
64
|
const tempFileName = "file.ts";
|
|
51
65
|
const host = new TsLanguageServiceHost(tempFileName, content);
|
|
52
|
-
const
|
|
53
|
-
const fileTextChanges = languageService.organizeImports({
|
|
66
|
+
const fileTextChanges = typescript.createLanguageService(host).organizeImports({
|
|
54
67
|
type: "file",
|
|
55
68
|
fileName: tempFileName
|
|
56
69
|
}, { newLineCharacter: typescript.sys.newLine }, void 0)[0];
|
|
@@ -64,11 +77,10 @@ var CodeFormatter = class {
|
|
|
64
77
|
files: { maxSize: Number.MAX_SAFE_INTEGER },
|
|
65
78
|
formatter: { indentStyle: "space" }
|
|
66
79
|
});
|
|
67
|
-
|
|
80
|
+
return biome.formatContent(biomeProject.projectKey, content, { filePath: node_path.format({
|
|
68
81
|
name: nanoid.nanoid(),
|
|
69
82
|
ext: "ts"
|
|
70
|
-
}) });
|
|
71
|
-
return formatted.content;
|
|
83
|
+
}) }).content;
|
|
72
84
|
};
|
|
73
85
|
formatCode = async (code, { removeUnusedImports = true, format = true } = {}) => {
|
|
74
86
|
if (removeUnusedImports) code = this.removeUnusedImports(code);
|
|
@@ -204,7 +216,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
204
216
|
//#endregion
|
|
205
217
|
//#region package.json
|
|
206
218
|
var name = "swagger-typescript-api";
|
|
207
|
-
var version = "13.2.
|
|
219
|
+
var version = "13.2.11";
|
|
208
220
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
209
221
|
var homepage = "https://github.com/acacode/swagger-typescript-api";
|
|
210
222
|
var bugs = "https://github.com/acacode/swagger-typescript-api/issues";
|
|
@@ -245,12 +257,12 @@ var scripts = {
|
|
|
245
257
|
};
|
|
246
258
|
var dependencies = {
|
|
247
259
|
"@biomejs/js-api": "3.0.0",
|
|
248
|
-
"@biomejs/wasm-nodejs": "2.2.
|
|
260
|
+
"@biomejs/wasm-nodejs": "2.2.4",
|
|
249
261
|
"@types/swagger-schema-official": "^2.0.25",
|
|
250
|
-
"c12": "^3.
|
|
262
|
+
"c12": "^3.3.0",
|
|
251
263
|
"citty": "^0.1.6",
|
|
252
264
|
"consola": "^3.4.2",
|
|
253
|
-
"eta": "^
|
|
265
|
+
"eta": "^4.0.1",
|
|
254
266
|
"js-yaml": "^4.1.0",
|
|
255
267
|
"lodash": "^4.17.21",
|
|
256
268
|
"nanoid": "^5.1.5",
|
|
@@ -259,19 +271,19 @@ var dependencies = {
|
|
|
259
271
|
"typescript": "~5.9.2"
|
|
260
272
|
};
|
|
261
273
|
var devDependencies = {
|
|
262
|
-
"@biomejs/biome": "2.2.
|
|
274
|
+
"@biomejs/biome": "2.2.4",
|
|
263
275
|
"@changesets/changelog-github": "0.5.1",
|
|
264
|
-
"@changesets/cli": "2.29.
|
|
265
|
-
"@tsconfig/
|
|
276
|
+
"@changesets/cli": "2.29.7",
|
|
277
|
+
"@tsconfig/node20": "20.1.6",
|
|
266
278
|
"@tsconfig/strictest": "2.0.5",
|
|
267
279
|
"@types/js-yaml": "4.0.9",
|
|
268
280
|
"@types/lodash": "4.17.20",
|
|
269
|
-
"@types/node": "24.
|
|
281
|
+
"@types/node": "24.5.2",
|
|
270
282
|
"@types/swagger2openapi": "7.0.4",
|
|
271
|
-
"axios": "1.
|
|
283
|
+
"axios": "1.12.2",
|
|
272
284
|
"openapi-types": "12.1.3",
|
|
273
|
-
"tsdown": "0.
|
|
274
|
-
"typedoc": "0.28.
|
|
285
|
+
"tsdown": "0.15.2",
|
|
286
|
+
"typedoc": "0.28.13",
|
|
275
287
|
"vitest": "3.2.4"
|
|
276
288
|
};
|
|
277
289
|
var packageManager = "yarn@4.9.4";
|
|
@@ -313,8 +325,7 @@ var package_default = {
|
|
|
313
325
|
|
|
314
326
|
//#endregion
|
|
315
327
|
//#region src/constants.ts
|
|
316
|
-
var constants_exports = {
|
|
317
|
-
__export(constants_exports, {
|
|
328
|
+
var constants_exports = /* @__PURE__ */ __export({
|
|
318
329
|
DEFAULT_BODY_ARG_NAME: () => DEFAULT_BODY_ARG_NAME,
|
|
319
330
|
FILE_PREFIX: () => FILE_PREFIX,
|
|
320
331
|
HTTP_CLIENT: () => HTTP_CLIENT,
|
|
@@ -324,7 +335,7 @@ __export(constants_exports, {
|
|
|
324
335
|
RESERVED_PATH_ARG_NAMES: () => RESERVED_PATH_ARG_NAMES,
|
|
325
336
|
RESERVED_QUERY_ARG_NAMES: () => RESERVED_QUERY_ARG_NAMES,
|
|
326
337
|
RESERVED_REQ_PARAMS_ARG_NAMES: () => RESERVED_REQ_PARAMS_ARG_NAMES,
|
|
327
|
-
SCHEMA_TYPES: () => SCHEMA_TYPES
|
|
338
|
+
SCHEMA_TYPES: () => SCHEMA_TYPES$1
|
|
328
339
|
});
|
|
329
340
|
const DEFAULT_BODY_ARG_NAME = "data";
|
|
330
341
|
const FILE_PREFIX = `/* eslint-disable */
|
|
@@ -363,7 +374,7 @@ const RESERVED_REQ_PARAMS_ARG_NAMES = [
|
|
|
363
374
|
"reqParams",
|
|
364
375
|
"httpParams"
|
|
365
376
|
];
|
|
366
|
-
const SCHEMA_TYPES = {
|
|
377
|
+
const SCHEMA_TYPES$1 = {
|
|
367
378
|
ARRAY: "array",
|
|
368
379
|
OBJECT: "object",
|
|
369
380
|
ENUM: "enum",
|
|
@@ -764,9 +775,9 @@ var SchemaComponentsMap = class {
|
|
|
764
775
|
filter(...componentNames) {
|
|
765
776
|
return this._data.filter((it) => componentNames.some((componentName) => it.$ref.startsWith(`#/components/${componentName}`)));
|
|
766
777
|
}
|
|
767
|
-
get($ref) {
|
|
778
|
+
get = ($ref) => {
|
|
768
779
|
return this._data.find((c) => c.$ref === $ref) || null;
|
|
769
|
-
}
|
|
780
|
+
};
|
|
770
781
|
enumsFirst() {
|
|
771
782
|
this._data.sort((a, b) => {
|
|
772
783
|
if (Object.keys(a.rawTypeData || {}).includes("enum")) return -1;
|
|
@@ -774,6 +785,13 @@ var SchemaComponentsMap = class {
|
|
|
774
785
|
return 0;
|
|
775
786
|
});
|
|
776
787
|
}
|
|
788
|
+
discriminatorsFirst() {
|
|
789
|
+
this._data.sort((a, b) => {
|
|
790
|
+
if (Object.keys(a.rawTypeData || {}).includes("discriminator")) return -1;
|
|
791
|
+
if (Object.keys(b.rawTypeData || {}).includes("discriminator")) return 1;
|
|
792
|
+
return 0;
|
|
793
|
+
});
|
|
794
|
+
}
|
|
777
795
|
};
|
|
778
796
|
|
|
779
797
|
//#endregion
|
|
@@ -788,7 +806,7 @@ var SchemaFormatters = class {
|
|
|
788
806
|
this.templatesWorker = schemaParser.templatesWorker;
|
|
789
807
|
}
|
|
790
808
|
base = {
|
|
791
|
-
[SCHEMA_TYPES.ENUM]: (parsedSchema) => {
|
|
809
|
+
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
792
810
|
if (this.config.generateUnionEnums) return {
|
|
793
811
|
...parsedSchema,
|
|
794
812
|
$content: parsedSchema.content,
|
|
@@ -800,15 +818,15 @@ var SchemaFormatters = class {
|
|
|
800
818
|
content: this.config.Ts.EnumFieldsWrapper(parsedSchema.content)
|
|
801
819
|
};
|
|
802
820
|
},
|
|
803
|
-
[SCHEMA_TYPES.OBJECT]: (parsedSchema) => {
|
|
804
|
-
if (parsedSchema.nullable) return this.inline[SCHEMA_TYPES.OBJECT](parsedSchema);
|
|
821
|
+
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
822
|
+
if (parsedSchema.nullable) return this.inline[SCHEMA_TYPES$1.OBJECT](parsedSchema);
|
|
805
823
|
return {
|
|
806
824
|
...parsedSchema,
|
|
807
825
|
$content: parsedSchema.content,
|
|
808
826
|
content: this.formatObjectContent(parsedSchema.content)
|
|
809
827
|
};
|
|
810
828
|
},
|
|
811
|
-
[SCHEMA_TYPES.PRIMITIVE]: (parsedSchema) => {
|
|
829
|
+
[SCHEMA_TYPES$1.PRIMITIVE]: (parsedSchema) => {
|
|
812
830
|
return {
|
|
813
831
|
...parsedSchema,
|
|
814
832
|
$content: parsedSchema.content
|
|
@@ -816,13 +834,13 @@ var SchemaFormatters = class {
|
|
|
816
834
|
}
|
|
817
835
|
};
|
|
818
836
|
inline = {
|
|
819
|
-
[SCHEMA_TYPES.ENUM]: (parsedSchema) => {
|
|
837
|
+
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
820
838
|
return {
|
|
821
839
|
...parsedSchema,
|
|
822
840
|
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType(lodash.default.compact([...parsedSchema.content.map(({ value }) => `${value}`), parsedSchema.nullable && this.config.Ts.Keyword.Null])) || this.config.Ts.Keyword.Any
|
|
823
841
|
};
|
|
824
842
|
},
|
|
825
|
-
[SCHEMA_TYPES.OBJECT]: (parsedSchema) => {
|
|
843
|
+
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
826
844
|
if (typeof parsedSchema.content === "string") return {
|
|
827
845
|
...parsedSchema,
|
|
828
846
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
@@ -837,13 +855,11 @@ var SchemaFormatters = class {
|
|
|
837
855
|
};
|
|
838
856
|
formatSchema = (parsedSchema, formatType = "base") => {
|
|
839
857
|
const schemaType = lodash.default.get(parsedSchema, ["schemaType"]) || lodash.default.get(parsedSchema, ["$parsed", "schemaType"]);
|
|
840
|
-
|
|
841
|
-
return formatterFn?.(parsedSchema) || parsedSchema;
|
|
858
|
+
return lodash.default.get(this, [formatType, schemaType])?.(parsedSchema) || parsedSchema;
|
|
842
859
|
};
|
|
843
860
|
formatDescription = (description$1, inline) => {
|
|
844
861
|
if (!description$1) return "";
|
|
845
|
-
|
|
846
|
-
if (!hasMultipleLines) return description$1;
|
|
862
|
+
if (!description$1.includes("\n")) return description$1;
|
|
847
863
|
if (inline) return lodash.default._(description$1).split(/\n/g).map((part) => part.trim()).compact().join(" ").valueOf();
|
|
848
864
|
return description$1.replace(/\n$/g, "");
|
|
849
865
|
};
|
|
@@ -852,8 +868,7 @@ var SchemaFormatters = class {
|
|
|
852
868
|
for (const part of content) {
|
|
853
869
|
const extraSpace = " ";
|
|
854
870
|
const result = `${extraSpace}${part.field},\n`;
|
|
855
|
-
const
|
|
856
|
-
const routeNameFromTemplate = renderedJsDoc.split("\n").map((c) => `${extraSpace}${c}`).join("\n");
|
|
871
|
+
const routeNameFromTemplate = this.templatesWorker.renderTemplate(this.config.templatesToRender.dataContractJsDoc, { data: part }).split("\n").map((c) => `${extraSpace}${c}`).join("\n");
|
|
857
872
|
if (routeNameFromTemplate) fields.push(`${routeNameFromTemplate}${result}`);
|
|
858
873
|
else fields.push(`${result}`);
|
|
859
874
|
}
|
|
@@ -908,7 +923,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
908
923
|
parse() {
|
|
909
924
|
let contentType;
|
|
910
925
|
const { type: type$1, description: description$1, items } = this.schema || {};
|
|
911
|
-
if (Array.isArray(items) && type$1 === SCHEMA_TYPES.ARRAY) {
|
|
926
|
+
if (Array.isArray(items) && type$1 === SCHEMA_TYPES$1.ARRAY) {
|
|
912
927
|
const tupleContent = [];
|
|
913
928
|
for (const item of items) tupleContent.push(this.schemaParserFabric.createSchemaParser({
|
|
914
929
|
schema: item,
|
|
@@ -926,8 +941,8 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
926
941
|
...typeof this.schema === "object" ? this.schema : {},
|
|
927
942
|
$schemaPath: this.schemaPath.slice(),
|
|
928
943
|
$parsedSchema: true,
|
|
929
|
-
schemaType: SCHEMA_TYPES.PRIMITIVE,
|
|
930
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
944
|
+
schemaType: SCHEMA_TYPES$1.PRIMITIVE,
|
|
945
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
931
946
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
932
947
|
name: this.typeName,
|
|
933
948
|
description: this.schemaFormatters.formatDescription(description$1),
|
|
@@ -947,12 +962,12 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
947
962
|
...typeof this.schema === "object" ? this.schema : {},
|
|
948
963
|
$schemaPath: this.schemaPath.slice(),
|
|
949
964
|
$parsedSchema: true,
|
|
950
|
-
schemaType: SCHEMA_TYPES.COMPLEX,
|
|
951
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
965
|
+
schemaType: SCHEMA_TYPES$1.COMPLEX,
|
|
966
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
952
967
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
953
968
|
name: this.typeName,
|
|
954
969
|
description: this.schemaFormatters.formatDescription(this.schema.description || lodash.default.compact(lodash.default.map(this.schema[complexType], "description"))[0] || ""),
|
|
955
|
-
content: this.config.Ts.IntersectionType(lodash.default.compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
970
|
+
content: this.config.Ts.IntersectionType(lodash.default.compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES$1.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
956
971
|
schema: simpleSchema,
|
|
957
972
|
schemaPath: this.schemaPath
|
|
958
973
|
}).getInlineParseContent())])) || this.config.Ts.Keyword.Any
|
|
@@ -982,8 +997,8 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
982
997
|
...typeof this.schema === "object" ? this.schema : {},
|
|
983
998
|
$schemaPath: this.schemaPath.slice(),
|
|
984
999
|
$parsedSchema: true,
|
|
985
|
-
schemaType: SCHEMA_TYPES.COMPLEX,
|
|
986
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
1000
|
+
schemaType: SCHEMA_TYPES$1.COMPLEX,
|
|
1001
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
987
1002
|
typeIdentifier: ts.Keyword.Type,
|
|
988
1003
|
name: this.typeName,
|
|
989
1004
|
description: this.schemaFormatters.formatDescription(this.schema.description),
|
|
@@ -1013,7 +1028,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1013
1028
|
suffixes: this.config.extractingOptions.discriminatorMappingSuffix,
|
|
1014
1029
|
resolver: this.config.extractingOptions.discriminatorMappingNameResolver
|
|
1015
1030
|
});
|
|
1016
|
-
const content
|
|
1031
|
+
const content = ts.IntersectionType([ts.ObjectWrapper(ts.TypeField({
|
|
1017
1032
|
key: ts.StringValue(discriminator.propertyName),
|
|
1018
1033
|
value: "Key"
|
|
1019
1034
|
})), "Type"]);
|
|
@@ -1026,21 +1041,21 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1026
1041
|
internal: true
|
|
1027
1042
|
}
|
|
1028
1043
|
});
|
|
1029
|
-
component.typeData.content = content
|
|
1044
|
+
component.typeData.content = content;
|
|
1030
1045
|
mappingTypeName = this.typeNameFormatter.format(component.typeName);
|
|
1031
1046
|
}
|
|
1032
1047
|
/** returns (GenericType<"mapping_key", MappingType>) or ({ discriminatorProperty: "mapping_key" } & MappingType) */
|
|
1033
1048
|
const createMappingContent = (mappingSchema, mappingKey) => {
|
|
1034
|
-
const content
|
|
1049
|
+
const content = this.schemaParserFabric.createSchemaParser({
|
|
1035
1050
|
schema: mappingSchema,
|
|
1036
1051
|
schemaPath: this.schemaPath
|
|
1037
1052
|
}).getInlineParseContent();
|
|
1038
1053
|
const mappingUsageKey = mappingPropertySchemaEnumKeysMap[mappingKey] || ts.StringValue(mappingKey);
|
|
1039
|
-
if (ableToCreateMappingType) return ts.TypeWithGeneric(mappingTypeName, [mappingUsageKey, content
|
|
1054
|
+
if (ableToCreateMappingType) return ts.TypeWithGeneric(mappingTypeName, [mappingUsageKey, content]);
|
|
1040
1055
|
return ts.ExpressionGroup(ts.IntersectionType([ts.ObjectWrapper(ts.TypeField({
|
|
1041
1056
|
key: discriminator.propertyName,
|
|
1042
1057
|
value: mappingUsageKey
|
|
1043
|
-
})), content
|
|
1058
|
+
})), content]));
|
|
1044
1059
|
};
|
|
1045
1060
|
for (const [mappingKey, schema] of mappingEntries) {
|
|
1046
1061
|
const mappingSchema = typeof schema === "string" ? { $ref: schema } : schema;
|
|
@@ -1054,15 +1069,14 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1054
1069
|
mappingContents.push(createMappingContent(mappingSchema, mappingKey));
|
|
1055
1070
|
}
|
|
1056
1071
|
if (skipMappingType) return null;
|
|
1057
|
-
|
|
1058
|
-
return { content };
|
|
1072
|
+
return { content: ts.ExpressionGroup(ts.UnionType(mappingContents)) };
|
|
1059
1073
|
};
|
|
1060
1074
|
createMappingPropertySchemaEnumKeys = ({ abstractSchemaStruct, discPropertyName }) => {
|
|
1061
1075
|
const ts = this.config.Ts;
|
|
1062
1076
|
let mappingPropertySchemaEnumKeysMap = {};
|
|
1063
1077
|
let mappingPropertySchema = lodash.default.get(abstractSchemaStruct?.component?.rawTypeData, ["properties", discPropertyName]);
|
|
1064
1078
|
if (this.schemaUtils.isRefSchema(mappingPropertySchema)) mappingPropertySchema = this.schemaUtils.getSchemaRefType(mappingPropertySchema);
|
|
1065
|
-
if (mappingPropertySchema?.rawTypeData?.$parsed?.type === SCHEMA_TYPES.ENUM) mappingPropertySchemaEnumKeysMap = lodash.default.reduce(mappingPropertySchema.rawTypeData.$parsed.enum, (acc, key, index) => {
|
|
1079
|
+
if (mappingPropertySchema?.rawTypeData?.$parsed?.type === SCHEMA_TYPES$1.ENUM) mappingPropertySchemaEnumKeysMap = lodash.default.reduce(mappingPropertySchema.rawTypeData.$parsed.enum, (acc, key, index) => {
|
|
1066
1080
|
const enumKey = mappingPropertySchema.rawTypeData.$parsed.content[index].key;
|
|
1067
1081
|
acc[key] = ts.EnumUsageKey(mappingPropertySchema.rawTypeData.$parsed.typeName, enumKey);
|
|
1068
1082
|
return acc;
|
|
@@ -1079,9 +1093,9 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1079
1093
|
...schema,
|
|
1080
1094
|
$ref: abstractSchemaStruct.component.$ref
|
|
1081
1095
|
};
|
|
1082
|
-
if (this.schemaUtils.getInternalSchemaType(schema) === SCHEMA_TYPES.OBJECT) for (const schemaPropertyName in schema.properties) {
|
|
1096
|
+
if (this.schemaUtils.getInternalSchemaType(schema) === SCHEMA_TYPES$1.OBJECT) for (const schemaPropertyName in schema.properties) {
|
|
1083
1097
|
const schemaProperty = schema.properties[schemaPropertyName];
|
|
1084
|
-
if (schemaPropertyName === discPropertyName && this.schemaUtils.getInternalSchemaType(schemaProperty) === SCHEMA_TYPES.ENUM && schemaProperty.enum.length === 1 && mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]]) schema.properties[schemaPropertyName] = this.schemaParserFabric.createSchema({ content: mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]] });
|
|
1098
|
+
if (schemaPropertyName === discPropertyName && this.schemaUtils.getInternalSchemaType(schemaProperty) === SCHEMA_TYPES$1.ENUM && schemaProperty.enum.length === 1 && mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]]) schema.properties[schemaPropertyName] = this.schemaParserFabric.createSchema({ content: mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]] });
|
|
1085
1099
|
}
|
|
1086
1100
|
return schema;
|
|
1087
1101
|
});
|
|
@@ -1093,8 +1107,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1093
1107
|
const complexSchemaKeys = lodash.default.keys(this.schemaParser._complexSchemaParsers);
|
|
1094
1108
|
const schema = lodash.default.omit(structuredClone(noDiscriminatorSchema), complexSchemaKeys);
|
|
1095
1109
|
const schemaIsAny = this.schemaParserFabric.getInlineParseContent(structuredClone(schema)) === this.config.Ts.Keyword.Any;
|
|
1096
|
-
|
|
1097
|
-
if (schemaIsEmpty || schemaIsAny) return null;
|
|
1110
|
+
if (!lodash.default.keys(schema).length || schemaIsAny) return null;
|
|
1098
1111
|
const typeName = this.schemaUtils.resolveTypeName(this.typeName, {
|
|
1099
1112
|
prefixes: this.config.extractingOptions.discriminatorAbstractPrefix,
|
|
1100
1113
|
resolver: this.config.extractingOptions.discriminatorAbstractResolver
|
|
@@ -1120,7 +1133,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1120
1133
|
createComplexSchemaStruct = () => {
|
|
1121
1134
|
const ts = this.config.Ts;
|
|
1122
1135
|
const complexType = this.schemaUtils.getComplexType(this.schema);
|
|
1123
|
-
if (complexType === SCHEMA_TYPES.COMPLEX_UNKNOWN) return null;
|
|
1136
|
+
if (complexType === SCHEMA_TYPES$1.COMPLEX_UNKNOWN) return null;
|
|
1124
1137
|
return { content: ts.ExpressionGroup(this.schemaParser._complexSchemaParsers[complexType](this.schema)) };
|
|
1125
1138
|
};
|
|
1126
1139
|
};
|
|
@@ -1223,8 +1236,8 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1223
1236
|
$ref,
|
|
1224
1237
|
typeName: this.typeName || $ref && refType.typeName || null,
|
|
1225
1238
|
$parsedSchema: true,
|
|
1226
|
-
schemaType: SCHEMA_TYPES.ENUM,
|
|
1227
|
-
type: SCHEMA_TYPES.ENUM,
|
|
1239
|
+
schemaType: SCHEMA_TYPES$1.ENUM,
|
|
1240
|
+
type: SCHEMA_TYPES$1.ENUM,
|
|
1228
1241
|
keyType,
|
|
1229
1242
|
typeIdentifier: this.config.generateUnionEnums ? this.config.Ts.Keyword.Type : this.config.Ts.Keyword.Enum,
|
|
1230
1243
|
name: this.typeName,
|
|
@@ -1249,8 +1262,8 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1249
1262
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1250
1263
|
$schemaPath: this.schemaPath.slice(),
|
|
1251
1264
|
$parsedSchema: true,
|
|
1252
|
-
schemaType: SCHEMA_TYPES.OBJECT,
|
|
1253
|
-
type: SCHEMA_TYPES.OBJECT,
|
|
1265
|
+
schemaType: SCHEMA_TYPES$1.OBJECT,
|
|
1266
|
+
type: SCHEMA_TYPES$1.OBJECT,
|
|
1254
1267
|
typeIdentifier: this.config.Ts.Keyword.Interface,
|
|
1255
1268
|
name: this.typeName,
|
|
1256
1269
|
description: this.schemaFormatters.formatDescription(this.schema.description),
|
|
@@ -1332,7 +1345,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1332
1345
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1333
1346
|
oneOf: type$1.map((type$2) => ({ type: type$2 }))
|
|
1334
1347
|
});
|
|
1335
|
-
if (Array.isArray(items) && type$1 === SCHEMA_TYPES.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1348
|
+
if (Array.isArray(items) && type$1 === SCHEMA_TYPES$1.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1336
1349
|
schema: item,
|
|
1337
1350
|
schemaPath: this.schemaPath
|
|
1338
1351
|
}).getInlineParseContent()));
|
|
@@ -1340,8 +1353,8 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1340
1353
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1341
1354
|
$schemaPath: this.schemaPath.slice(),
|
|
1342
1355
|
$parsedSchema: true,
|
|
1343
|
-
schemaType: SCHEMA_TYPES.PRIMITIVE,
|
|
1344
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
1356
|
+
schemaType: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1357
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1345
1358
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
1346
1359
|
name: this.typeName,
|
|
1347
1360
|
description: this.schemaFormatters.formatDescription(description$1),
|
|
@@ -1422,67 +1435,47 @@ var SchemaParser = class {
|
|
|
1422
1435
|
this.schemaPath = [...schemaPath || []];
|
|
1423
1436
|
}
|
|
1424
1437
|
_complexSchemaParsers = {
|
|
1425
|
-
[SCHEMA_TYPES.COMPLEX_ONE_OF]: (schema) => {
|
|
1426
|
-
|
|
1427
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1428
|
-
return schemaParser.parse();
|
|
1438
|
+
[SCHEMA_TYPES$1.COMPLEX_ONE_OF]: (schema) => {
|
|
1439
|
+
return new (this.config.schemaParsers.complexOneOf || OneOfSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1429
1440
|
},
|
|
1430
|
-
[SCHEMA_TYPES.COMPLEX_ALL_OF]: (schema) => {
|
|
1431
|
-
|
|
1432
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1433
|
-
return schemaParser.parse();
|
|
1441
|
+
[SCHEMA_TYPES$1.COMPLEX_ALL_OF]: (schema) => {
|
|
1442
|
+
return new (this.config.schemaParsers.complexAllOf || AllOfSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1434
1443
|
},
|
|
1435
|
-
[SCHEMA_TYPES.COMPLEX_ANY_OF]: (schema) => {
|
|
1436
|
-
|
|
1437
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1438
|
-
return schemaParser.parse();
|
|
1444
|
+
[SCHEMA_TYPES$1.COMPLEX_ANY_OF]: (schema) => {
|
|
1445
|
+
return new (this.config.schemaParsers.complexAnyOf || AnyOfSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1439
1446
|
},
|
|
1440
|
-
[SCHEMA_TYPES.COMPLEX_NOT]: (schema) => {
|
|
1441
|
-
|
|
1442
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1443
|
-
return schemaParser.parse();
|
|
1447
|
+
[SCHEMA_TYPES$1.COMPLEX_NOT]: (schema) => {
|
|
1448
|
+
return new (this.config.schemaParsers.complexNot || NotSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1444
1449
|
}
|
|
1445
1450
|
};
|
|
1446
1451
|
_baseSchemaParsers = {
|
|
1447
|
-
[SCHEMA_TYPES.ENUM]: (schema, typeName) => {
|
|
1448
|
-
|
|
1449
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1450
|
-
return schemaParser.parse();
|
|
1452
|
+
[SCHEMA_TYPES$1.ENUM]: (schema, typeName) => {
|
|
1453
|
+
return new (this.config.schemaParsers.enum || EnumSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1451
1454
|
},
|
|
1452
|
-
[SCHEMA_TYPES.OBJECT]: (schema, typeName) => {
|
|
1453
|
-
|
|
1454
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1455
|
-
return schemaParser.parse();
|
|
1455
|
+
[SCHEMA_TYPES$1.OBJECT]: (schema, typeName) => {
|
|
1456
|
+
return new (this.config.schemaParsers.object || ObjectSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1456
1457
|
},
|
|
1457
|
-
[SCHEMA_TYPES.COMPLEX]: (schema, typeName) => {
|
|
1458
|
-
|
|
1459
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1460
|
-
return schemaParser.parse();
|
|
1458
|
+
[SCHEMA_TYPES$1.COMPLEX]: (schema, typeName) => {
|
|
1459
|
+
return new (this.config.schemaParsers.complex || ComplexSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1461
1460
|
},
|
|
1462
|
-
[SCHEMA_TYPES.PRIMITIVE]: (schema, typeName) => {
|
|
1463
|
-
|
|
1464
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1465
|
-
return schemaParser.parse();
|
|
1461
|
+
[SCHEMA_TYPES$1.PRIMITIVE]: (schema, typeName) => {
|
|
1462
|
+
return new (this.config.schemaParsers.primitive || PrimitiveSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1466
1463
|
},
|
|
1467
|
-
[SCHEMA_TYPES.DISCRIMINATOR]: (schema, typeName) => {
|
|
1468
|
-
|
|
1469
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1470
|
-
return schemaParser.parse();
|
|
1464
|
+
[SCHEMA_TYPES$1.DISCRIMINATOR]: (schema, typeName) => {
|
|
1465
|
+
return new (this.config.schemaParsers.discriminator || DiscriminatorSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1471
1466
|
},
|
|
1472
|
-
[SCHEMA_TYPES.ARRAY]: (schema, typeName) => {
|
|
1473
|
-
|
|
1474
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1475
|
-
return schemaParser.parse();
|
|
1467
|
+
[SCHEMA_TYPES$1.ARRAY]: (schema, typeName) => {
|
|
1468
|
+
return new (this.config.schemaParsers.array || ArraySchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1476
1469
|
}
|
|
1477
1470
|
};
|
|
1478
1471
|
parseSchema = () => {
|
|
1479
|
-
if (!this.schema) return this._baseSchemaParsers[SCHEMA_TYPES.PRIMITIVE](null, this.typeName);
|
|
1472
|
+
if (!this.schema) return this._baseSchemaParsers[SCHEMA_TYPES$1.PRIMITIVE](null, this.typeName);
|
|
1480
1473
|
let schemaType = null;
|
|
1481
1474
|
let parsedSchema = null;
|
|
1482
1475
|
if (typeof this.schema === "string") return this.schema;
|
|
1483
1476
|
if (!this.schema.$parsed) {
|
|
1484
1477
|
if (!this.typeName && this.schemaUtils.isRefSchema(this.schema)) this.typeName = this.schemaUtils.getSchemaType(this.schema);
|
|
1485
|
-
if (this.schema.items && !Array.isArray(this.schema.items) && !this.schema.type) this.schema.type = SCHEMA_TYPES.ARRAY;
|
|
1478
|
+
if (this.schema.items && !Array.isArray(this.schema.items) && !this.schema.type) this.schema.type = SCHEMA_TYPES$1.ARRAY;
|
|
1486
1479
|
if (Array.isArray(this.schema.enum) && this.schema.enum.length === 1 && this.schema.enum[0] == null) {
|
|
1487
1480
|
consola.consola.debug("invalid enum schema", this.schema);
|
|
1488
1481
|
this.schema = { type: this.config.Ts.Keyword.Null };
|
|
@@ -1509,13 +1502,11 @@ var SchemaParser = class {
|
|
|
1509
1502
|
};
|
|
1510
1503
|
getInlineParseContent = () => {
|
|
1511
1504
|
const parsedSchema = this.parseSchema();
|
|
1512
|
-
|
|
1513
|
-
return formattedSchema.content;
|
|
1505
|
+
return this.schemaFormatters.formatSchema(parsedSchema, "inline").content;
|
|
1514
1506
|
};
|
|
1515
1507
|
getParseContent = () => {
|
|
1516
1508
|
const parsedSchema = this.parseSchema();
|
|
1517
|
-
|
|
1518
|
-
return formattedSchema.content;
|
|
1509
|
+
return this.schemaFormatters.formatSchema(parsedSchema, "base").content;
|
|
1519
1510
|
};
|
|
1520
1511
|
extractSchemaFromResponseStruct = (responseStruct) => {
|
|
1521
1512
|
const { content,...extras } = responseStruct;
|
|
@@ -1597,8 +1588,8 @@ var SchemaUtils = class {
|
|
|
1597
1588
|
if (enumFieldType === this.config.Ts.Keyword.Undefined) return;
|
|
1598
1589
|
return internalCase(enumFieldType);
|
|
1599
1590
|
}
|
|
1600
|
-
if (lodash.default.keys(schema.properties).length) return SCHEMA_TYPES.OBJECT;
|
|
1601
|
-
if (schema.items) return SCHEMA_TYPES.ARRAY;
|
|
1591
|
+
if (lodash.default.keys(schema.properties).length) return SCHEMA_TYPES$1.OBJECT;
|
|
1592
|
+
if (schema.items) return SCHEMA_TYPES$1.ARRAY;
|
|
1602
1593
|
return null;
|
|
1603
1594
|
};
|
|
1604
1595
|
checkAndAddRequiredKeys = (schema, resultType) => {
|
|
@@ -1613,8 +1604,7 @@ var SchemaUtils = class {
|
|
|
1613
1604
|
const required = lodash.default.uniq([...this.getRequiredProperties(parentSchema), ...this.getRequiredProperties(childSchema)]);
|
|
1614
1605
|
const refData = this.getSchemaRefType(childSchema);
|
|
1615
1606
|
if (refData) {
|
|
1616
|
-
const
|
|
1617
|
-
const existedRequiredKeys = refObjectProperties.filter((key) => required.includes(key));
|
|
1607
|
+
const existedRequiredKeys = lodash.default.keys(refData.rawTypeData?.properties || {}).filter((key) => required.includes(key));
|
|
1618
1608
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1619
1609
|
return {
|
|
1620
1610
|
...childSchema,
|
|
@@ -1622,8 +1612,7 @@ var SchemaUtils = class {
|
|
|
1622
1612
|
};
|
|
1623
1613
|
}
|
|
1624
1614
|
if (childSchema.properties) {
|
|
1625
|
-
const
|
|
1626
|
-
const existedRequiredKeys = childSchemaProperties.filter((key) => required.includes(key));
|
|
1615
|
+
const existedRequiredKeys = lodash.default.keys(childSchema.properties).filter((key) => required.includes(key));
|
|
1627
1616
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1628
1617
|
return {
|
|
1629
1618
|
required: lodash.default.uniq([...this.getRequiredProperties(childSchema), ...existedRequiredKeys]),
|
|
@@ -1642,19 +1631,19 @@ var SchemaUtils = class {
|
|
|
1642
1631
|
return this.config.componentTypeNameResolver.resolve([...(prefixes || []).map((prefix) => pascalCase(`${prefix} ${typeName}`)), ...(suffixes || []).map((suffix) => pascalCase(`${typeName} ${suffix}`))], shouldReserve);
|
|
1643
1632
|
};
|
|
1644
1633
|
getComplexType = (schema) => {
|
|
1645
|
-
if (schema.oneOf) return SCHEMA_TYPES.COMPLEX_ONE_OF;
|
|
1646
|
-
if (schema.allOf) return SCHEMA_TYPES.COMPLEX_ALL_OF;
|
|
1647
|
-
if (schema.anyOf) return SCHEMA_TYPES.COMPLEX_ANY_OF;
|
|
1648
|
-
if (schema.not) return SCHEMA_TYPES.COMPLEX_NOT;
|
|
1649
|
-
return SCHEMA_TYPES.COMPLEX_UNKNOWN;
|
|
1634
|
+
if (schema.oneOf) return SCHEMA_TYPES$1.COMPLEX_ONE_OF;
|
|
1635
|
+
if (schema.allOf) return SCHEMA_TYPES$1.COMPLEX_ALL_OF;
|
|
1636
|
+
if (schema.anyOf) return SCHEMA_TYPES$1.COMPLEX_ANY_OF;
|
|
1637
|
+
if (schema.not) return SCHEMA_TYPES$1.COMPLEX_NOT;
|
|
1638
|
+
return SCHEMA_TYPES$1.COMPLEX_UNKNOWN;
|
|
1650
1639
|
};
|
|
1651
1640
|
getInternalSchemaType = (schema) => {
|
|
1652
|
-
if (!lodash.default.isEmpty(schema.enum) || !lodash.default.isEmpty(this.getEnumNames(schema))) return SCHEMA_TYPES.ENUM;
|
|
1653
|
-
if (schema.discriminator) return SCHEMA_TYPES.DISCRIMINATOR;
|
|
1654
|
-
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES.COMPLEX;
|
|
1655
|
-
if (!lodash.default.isEmpty(schema.properties)) return SCHEMA_TYPES.OBJECT;
|
|
1656
|
-
if (schema.type === SCHEMA_TYPES.ARRAY) return SCHEMA_TYPES.ARRAY;
|
|
1657
|
-
return SCHEMA_TYPES.PRIMITIVE;
|
|
1641
|
+
if (!lodash.default.isEmpty(schema.enum) || !lodash.default.isEmpty(this.getEnumNames(schema))) return SCHEMA_TYPES$1.ENUM;
|
|
1642
|
+
if (schema.discriminator) return SCHEMA_TYPES$1.DISCRIMINATOR;
|
|
1643
|
+
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES$1.COMPLEX;
|
|
1644
|
+
if (!lodash.default.isEmpty(schema.properties)) return SCHEMA_TYPES$1.OBJECT;
|
|
1645
|
+
if (schema.type === SCHEMA_TYPES$1.ARRAY) return SCHEMA_TYPES$1.ARRAY;
|
|
1646
|
+
return SCHEMA_TYPES$1.PRIMITIVE;
|
|
1658
1647
|
};
|
|
1659
1648
|
getSchemaType = (schema) => {
|
|
1660
1649
|
if (!schema) return this.config.Ts.Keyword.Any;
|
|
@@ -1742,28 +1731,25 @@ var SchemaParserFabric = class {
|
|
|
1742
1731
|
return customComponent;
|
|
1743
1732
|
};
|
|
1744
1733
|
parseSchema = (schema, typeName = null, schemaPath = []) => {
|
|
1745
|
-
|
|
1734
|
+
return this.createSchemaParser({
|
|
1746
1735
|
schema,
|
|
1747
1736
|
typeName,
|
|
1748
1737
|
schemaPath
|
|
1749
|
-
});
|
|
1750
|
-
return schemaParser.parseSchema();
|
|
1738
|
+
}).parseSchema();
|
|
1751
1739
|
};
|
|
1752
1740
|
getInlineParseContent = (schema, typeName, schemaPath) => {
|
|
1753
|
-
|
|
1741
|
+
return this.createSchemaParser({
|
|
1754
1742
|
schema,
|
|
1755
1743
|
typeName,
|
|
1756
1744
|
schemaPath
|
|
1757
|
-
});
|
|
1758
|
-
return parser.getInlineParseContent();
|
|
1745
|
+
}).getInlineParseContent();
|
|
1759
1746
|
};
|
|
1760
1747
|
getParseContent = (schema, typeName, schemaPath) => {
|
|
1761
|
-
|
|
1748
|
+
return this.createSchemaParser({
|
|
1762
1749
|
schema,
|
|
1763
1750
|
typeName,
|
|
1764
1751
|
schemaPath
|
|
1765
|
-
});
|
|
1766
|
-
return parser.getParseContent();
|
|
1752
|
+
}).getParseContent();
|
|
1767
1753
|
};
|
|
1768
1754
|
};
|
|
1769
1755
|
|
|
@@ -1916,14 +1902,8 @@ var SchemaRoutes = class {
|
|
|
1916
1902
|
}
|
|
1917
1903
|
if (routeParam) routeParams[routeParam.in].push(routeParam);
|
|
1918
1904
|
});
|
|
1919
|
-
for (const pathParam of pathParamsFromRouteName)
|
|
1920
|
-
|
|
1921
|
-
if (!alreadyExist) routeParams.path.push(pathParam);
|
|
1922
|
-
}
|
|
1923
|
-
for (const queryParam of queryParamsFromRouteName) {
|
|
1924
|
-
const alreadyExist = routeParams.query.some((parameter) => parameter.name === queryParam.name);
|
|
1925
|
-
if (!alreadyExist) routeParams.query.push(queryParam);
|
|
1926
|
-
}
|
|
1905
|
+
for (const pathParam of pathParamsFromRouteName) if (!routeParams.path.some((parameter) => parameter.name === pathParam.name)) routeParams.path.push(pathParam);
|
|
1906
|
+
for (const queryParam of queryParamsFromRouteName) if (!routeParams.query.some((parameter) => parameter.name === queryParam.name)) routeParams.query.push(queryParam);
|
|
1927
1907
|
return routeParams;
|
|
1928
1908
|
};
|
|
1929
1909
|
getContentTypes = (requestInfo, extraContentTypes) => lodash.default.uniq(lodash.default.compact([...extraContentTypes || [], ...lodash.default.flatten(lodash.default.map(requestInfo, (requestInfoData) => requestInfoData && lodash.default.keys(requestInfoData.content)))]));
|
|
@@ -2001,8 +1981,7 @@ var SchemaRoutes = class {
|
|
|
2001
1981
|
const headerTypes = Object.fromEntries(Object.entries(src).map(([k, v]) => {
|
|
2002
1982
|
return [k, this.schemaUtils.getSchemaType(v)];
|
|
2003
1983
|
}));
|
|
2004
|
-
|
|
2005
|
-
return r;
|
|
1984
|
+
return `headers: { ${Object.entries(headerTypes).map(([k, v]) => `"${k}": ${v}`).join(",")} },`;
|
|
2006
1985
|
};
|
|
2007
1986
|
return {
|
|
2008
1987
|
contentTypes,
|
|
@@ -2414,8 +2393,7 @@ var Request = class {
|
|
|
2414
2393
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2415
2394
|
lodash.default.merge(requestOptions, options, this.config.requestOptions);
|
|
2416
2395
|
try {
|
|
2417
|
-
|
|
2418
|
-
return await response.text();
|
|
2396
|
+
return await (await fetch(url$1, requestOptions)).text();
|
|
2419
2397
|
} catch (error) {
|
|
2420
2398
|
const message = `error while fetching data from URL "${url$1}"`;
|
|
2421
2399
|
consola.consola.error(message, error);
|
|
@@ -2506,8 +2484,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2506
2484
|
usageRouteInfo.produces = lodash.default.uniq(lodash.default.compact([...usageRouteInfo.produces || [], ...originalRouteInfo.produces || []]));
|
|
2507
2485
|
}
|
|
2508
2486
|
lodash.default.each(originalRouteParams, (originalRouteParam) => {
|
|
2509
|
-
|
|
2510
|
-
if (!existUsageParam) usageRouteParams.push(originalRouteParam);
|
|
2487
|
+
if (!usageRouteParams.find((param) => originalRouteParam.in === param.in && originalRouteParam.name === param.name)) usageRouteParams.push(originalRouteParam);
|
|
2511
2488
|
});
|
|
2512
2489
|
});
|
|
2513
2490
|
});
|
|
@@ -2517,6 +2494,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2517
2494
|
//#endregion
|
|
2518
2495
|
//#region src/templates-worker.ts
|
|
2519
2496
|
const require$1 = node_module.createRequire(require("url").pathToFileURL(__filename).href);
|
|
2497
|
+
const eta$1 = new eta.Eta({ functionHeader: "const includeFile = options.includeFile;" });
|
|
2520
2498
|
var TemplatesWorker = class {
|
|
2521
2499
|
config;
|
|
2522
2500
|
fileSystem;
|
|
@@ -2546,12 +2524,10 @@ var TemplatesWorker = class {
|
|
|
2546
2524
|
cropExtension = (path$1) => this.config.templateExtensions.reduce((path$2, ext) => path$2.endsWith(ext) ? path$2.replace(ext, "") : path$2, path$1);
|
|
2547
2525
|
getTemplateFullPath = (path_, fileName) => {
|
|
2548
2526
|
const raw = node_path.resolve(path_, "./", this.cropExtension(fileName));
|
|
2549
|
-
|
|
2550
|
-
return pathVariants.find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
2527
|
+
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
2551
2528
|
};
|
|
2552
2529
|
requireFnFromTemplate = (packageOrPath) => {
|
|
2553
|
-
|
|
2554
|
-
if (isPath) return require$1(node_path.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2530
|
+
if (packageOrPath.startsWith("./") || packageOrPath.startsWith("../")) return require$1(node_path.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2555
2531
|
return require$1(packageOrPath);
|
|
2556
2532
|
};
|
|
2557
2533
|
getTemplate = (name$1, fileName, path$1) => {
|
|
@@ -2581,8 +2557,7 @@ var TemplatesWorker = class {
|
|
|
2581
2557
|
};
|
|
2582
2558
|
findTemplateWithExt = (path$1) => {
|
|
2583
2559
|
const raw = this.cropExtension(path$1);
|
|
2584
|
-
|
|
2585
|
-
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2560
|
+
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2586
2561
|
};
|
|
2587
2562
|
getTemplateContent = (path_) => {
|
|
2588
2563
|
const foundTemplatePathKey = lodash.default.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
@@ -2597,18 +2572,12 @@ var TemplatesWorker = class {
|
|
|
2597
2572
|
if (originalPath) return this.fileSystem.getFileContent(originalPath);
|
|
2598
2573
|
return "";
|
|
2599
2574
|
};
|
|
2600
|
-
renderTemplate = (template, configuration
|
|
2575
|
+
renderTemplate = (template, configuration) => {
|
|
2601
2576
|
if (!template) return "";
|
|
2602
|
-
return eta.render(template, {
|
|
2577
|
+
return eta$1.render(eta$1.compile(template, { async: false }), {
|
|
2603
2578
|
...this.getRenderTemplateData(),
|
|
2604
2579
|
...configuration
|
|
2605
|
-
}, {
|
|
2606
|
-
async: false,
|
|
2607
|
-
...options,
|
|
2608
|
-
includeFile: (path$1, configuration$1, options$1 = {}) => {
|
|
2609
|
-
return this.renderTemplate(this.getTemplateContent(path$1), configuration$1, options$1);
|
|
2610
|
-
}
|
|
2611
|
-
});
|
|
2580
|
+
}, { includeFile: (path$1, configuration$1) => this.renderTemplate(this.getTemplateContent(path$1), configuration$1) });
|
|
2612
2581
|
};
|
|
2613
2582
|
};
|
|
2614
2583
|
|
|
@@ -2699,10 +2668,7 @@ var TypeNameFormatter = class {
|
|
|
2699
2668
|
isValidName = (name$1) => /^([A-Za-z$_]{1,})$/g.test(name$1);
|
|
2700
2669
|
fixModelName = (name$1, options) => {
|
|
2701
2670
|
if (!this.isValidName(name$1)) {
|
|
2702
|
-
if (!/^[a-zA-Z_$]/g.test(name$1)) {
|
|
2703
|
-
const fixPrefix = options.type === "enum-key" ? this.config.fixInvalidEnumKeyPrefix : this.config.fixInvalidTypeNamePrefix;
|
|
2704
|
-
return `${fixPrefix} ${name$1}`;
|
|
2705
|
-
}
|
|
2671
|
+
if (!/^[a-zA-Z_$]/g.test(name$1)) return `${options.type === "enum-key" ? this.config.fixInvalidEnumKeyPrefix : this.config.fixInvalidTypeNamePrefix} ${name$1}`;
|
|
2706
2672
|
if (name$1.includes(".")) return name$1.replace(/Exclude_keyof[A-Za-z]+/g, () => "ExcludeKeys").replace(/%22~AND~%22/g, "And").replace(/%22~OR~%22/g, "Or").replace(/(\.?%22)|\./g, "_").replace(/__+$/, "");
|
|
2707
2673
|
if (name$1.includes("-")) return lodash.default.startCase(name$1).replace(/ /g, "");
|
|
2708
2674
|
}
|
|
@@ -2722,8 +2688,7 @@ var FileSystem = class {
|
|
|
2722
2688
|
pathIsDir = (path$1) => {
|
|
2723
2689
|
if (!path$1) return false;
|
|
2724
2690
|
try {
|
|
2725
|
-
|
|
2726
|
-
return stat.isDirectory();
|
|
2691
|
+
return node_fs.statSync(path$1).isDirectory();
|
|
2727
2692
|
} catch (e) {
|
|
2728
2693
|
return false;
|
|
2729
2694
|
}
|
|
@@ -2822,9 +2787,9 @@ var CodeGenProcess = class {
|
|
|
2822
2787
|
typeName
|
|
2823
2788
|
]), rawTypeData);
|
|
2824
2789
|
}));
|
|
2790
|
+
this.schemaComponentsMap.discriminatorsFirst();
|
|
2825
2791
|
this.schemaComponentsMap.enumsFirst();
|
|
2826
|
-
const
|
|
2827
|
-
const parsedSchemas = componentsToParse.map((schemaComponent) => {
|
|
2792
|
+
const parsedSchemas = this.schemaComponentsMap.filter(lodash.default.compact(["schemas", this.config.extractResponses && "responses"])).map((schemaComponent) => {
|
|
2828
2793
|
const parsed = this.schemaParserFabric.parseSchema(schemaComponent.rawTypeData, schemaComponent.typeName);
|
|
2829
2794
|
schemaComponent.typeData = parsed;
|
|
2830
2795
|
return parsed;
|
|
@@ -2859,8 +2824,7 @@ var CodeGenProcess = class {
|
|
|
2859
2824
|
this.fileSystem.createDir(this.config.output);
|
|
2860
2825
|
}
|
|
2861
2826
|
const files$1 = await this.generateOutputFiles({ configuration });
|
|
2862
|
-
|
|
2863
|
-
if (isDirPath) for (const file of files$1) {
|
|
2827
|
+
if (this.fileSystem.pathIsDir(this.config.output)) for (const file of files$1) {
|
|
2864
2828
|
this.fileSystem.createFile({
|
|
2865
2829
|
path: this.config.output,
|
|
2866
2830
|
fileName: `${file.fileName}${file.fileExtension}`,
|
|
@@ -3059,6 +3023,32 @@ var CodeGenProcess = class {
|
|
|
3059
3023
|
};
|
|
3060
3024
|
};
|
|
3061
3025
|
|
|
3026
|
+
//#endregion
|
|
3027
|
+
//#region types/index.ts
|
|
3028
|
+
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind$1) {
|
|
3029
|
+
RequestContentKind$1["JSON"] = "JSON";
|
|
3030
|
+
RequestContentKind$1["URL_ENCODED"] = "URL_ENCODED";
|
|
3031
|
+
RequestContentKind$1["FORM_DATA"] = "FORM_DATA";
|
|
3032
|
+
RequestContentKind$1["IMAGE"] = "IMAGE";
|
|
3033
|
+
RequestContentKind$1["OTHER"] = "OTHER";
|
|
3034
|
+
RequestContentKind$1["TEXT"] = "TEXT";
|
|
3035
|
+
return RequestContentKind$1;
|
|
3036
|
+
}({});
|
|
3037
|
+
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES$2) {
|
|
3038
|
+
SCHEMA_TYPES$2["ARRAY"] = "array";
|
|
3039
|
+
SCHEMA_TYPES$2["OBJECT"] = "object";
|
|
3040
|
+
SCHEMA_TYPES$2["ENUM"] = "enum";
|
|
3041
|
+
SCHEMA_TYPES$2["REF"] = "$ref";
|
|
3042
|
+
SCHEMA_TYPES$2["PRIMITIVE"] = "primitive";
|
|
3043
|
+
SCHEMA_TYPES$2["COMPLEX"] = "complex";
|
|
3044
|
+
SCHEMA_TYPES$2["COMPLEX_ONE_OF"] = "oneOf";
|
|
3045
|
+
SCHEMA_TYPES$2["COMPLEX_ANY_OF"] = "anyOf";
|
|
3046
|
+
SCHEMA_TYPES$2["COMPLEX_ALL_OF"] = "allOf";
|
|
3047
|
+
SCHEMA_TYPES$2["COMPLEX_NOT"] = "not";
|
|
3048
|
+
SCHEMA_TYPES$2["COMPLEX_UNKNOWN"] = "__unknown";
|
|
3049
|
+
return SCHEMA_TYPES$2;
|
|
3050
|
+
}({});
|
|
3051
|
+
|
|
3062
3052
|
//#endregion
|
|
3063
3053
|
//#region src/commands/generate-templates/configuration.ts
|
|
3064
3054
|
var TemplatesGenConfig = class {
|
|
@@ -3115,8 +3105,7 @@ var TemplatesGenProcess = class {
|
|
|
3115
3105
|
const templateEtaPath = node_path.default.resolve(outputPath, `${templateName}.eta`);
|
|
3116
3106
|
const templateEjsPathExist = this.fileSystem.pathIsExist(templateEjsPath);
|
|
3117
3107
|
const templateEtaPathExist = this.fileSystem.pathIsExist(templateEtaPath);
|
|
3118
|
-
|
|
3119
|
-
if (templateNotExist) this.fileSystem.createFile({
|
|
3108
|
+
if (!templateEjsPathExist && !templateEtaPathExist) this.fileSystem.createFile({
|
|
3120
3109
|
path: outputPath,
|
|
3121
3110
|
fileName: template.name,
|
|
3122
3111
|
content: template.content,
|
|
@@ -3186,8 +3175,7 @@ var TemplatesGenProcess = class {
|
|
|
3186
3175
|
async function generateTemplates(config) {
|
|
3187
3176
|
if (config.debug) consola.consola.level = Number.MAX_SAFE_INTEGER;
|
|
3188
3177
|
if (config.silent) consola.consola.level = 0;
|
|
3189
|
-
|
|
3190
|
-
return await codeGenProcess.start();
|
|
3178
|
+
return await new TemplatesGenProcess(config).start();
|
|
3191
3179
|
}
|
|
3192
3180
|
|
|
3193
3181
|
//#endregion
|
|
@@ -3195,8 +3183,7 @@ async function generateTemplates(config) {
|
|
|
3195
3183
|
async function generateApi(config) {
|
|
3196
3184
|
if (config.debug) consola.consola.level = Number.MAX_SAFE_INTEGER;
|
|
3197
3185
|
if (config.silent) consola.consola.level = 0;
|
|
3198
|
-
|
|
3199
|
-
return await codeGenProcess.start();
|
|
3186
|
+
return await new CodeGenProcess(config).start();
|
|
3200
3187
|
}
|
|
3201
3188
|
|
|
3202
3189
|
//#endregion
|
|
@@ -3212,6 +3199,18 @@ Object.defineProperty(exports, 'HTTP_CLIENT', {
|
|
|
3212
3199
|
return HTTP_CLIENT;
|
|
3213
3200
|
}
|
|
3214
3201
|
});
|
|
3202
|
+
Object.defineProperty(exports, 'RequestContentKind', {
|
|
3203
|
+
enumerable: true,
|
|
3204
|
+
get: function () {
|
|
3205
|
+
return RequestContentKind;
|
|
3206
|
+
}
|
|
3207
|
+
});
|
|
3208
|
+
Object.defineProperty(exports, 'SCHEMA_TYPES', {
|
|
3209
|
+
enumerable: true,
|
|
3210
|
+
get: function () {
|
|
3211
|
+
return SCHEMA_TYPES;
|
|
3212
|
+
}
|
|
3213
|
+
});
|
|
3215
3214
|
Object.defineProperty(exports, 'TemplatesGenConfig', {
|
|
3216
3215
|
enumerable: true,
|
|
3217
3216
|
get: function () {
|
|
@@ -3248,4 +3247,4 @@ Object.defineProperty(exports, 'package_default', {
|
|
|
3248
3247
|
return package_default;
|
|
3249
3248
|
}
|
|
3250
3249
|
});
|
|
3251
|
-
//# sourceMappingURL=src-
|
|
3250
|
+
//# sourceMappingURL=src-D2FYrO2h.cjs.map
|