swagger-typescript-api 13.2.16 → 13.2.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-DQk6qfdC.mjs +18 -0
- package/dist/cli.cjs +14 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/{cli.js → cli.mjs} +3 -2
- package/dist/cli.mjs.map +1 -0
- package/dist/{src-D-LZ3PGk.js → generate-templates-BO-5CKCm.mjs} +338 -347
- package/dist/generate-templates-BO-5CKCm.mjs.map +1 -0
- package/dist/{src-DWf638kx.cjs → generate-templates-wjE78AWV.cjs} +366 -369
- package/dist/generate-templates-wjE78AWV.cjs.map +1 -0
- package/dist/index.cjs +17 -6
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +105 -223
- package/dist/index.d.cts.map +1 -1
- package/dist/{index.d.ts → index.d.mts} +105 -224
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +13 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +23 -28
- package/templates/default/procedure-call.ejs +1 -1
- package/templates/modular/procedure-call.ejs +1 -1
- package/CHANGELOG.md +0 -1770
- package/dist/chunk-Bp6m_JJh.js +0 -13
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/src-D-LZ3PGk.js.map +0 -1
- package/dist/src-DWf638kx.cjs.map +0 -1
- /package/dist/{cli.d.ts → cli.d.mts} +0 -0
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { t as
|
|
1
|
+
import { t as __exportAll } from "./chunk-DQk6qfdC.mjs";
|
|
2
2
|
import * as module from "node:module";
|
|
3
3
|
import { consola } from "consola";
|
|
4
|
-
import
|
|
4
|
+
import * as esToolkit from "es-toolkit";
|
|
5
|
+
import { compact, flattenDeep, isEqual, merge, omit, uniq } from "es-toolkit";
|
|
6
|
+
import * as esToolkitCompat from "es-toolkit/compat";
|
|
7
|
+
import { camelCase, get, startCase, upperFirst } from "es-toolkit/compat";
|
|
5
8
|
import * as typescript from "typescript";
|
|
6
9
|
import * as path$1 from "node:path";
|
|
7
10
|
import path from "node:path";
|
|
8
11
|
import { Biome, Distribution } from "@biomejs/js-api";
|
|
9
12
|
import * as nanoid from "nanoid";
|
|
13
|
+
import * as crypto from "node:crypto";
|
|
10
14
|
import * as swagger2openapi from "swagger2openapi";
|
|
11
15
|
import * as YAML from "yaml";
|
|
12
16
|
import * as url$1 from "node:url";
|
|
@@ -27,7 +31,7 @@ var CodeFormatter = class {
|
|
|
27
31
|
type: "file",
|
|
28
32
|
fileName: tempFileName
|
|
29
33
|
}, { newLineCharacter: typescript.sys.newLine }, void 0)[0];
|
|
30
|
-
if (fileTextChanges?.textChanges.length) return fileTextChanges.textChanges.reduceRight((content
|
|
34
|
+
if (fileTextChanges?.textChanges.length) return fileTextChanges.textChanges.reduceRight((content, { span, newText }) => `${content.slice(0, span.start)}${newText}${content.slice(span.start + span.length)}`, content);
|
|
31
35
|
return content;
|
|
32
36
|
};
|
|
33
37
|
format = async (content) => {
|
|
@@ -83,8 +87,8 @@ var TsLanguageServiceHost = class {
|
|
|
83
87
|
if (fileName === this.fileName) return this.content;
|
|
84
88
|
return typescript.sys.readFile(fileName, encoding);
|
|
85
89
|
}
|
|
86
|
-
fileExists(path
|
|
87
|
-
return typescript.sys.fileExists(path
|
|
90
|
+
fileExists(path) {
|
|
91
|
+
return typescript.sys.fileExists(path);
|
|
88
92
|
}
|
|
89
93
|
};
|
|
90
94
|
|
|
@@ -100,14 +104,14 @@ var NameResolver = class {
|
|
|
100
104
|
this.reserve(reservedNames);
|
|
101
105
|
}
|
|
102
106
|
reserve(names) {
|
|
103
|
-
const fixedNames =
|
|
104
|
-
for (const name
|
|
107
|
+
const fixedNames = uniq(compact(names));
|
|
108
|
+
for (const name of fixedNames) if (this.reservedNames.indexOf(name) === -1) this.reservedNames.push(name);
|
|
105
109
|
}
|
|
106
110
|
unreserve(names) {
|
|
107
|
-
this.reservedNames = this.reservedNames.filter((reservedName) => !names.some((name
|
|
111
|
+
this.reservedNames = this.reservedNames.filter((reservedName) => !names.some((name) => name === reservedName));
|
|
108
112
|
}
|
|
109
|
-
isReserved(name
|
|
110
|
-
return this.reservedNames.some((reservedName) => reservedName === name
|
|
113
|
+
isReserved(name) {
|
|
114
|
+
return this.reservedNames.some((reservedName) => reservedName === name);
|
|
111
115
|
}
|
|
112
116
|
resolve(variants, resolver, extras, shouldReserve = true) {
|
|
113
117
|
if (typeof resolver === "function") {
|
|
@@ -125,7 +129,7 @@ var NameResolver = class {
|
|
|
125
129
|
}
|
|
126
130
|
if (Array.isArray(variants)) {
|
|
127
131
|
let usageName = null;
|
|
128
|
-
const uniqVariants =
|
|
132
|
+
const uniqVariants = uniq(compact(variants));
|
|
129
133
|
for (const variant of uniqVariants) if (!usageName && (!shouldReserve || !this.isReserved(variant))) usageName = variant;
|
|
130
134
|
if (usageName) {
|
|
131
135
|
shouldReserve && this.reserve([usageName]);
|
|
@@ -141,12 +145,9 @@ var NameResolver = class {
|
|
|
141
145
|
|
|
142
146
|
//#endregion
|
|
143
147
|
//#region src/util/random.ts
|
|
144
|
-
const getRandomFloat = (min = 0, max = 1) => {
|
|
145
|
-
return Math.random() * (max - min) + min;
|
|
146
|
-
};
|
|
147
148
|
const getRandomInt = (min = 0, max = 1) => {
|
|
148
149
|
if (min === max) return min;
|
|
149
|
-
return Math.round(
|
|
150
|
+
return Math.round(Math.random() * (max - min) + min);
|
|
150
151
|
};
|
|
151
152
|
|
|
152
153
|
//#endregion
|
|
@@ -176,12 +177,12 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
176
177
|
//#endregion
|
|
177
178
|
//#region package.json
|
|
178
179
|
var name = "swagger-typescript-api";
|
|
179
|
-
var version = "13.2.
|
|
180
|
+
var version = "13.2.17";
|
|
180
181
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
181
182
|
|
|
182
183
|
//#endregion
|
|
183
184
|
//#region src/constants.ts
|
|
184
|
-
var constants_exports = /* @__PURE__ */
|
|
185
|
+
var constants_exports = /* @__PURE__ */ __exportAll({
|
|
185
186
|
DEFAULT_BODY_ARG_NAME: () => DEFAULT_BODY_ARG_NAME,
|
|
186
187
|
FILE_PREFIX: () => FILE_PREFIX,
|
|
187
188
|
HTTP_CLIENT: () => HTTP_CLIENT,
|
|
@@ -245,16 +246,6 @@ const SCHEMA_TYPES$1 = {
|
|
|
245
246
|
COMPLEX_UNKNOWN: "__unknown"
|
|
246
247
|
};
|
|
247
248
|
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/util/object-assign.ts
|
|
250
|
-
const objectAssign = (target, updater) => {
|
|
251
|
-
if (!updater) return;
|
|
252
|
-
const update = typeof updater === "function" ? updater(target) : updater;
|
|
253
|
-
const undefinedKeys = lodash.map(update, (value, key) => value === void 0 && key).filter((key) => typeof key === "string");
|
|
254
|
-
Object.assign(target, lodash.merge(target, update));
|
|
255
|
-
for (const key of undefinedKeys) target[key] = void 0;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
249
|
//#endregion
|
|
259
250
|
//#region src/configuration.ts
|
|
260
251
|
const TsKeyword = {
|
|
@@ -455,11 +446,11 @@ var CodeGenConfig = class {
|
|
|
455
446
|
BooleanValue: (content) => `${content}`,
|
|
456
447
|
NumberValue: (content) => `${content}`,
|
|
457
448
|
NullValue: () => "null",
|
|
458
|
-
UnionType: (contents) =>
|
|
449
|
+
UnionType: (contents) => uniq(contents).join(` ${this.Ts.Keyword.Union} `),
|
|
459
450
|
ExpressionGroup: (content) => content ? `(${content})` : "",
|
|
460
|
-
IntersectionType: (contents) =>
|
|
451
|
+
IntersectionType: (contents) => uniq(contents).join(` ${this.Ts.Keyword.Intersection} `),
|
|
461
452
|
RecordType: (key, value) => this.Ts.TypeWithGeneric(this.Ts.Keyword.Record, [key, value]),
|
|
462
|
-
TypeField: ({ readonly, key, optional, value }) =>
|
|
453
|
+
TypeField: ({ readonly, key, optional, value }) => compact([
|
|
463
454
|
readonly && "readonly ",
|
|
464
455
|
key,
|
|
465
456
|
optional && "?",
|
|
@@ -469,12 +460,12 @@ var CodeGenConfig = class {
|
|
|
469
460
|
InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
|
|
470
461
|
EnumUsageKey: (enumStruct, key) => `${enumStruct}.${key}`,
|
|
471
462
|
EnumField: (key, value) => `${key} = ${value}`,
|
|
472
|
-
EnumFieldDescription: (description
|
|
473
|
-
if (description
|
|
463
|
+
EnumFieldDescription: (description) => {
|
|
464
|
+
if (description) return ` /** ${description} */`;
|
|
474
465
|
else return "";
|
|
475
466
|
},
|
|
476
|
-
EnumFieldsWrapper: (contents) =>
|
|
477
|
-
return [this.Ts.EnumFieldDescription(description
|
|
467
|
+
EnumFieldsWrapper: (contents) => contents.map(({ key, value, description }) => {
|
|
468
|
+
return compact([this.Ts.EnumFieldDescription(description), ` ${this.Ts.EnumField(key, value)}`]).join("\n");
|
|
478
469
|
}).join(",\n"),
|
|
479
470
|
ObjectWrapper: (content) => `{\n${content}\n}`,
|
|
480
471
|
MultilineComment: (contents, formatFn) => [...contents.length === 1 ? [`/** ${contents[0]} */`] : [
|
|
@@ -564,13 +555,13 @@ var CodeGenConfig = class {
|
|
|
564
555
|
}
|
|
565
556
|
];
|
|
566
557
|
templateExtensions = [".eta", ".ejs"];
|
|
567
|
-
constructor({ codeGenConstructs, primitiveTypeConstructs, constants, templateInfos, hooks
|
|
568
|
-
|
|
569
|
-
|
|
558
|
+
constructor({ codeGenConstructs, primitiveTypeConstructs, constants, templateInfos, hooks, ...otherConfig }) {
|
|
559
|
+
Object.assign(this.Ts, codeGenConstructs);
|
|
560
|
+
Object.assign(this.primitiveTypes, primitiveTypeConstructs);
|
|
570
561
|
this.defaultResponseType = this.Ts.Keyword.Void;
|
|
571
562
|
this.update({
|
|
572
563
|
...otherConfig,
|
|
573
|
-
hooks:
|
|
564
|
+
hooks: merge(this.hooks, hooks || {}),
|
|
574
565
|
constants: {
|
|
575
566
|
...constants_exports,
|
|
576
567
|
...constants
|
|
@@ -586,7 +577,7 @@ var CodeGenConfig = class {
|
|
|
586
577
|
this.componentTypeNameResolver = new ComponentTypeNameResolver(this, []);
|
|
587
578
|
}
|
|
588
579
|
update = (update) => {
|
|
589
|
-
|
|
580
|
+
Object.assign(this, update);
|
|
590
581
|
if (this.enumNamesAsValues) this.extractEnums = true;
|
|
591
582
|
};
|
|
592
583
|
};
|
|
@@ -691,7 +682,7 @@ var SchemaFormatters = class {
|
|
|
691
682
|
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
692
683
|
return {
|
|
693
684
|
...parsedSchema,
|
|
694
|
-
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType(
|
|
685
|
+
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType(compact([...parsedSchema.content.map(({ value }) => `${value}`), parsedSchema.nullable && this.config.Ts.Keyword.Null])) || this.config.Ts.Keyword.Any
|
|
695
686
|
};
|
|
696
687
|
},
|
|
697
688
|
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
@@ -708,14 +699,14 @@ var SchemaFormatters = class {
|
|
|
708
699
|
}
|
|
709
700
|
};
|
|
710
701
|
formatSchema = (parsedSchema, formatType = "base") => {
|
|
711
|
-
const schemaType =
|
|
712
|
-
return
|
|
702
|
+
const schemaType = get(parsedSchema, ["schemaType"]) || get(parsedSchema, ["$parsed", "schemaType"]);
|
|
703
|
+
return get(this, [formatType, schemaType])?.(parsedSchema) || parsedSchema;
|
|
713
704
|
};
|
|
714
|
-
formatDescription = (description
|
|
715
|
-
if (!description
|
|
716
|
-
if (!description
|
|
717
|
-
if (inline) return
|
|
718
|
-
return description
|
|
705
|
+
formatDescription = (description, inline) => {
|
|
706
|
+
if (!description) return "";
|
|
707
|
+
if (!description.includes("\n")) return description;
|
|
708
|
+
if (inline) return compact(description.split(/\n/g).map((part) => part.trim())).join(" ");
|
|
709
|
+
return description.replace(/\n$/g, "");
|
|
719
710
|
};
|
|
720
711
|
formatObjectContent = (content) => {
|
|
721
712
|
const fields = [];
|
|
@@ -776,7 +767,7 @@ var MonoSchemaParser = class {
|
|
|
776
767
|
var ArraySchemaParser = class extends MonoSchemaParser {
|
|
777
768
|
parse() {
|
|
778
769
|
let contentType;
|
|
779
|
-
const { type, description
|
|
770
|
+
const { type, description, items } = this.schema || {};
|
|
780
771
|
if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) {
|
|
781
772
|
const tupleContent = [];
|
|
782
773
|
for (const item of items) tupleContent.push(this.schemaParserFabric.createSchemaParser({
|
|
@@ -799,7 +790,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
799
790
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
800
791
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
801
792
|
name: this.typeName,
|
|
802
|
-
description: this.schemaFormatters.formatDescription(description
|
|
793
|
+
description: this.schemaFormatters.formatDescription(description),
|
|
803
794
|
content: this.schemaUtils.safeAddNullToType(this.schema, contentType)
|
|
804
795
|
};
|
|
805
796
|
}
|
|
@@ -810,7 +801,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
810
801
|
var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
811
802
|
parse() {
|
|
812
803
|
const complexType = this.schemaUtils.getComplexType(this.schema);
|
|
813
|
-
const simpleSchema =
|
|
804
|
+
const simpleSchema = omit(this.schema, Object.keys(this.schemaParser._complexSchemaParsers));
|
|
814
805
|
const complexSchemaContent = this.schemaParser._complexSchemaParsers[complexType](this.schema);
|
|
815
806
|
return {
|
|
816
807
|
...typeof this.schema === "object" ? this.schema : {},
|
|
@@ -820,8 +811,8 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
820
811
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
821
812
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
822
813
|
name: this.typeName,
|
|
823
|
-
description: this.schemaFormatters.formatDescription(this.schema.description ||
|
|
824
|
-
content: this.config.Ts.IntersectionType(
|
|
814
|
+
description: this.schemaFormatters.formatDescription(this.schema.description || compact((this.schema[complexType] || []).map((item) => item?.description))[0] || ""),
|
|
815
|
+
content: this.config.Ts.IntersectionType(compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES$1.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
825
816
|
schema: simpleSchema,
|
|
826
817
|
schemaPath: this.schemaPath
|
|
827
818
|
}).getInlineParseContent())])) || this.config.Ts.Keyword.Any
|
|
@@ -834,7 +825,7 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
834
825
|
var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
835
826
|
parse() {
|
|
836
827
|
const ts = this.config.Ts;
|
|
837
|
-
const { discriminator
|
|
828
|
+
const { discriminator, ...noDiscriminatorSchema } = this.schema;
|
|
838
829
|
if (!discriminator.mapping) return this.schemaParserFabric.createSchemaParser({
|
|
839
830
|
schema: noDiscriminatorSchema,
|
|
840
831
|
typeName: this.typeName,
|
|
@@ -846,7 +837,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
846
837
|
skipMappingType,
|
|
847
838
|
abstractSchemaStruct
|
|
848
839
|
});
|
|
849
|
-
const schemaContent = ts.IntersectionType([abstractSchemaStruct?.content, discriminatorSchemaStruct?.content]
|
|
840
|
+
const schemaContent = ts.IntersectionType(compact([abstractSchemaStruct?.content, discriminatorSchemaStruct?.content]));
|
|
850
841
|
return {
|
|
851
842
|
...typeof this.schema === "object" ? this.schema : {},
|
|
852
843
|
$schemaPath: this.schemaPath.slice(),
|
|
@@ -867,7 +858,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
867
858
|
this.typeName
|
|
868
859
|
]);
|
|
869
860
|
const { discriminator } = this.schema;
|
|
870
|
-
const mappingEntries =
|
|
861
|
+
const mappingEntries = Object.entries(discriminator.mapping || {});
|
|
871
862
|
const ableToCreateMappingType = !skipMappingType && !!(abstractSchemaStruct?.typeName && mappingEntries.length);
|
|
872
863
|
const mappingContents = [];
|
|
873
864
|
let mappingTypeName;
|
|
@@ -927,22 +918,24 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
927
918
|
};
|
|
928
919
|
createMappingPropertySchemaEnumKeys = ({ abstractSchemaStruct, discPropertyName }) => {
|
|
929
920
|
const ts = this.config.Ts;
|
|
930
|
-
|
|
931
|
-
let mappingPropertySchema =
|
|
921
|
+
const mappingPropertySchemaEnumKeysMap = {};
|
|
922
|
+
let mappingPropertySchema = get(abstractSchemaStruct?.component?.rawTypeData, ["properties", discPropertyName]);
|
|
932
923
|
if (this.schemaUtils.isRefSchema(mappingPropertySchema)) mappingPropertySchema = this.schemaUtils.getSchemaRefType(mappingPropertySchema);
|
|
933
924
|
const parsedEnum = mappingPropertySchema?.rawTypeData?.$parsed;
|
|
934
|
-
if (parsedEnum?.type === SCHEMA_TYPES$1.ENUM)
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
const
|
|
938
|
-
if (
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
925
|
+
if (parsedEnum?.type === SCHEMA_TYPES$1.ENUM) {
|
|
926
|
+
const enumEntries = (parsedEnum.enum || []).map((key, index) => [key, index]);
|
|
927
|
+
for (const [key, index] of enumEntries) {
|
|
928
|
+
const enumContent = parsedEnum.content?.[index];
|
|
929
|
+
if (this.config.generateUnionEnums) {
|
|
930
|
+
const literalValue = enumContent?.value ?? (key !== void 0 ? ts.StringValue(key) : void 0);
|
|
931
|
+
if (literalValue !== void 0) mappingPropertySchemaEnumKeysMap[key] = literalValue;
|
|
932
|
+
} else if (parsedEnum.typeName && enumContent?.key) mappingPropertySchemaEnumKeysMap[key] = ts.EnumUsageKey(parsedEnum.typeName, enumContent.key);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
942
935
|
return mappingPropertySchemaEnumKeysMap;
|
|
943
936
|
};
|
|
944
937
|
mutateMappingDependentSchema = ({ discPropertyName, abstractSchemaStruct, mappingSchema, refPath, mappingPropertySchemaEnumKeysMap }) => {
|
|
945
|
-
const complexSchemaKeys =
|
|
938
|
+
const complexSchemaKeys = Object.keys(this.schemaParser._complexSchemaParsers);
|
|
946
939
|
if (mappingSchema.$ref && abstractSchemaStruct?.component?.$ref) {
|
|
947
940
|
const mappingRefSchema = this.schemaUtils.getSchemaRefType(mappingSchema)?.rawTypeData;
|
|
948
941
|
if (mappingRefSchema) {
|
|
@@ -961,11 +954,11 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
961
954
|
}
|
|
962
955
|
};
|
|
963
956
|
createAbstractSchemaStruct = () => {
|
|
964
|
-
const { discriminator
|
|
965
|
-
const complexSchemaKeys =
|
|
966
|
-
const schema =
|
|
957
|
+
const { discriminator, ...noDiscriminatorSchema } = this.schema;
|
|
958
|
+
const complexSchemaKeys = Object.keys(this.schemaParser._complexSchemaParsers);
|
|
959
|
+
const schema = omit(structuredClone(noDiscriminatorSchema), complexSchemaKeys);
|
|
967
960
|
const schemaIsAny = this.schemaParserFabric.getInlineParseContent(structuredClone(schema)) === this.config.Ts.Keyword.Any;
|
|
968
|
-
if (!
|
|
961
|
+
if (!Object.keys(schema).length || schemaIsAny) return null;
|
|
969
962
|
const typeName = this.schemaUtils.resolveTypeName(this.typeName, {
|
|
970
963
|
prefixes: this.config.extractingOptions.discriminatorAbstractPrefix,
|
|
971
964
|
resolver: this.config.extractingOptions.discriminatorAbstractResolver
|
|
@@ -1034,9 +1027,9 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1034
1027
|
const refType = this.schemaUtils.getSchemaRefType(this.schema);
|
|
1035
1028
|
const $ref = refType?.$ref || null;
|
|
1036
1029
|
if (Array.isArray(this.schema.enum)) this.schema.enum = this.schema.enum.filter((key) => key != null);
|
|
1037
|
-
if (Array.isArray(this.schema.enum) && Array.isArray(this.schema.enum[0])) return this.schemaParserFabric.parseSchema({ oneOf: this.schema.enum.map((enumNames
|
|
1030
|
+
if (Array.isArray(this.schema.enum) && Array.isArray(this.schema.enum[0])) return this.schemaParserFabric.parseSchema({ oneOf: this.schema.enum.map((enumNames) => ({
|
|
1038
1031
|
type: "array",
|
|
1039
|
-
items: enumNames
|
|
1032
|
+
items: enumNames.map((enumName) => ({
|
|
1040
1033
|
type: "string",
|
|
1041
1034
|
enum: [enumName]
|
|
1042
1035
|
}))
|
|
@@ -1061,8 +1054,8 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1061
1054
|
default: return this.config.Ts.StringValue(value);
|
|
1062
1055
|
}
|
|
1063
1056
|
};
|
|
1064
|
-
if (Array.isArray(enumNames) &&
|
|
1065
|
-
const enumValue =
|
|
1057
|
+
if (Array.isArray(enumNames) && enumNames.length > 0) content = enumNames.map((enumName, index) => {
|
|
1058
|
+
const enumValue = get(this.schema.enum, index);
|
|
1066
1059
|
const formattedKey = this.formatEnumKey({
|
|
1067
1060
|
key: enumName,
|
|
1068
1061
|
value: enumValue
|
|
@@ -1130,21 +1123,24 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1130
1123
|
}
|
|
1131
1124
|
getObjectSchemaContent = (schema) => {
|
|
1132
1125
|
const { properties, additionalProperties } = schema || {};
|
|
1133
|
-
const propertiesContent =
|
|
1134
|
-
|
|
1135
|
-
const
|
|
1126
|
+
const propertiesContent = [];
|
|
1127
|
+
for (const [name, property] of Object.entries(properties || {})) {
|
|
1128
|
+
const required = this.schemaUtils.isPropertyRequired(name, property, schema);
|
|
1129
|
+
const rawTypeData = get(this.schemaUtils.getSchemaRefType(property), "rawTypeData", {});
|
|
1136
1130
|
const nullable = !!(rawTypeData.nullable || property.nullable);
|
|
1137
|
-
const fieldName = this.typeNameFormatter.isValidName(name
|
|
1131
|
+
const fieldName = this.typeNameFormatter.isValidName(name) ? name : this.config.Ts.StringValue(name);
|
|
1138
1132
|
const fieldValue = this.schemaParserFabric.createSchemaParser({
|
|
1139
1133
|
schema: property,
|
|
1140
|
-
schemaPath: [...this.schemaPath, name
|
|
1134
|
+
schemaPath: [...this.schemaPath, name]
|
|
1141
1135
|
}).getInlineParseContent();
|
|
1142
1136
|
const readOnly = property.readOnly;
|
|
1143
|
-
|
|
1137
|
+
const complexType = this.schemaUtils.getComplexType(property);
|
|
1138
|
+
const rawDataComplexType = this.schemaUtils.getComplexType(rawTypeData);
|
|
1139
|
+
propertiesContent.push({
|
|
1144
1140
|
...property,
|
|
1145
1141
|
$$raw: property,
|
|
1146
1142
|
title: property.title,
|
|
1147
|
-
description: property.description ||
|
|
1143
|
+
description: property.description || compact((property[complexType] || []).map((item) => item?.description))[0] || rawTypeData.description || compact((rawTypeData[rawDataComplexType] || []).map((item) => item?.description))[0] || "",
|
|
1148
1144
|
isRequired: required,
|
|
1149
1145
|
isNullable: nullable,
|
|
1150
1146
|
name: fieldName,
|
|
@@ -1155,8 +1151,8 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1155
1151
|
key: fieldName,
|
|
1156
1152
|
value: fieldValue
|
|
1157
1153
|
})
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1154
|
+
});
|
|
1155
|
+
}
|
|
1160
1156
|
if (additionalProperties) {
|
|
1161
1157
|
const propertyNamesSchema = this.schemaUtils.getSchemaPropertyNamesSchema(schema);
|
|
1162
1158
|
let interfaceKeysContent;
|
|
@@ -1181,7 +1177,7 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1181
1177
|
var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
1182
1178
|
parse() {
|
|
1183
1179
|
let contentType = null;
|
|
1184
|
-
const { additionalProperties, type, description
|
|
1180
|
+
const { additionalProperties, type, description, items } = this.schema || {};
|
|
1185
1181
|
if (type === this.config.Ts.Keyword.Object && additionalProperties) {
|
|
1186
1182
|
const propertyNamesSchema = this.schemaUtils.getSchemaPropertyNamesSchema(this.schema);
|
|
1187
1183
|
let recordKeysContent;
|
|
@@ -1200,7 +1196,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1200
1196
|
}
|
|
1201
1197
|
if (Array.isArray(type) && type.length) contentType = this.schemaParser._complexSchemaParsers.oneOf({
|
|
1202
1198
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1203
|
-
oneOf: type.map((type
|
|
1199
|
+
oneOf: type.map((type) => ({ type }))
|
|
1204
1200
|
});
|
|
1205
1201
|
if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1206
1202
|
schema: item,
|
|
@@ -1214,7 +1210,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1214
1210
|
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1215
1211
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
1216
1212
|
name: this.typeName,
|
|
1217
|
-
description: this.schemaFormatters.formatDescription(description
|
|
1213
|
+
description: this.schemaFormatters.formatDescription(description),
|
|
1218
1214
|
content: type === this.config.Ts.Keyword.Null ? type : contentType || this.schemaUtils.getSchemaType(this.schema)
|
|
1219
1215
|
};
|
|
1220
1216
|
}
|
|
@@ -1349,7 +1345,7 @@ var SchemaParser = class {
|
|
|
1349
1345
|
}
|
|
1350
1346
|
schemaType = this.schemaUtils.getInternalSchemaType(this.schema);
|
|
1351
1347
|
this.schemaPath.push(this.typeName);
|
|
1352
|
-
|
|
1348
|
+
merge(this.schema, this.config.hooks.onPreParseSchema(this.schema, this.typeName, schemaType) || {});
|
|
1353
1349
|
parsedSchema = this._baseSchemaParsers[schemaType](this.schema, this.typeName);
|
|
1354
1350
|
this.schema.$parsed = this.config.hooks.onParseSchema(this.schema, parsedSchema) || parsedSchema;
|
|
1355
1351
|
if (this.config.sortTypes && Array.isArray(this.schema.$parsed?.content)) this.schema.$parsed.content = this.schema.$parsed.content.sort(sortByProperty("name"));
|
|
@@ -1366,28 +1362,23 @@ var SchemaParser = class {
|
|
|
1366
1362
|
return this.schemaFormatters.formatSchema(parsedSchema, "base").content;
|
|
1367
1363
|
};
|
|
1368
1364
|
extractSchemaFromResponseStruct = (responseStruct) => {
|
|
1369
|
-
const { content
|
|
1370
|
-
const firstResponse =
|
|
1371
|
-
const firstSchema =
|
|
1365
|
+
const { content, ...extras } = responseStruct;
|
|
1366
|
+
const firstResponse = Object.values(content || {})[0];
|
|
1367
|
+
const firstSchema = get(firstResponse, "schema");
|
|
1372
1368
|
if (!firstSchema) return;
|
|
1369
|
+
const { schema: _, ...restResponse } = firstResponse || {};
|
|
1373
1370
|
return {
|
|
1374
1371
|
...extras,
|
|
1375
|
-
...
|
|
1372
|
+
...restResponse,
|
|
1376
1373
|
...firstSchema
|
|
1377
1374
|
};
|
|
1378
1375
|
};
|
|
1379
1376
|
};
|
|
1380
1377
|
|
|
1381
|
-
//#endregion
|
|
1382
|
-
//#region src/util/internal-case.ts
|
|
1383
|
-
function internalCase(value) {
|
|
1384
|
-
return lodash.camelCase(lodash.lowerCase(value));
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
1378
|
//#endregion
|
|
1388
1379
|
//#region src/util/pascal-case.ts
|
|
1389
1380
|
function pascalCase(value) {
|
|
1390
|
-
return
|
|
1381
|
+
return upperFirst(camelCase(value));
|
|
1391
1382
|
}
|
|
1392
1383
|
|
|
1393
1384
|
//#endregion
|
|
@@ -1404,7 +1395,7 @@ var SchemaUtils = class {
|
|
|
1404
1395
|
this.schemaWalker = schemaWalker;
|
|
1405
1396
|
}
|
|
1406
1397
|
getRequiredProperties = (schema) => {
|
|
1407
|
-
return
|
|
1398
|
+
return uniq(schema && Array.isArray(schema.required) && schema.required || []);
|
|
1408
1399
|
};
|
|
1409
1400
|
isRefSchema = (schema) => {
|
|
1410
1401
|
return !!schema?.$ref;
|
|
@@ -1423,15 +1414,15 @@ var SchemaUtils = class {
|
|
|
1423
1414
|
if (!this.isRefSchema(schema)) return null;
|
|
1424
1415
|
return this.schemaComponentsMap.get(schema.$ref);
|
|
1425
1416
|
};
|
|
1426
|
-
isPropertyRequired = (name
|
|
1417
|
+
isPropertyRequired = (name, propertySchema, rootSchema) => {
|
|
1427
1418
|
if (propertySchema["x-omitempty"] === false) return true;
|
|
1428
|
-
const isRequired = typeof propertySchema.required === "boolean" ? !!propertySchema.required : Array.isArray(rootSchema.required) ? rootSchema.required.includes(name
|
|
1419
|
+
const isRequired = typeof propertySchema.required === "boolean" ? !!propertySchema.required : Array.isArray(rootSchema.required) ? rootSchema.required.includes(name) : !!rootSchema.required;
|
|
1429
1420
|
if (this.config.convertedFromSwagger2) return typeof propertySchema.nullable === this.config.Ts.Keyword.Undefined ? isRequired : !propertySchema.nullable;
|
|
1430
1421
|
return isRequired;
|
|
1431
1422
|
};
|
|
1432
1423
|
isNullMissingInType = (schema, type) => {
|
|
1433
1424
|
const { nullable, type: schemaType } = schema || {};
|
|
1434
|
-
return (nullable || !!
|
|
1425
|
+
return (nullable || !!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} `);
|
|
1435
1426
|
};
|
|
1436
1427
|
safeAddNullToType = (schema, type) => {
|
|
1437
1428
|
if (this.isNullMissingInType(schema, type)) return this.config.Ts.UnionType([type, this.config.Ts.Keyword.Null]);
|
|
@@ -1439,13 +1430,13 @@ var SchemaUtils = class {
|
|
|
1439
1430
|
};
|
|
1440
1431
|
getSchemaPrimitiveType = (rawSchema) => {
|
|
1441
1432
|
const schema = rawSchema || {};
|
|
1442
|
-
if (schema.type) return
|
|
1433
|
+
if (schema.type) return camelCase(schema.type);
|
|
1443
1434
|
if (schema.enum) {
|
|
1444
1435
|
const enumFieldType = typeof schema.enum[0];
|
|
1445
1436
|
if (enumFieldType === this.config.Ts.Keyword.Undefined) return;
|
|
1446
|
-
return
|
|
1437
|
+
return camelCase(enumFieldType);
|
|
1447
1438
|
}
|
|
1448
|
-
if (
|
|
1439
|
+
if (Object.keys(schema.properties || {}).length) return SCHEMA_TYPES$1.OBJECT;
|
|
1449
1440
|
if (schema.items) return SCHEMA_TYPES$1.ARRAY;
|
|
1450
1441
|
return null;
|
|
1451
1442
|
};
|
|
@@ -1458,10 +1449,10 @@ var SchemaUtils = class {
|
|
|
1458
1449
|
};
|
|
1459
1450
|
makeAddRequiredToChildSchema = (parentSchema, childSchema) => {
|
|
1460
1451
|
if (!childSchema) return childSchema;
|
|
1461
|
-
const required =
|
|
1452
|
+
const required = uniq([...this.getRequiredProperties(parentSchema), ...this.getRequiredProperties(childSchema)]);
|
|
1462
1453
|
const refData = this.getSchemaRefType(childSchema);
|
|
1463
1454
|
if (refData) {
|
|
1464
|
-
const existedRequiredKeys =
|
|
1455
|
+
const existedRequiredKeys = Object.keys(refData.rawTypeData?.properties || {}).filter((key) => required.includes(key));
|
|
1465
1456
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1466
1457
|
return {
|
|
1467
1458
|
...childSchema,
|
|
@@ -1469,17 +1460,17 @@ var SchemaUtils = class {
|
|
|
1469
1460
|
};
|
|
1470
1461
|
}
|
|
1471
1462
|
if (childSchema.properties) {
|
|
1472
|
-
const existedRequiredKeys =
|
|
1463
|
+
const existedRequiredKeys = Object.keys(childSchema.properties).filter((key) => required.includes(key));
|
|
1473
1464
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1474
1465
|
return {
|
|
1475
|
-
required:
|
|
1466
|
+
required: uniq([...this.getRequiredProperties(childSchema), ...existedRequiredKeys]),
|
|
1476
1467
|
...childSchema
|
|
1477
1468
|
};
|
|
1478
1469
|
}
|
|
1479
1470
|
return childSchema;
|
|
1480
1471
|
};
|
|
1481
1472
|
filterSchemaContents = (contents, filterFn) => {
|
|
1482
|
-
return
|
|
1473
|
+
return uniq(contents.filter((type) => filterFn(type)));
|
|
1483
1474
|
};
|
|
1484
1475
|
resolveTypeName = (typeName, { suffixes, resolver, prefixes, shouldReserve = true }) => {
|
|
1485
1476
|
if (resolver) return this.config.componentTypeNameResolver.resolve([], (reserved) => {
|
|
@@ -1495,10 +1486,10 @@ var SchemaUtils = class {
|
|
|
1495
1486
|
return SCHEMA_TYPES$1.COMPLEX_UNKNOWN;
|
|
1496
1487
|
};
|
|
1497
1488
|
getInternalSchemaType = (schema) => {
|
|
1498
|
-
if (
|
|
1489
|
+
if (schema.enum && schema.enum.length > 0 || this.getEnumNames(schema) && this.getEnumNames(schema).length > 0) return SCHEMA_TYPES$1.ENUM;
|
|
1499
1490
|
if (schema.discriminator) return SCHEMA_TYPES$1.DISCRIMINATOR;
|
|
1500
1491
|
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES$1.COMPLEX;
|
|
1501
|
-
if (
|
|
1492
|
+
if (schema.properties && Object.keys(schema.properties).length > 0) return SCHEMA_TYPES$1.OBJECT;
|
|
1502
1493
|
if (schema.type === SCHEMA_TYPES$1.ARRAY) return SCHEMA_TYPES$1.ARRAY;
|
|
1503
1494
|
return SCHEMA_TYPES$1.PRIMITIVE;
|
|
1504
1495
|
};
|
|
@@ -1511,7 +1502,7 @@ var SchemaUtils = class {
|
|
|
1511
1502
|
else {
|
|
1512
1503
|
const primitiveType = this.getSchemaPrimitiveType(schema);
|
|
1513
1504
|
if (primitiveType == null) return this.config.Ts.Keyword.Any;
|
|
1514
|
-
const typeAlias =
|
|
1505
|
+
const typeAlias = get(this.config.primitiveTypes, [primitiveType, schema.format]) || get(this.config.primitiveTypes, [primitiveType, "$default"]) || this.config.primitiveTypes[primitiveType];
|
|
1515
1506
|
if (typeof typeAlias === "function") resultType = typeAlias(schema, this);
|
|
1516
1507
|
else resultType = typeAlias || primitiveType;
|
|
1517
1508
|
}
|
|
@@ -1519,9 +1510,9 @@ var SchemaUtils = class {
|
|
|
1519
1510
|
return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, resultType));
|
|
1520
1511
|
};
|
|
1521
1512
|
buildTypeNameFromPath = (schemaPath) => {
|
|
1522
|
-
schemaPath =
|
|
1513
|
+
schemaPath = uniq(compact(schemaPath || []));
|
|
1523
1514
|
if (!schemaPath || !schemaPath[0]) return null;
|
|
1524
|
-
return pascalCase(
|
|
1515
|
+
return pascalCase(uniq([schemaPath[0], schemaPath[schemaPath.length - 1]]).join("_"));
|
|
1525
1516
|
};
|
|
1526
1517
|
isConstantSchema(schema) {
|
|
1527
1518
|
return "const" in schema;
|
|
@@ -1564,7 +1555,7 @@ var SchemaParserFabric = class {
|
|
|
1564
1555
|
schemaPath
|
|
1565
1556
|
});
|
|
1566
1557
|
};
|
|
1567
|
-
createSchema = ({ content, linkedSchema = {}, linkedComponent, schemaPath
|
|
1558
|
+
createSchema = ({ content, linkedSchema = {}, linkedComponent, schemaPath, ...otherSchemaProps }) => {
|
|
1568
1559
|
const parser = this.createSchemaParser({
|
|
1569
1560
|
schema: linkedComponent || linkedSchema,
|
|
1570
1561
|
schemaPath
|
|
@@ -1612,8 +1603,7 @@ var SchemaParserFabric = class {
|
|
|
1612
1603
|
|
|
1613
1604
|
//#endregion
|
|
1614
1605
|
//#region src/util/id.ts
|
|
1615
|
-
const
|
|
1616
|
-
const generateId = nanoid.customAlphabet(ALPHABET, 12);
|
|
1606
|
+
const generateId = () => crypto.randomUUID();
|
|
1617
1607
|
|
|
1618
1608
|
//#endregion
|
|
1619
1609
|
//#region src/schema-routes/util/specific-arg-name-resolver.ts
|
|
@@ -1658,7 +1648,7 @@ var SchemaRoutes = class {
|
|
|
1658
1648
|
this.typeNameFormatter = typeNameFormatter;
|
|
1659
1649
|
this.schemaComponentsMap = schemaComponentsMap;
|
|
1660
1650
|
this.templatesWorker = templatesWorker;
|
|
1661
|
-
this.FORM_DATA_TYPES =
|
|
1651
|
+
this.FORM_DATA_TYPES = uniq([this.schemaUtils.getSchemaType({
|
|
1662
1652
|
type: "string",
|
|
1663
1653
|
format: "file"
|
|
1664
1654
|
}), this.schemaUtils.getSchemaType({
|
|
@@ -1666,49 +1656,50 @@ var SchemaRoutes = class {
|
|
|
1666
1656
|
format: "binary"
|
|
1667
1657
|
})]);
|
|
1668
1658
|
}
|
|
1669
|
-
createRequestsMap = (
|
|
1670
|
-
const parameters =
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1659
|
+
createRequestsMap = (routesByMethod) => {
|
|
1660
|
+
const parameters = get(routesByMethod, "parameters");
|
|
1661
|
+
const result = {};
|
|
1662
|
+
for (const [method, requestInfo] of Object.entries(routesByMethod)) {
|
|
1663
|
+
if (method.startsWith("x-") || ["parameters", "$ref"].includes(method)) continue;
|
|
1664
|
+
result[method] = {
|
|
1674
1665
|
...requestInfo,
|
|
1675
|
-
parameters:
|
|
1666
|
+
parameters: compact([...parameters || [], ...requestInfo.parameters || []])
|
|
1676
1667
|
};
|
|
1677
|
-
|
|
1678
|
-
|
|
1668
|
+
}
|
|
1669
|
+
return result;
|
|
1679
1670
|
};
|
|
1680
|
-
parseRouteName = (
|
|
1681
|
-
const routeName = this.config.hooks.onPreBuildRoutePath(
|
|
1671
|
+
parseRouteName = (rawRoute) => {
|
|
1672
|
+
const routeName = this.config.hooks.onPreBuildRoutePath(rawRoute) || rawRoute;
|
|
1682
1673
|
const pathParamMatches = (routeName || "").match(/({[\w[\\\]^`][-_.\w]*})|(:[\w[\\\]^`][-_.\w]*:?)/g);
|
|
1683
|
-
const pathParams =
|
|
1674
|
+
const pathParams = [];
|
|
1675
|
+
for (const match of pathParamMatches || []) {
|
|
1684
1676
|
const paramName = match.replace(/\{|\}|:/g, "");
|
|
1685
|
-
if (!paramName)
|
|
1677
|
+
if (!paramName) continue;
|
|
1686
1678
|
if (paramName.includes("-")) consola.warn("wrong path param name", paramName);
|
|
1687
|
-
pathParams
|
|
1679
|
+
pathParams.push({
|
|
1688
1680
|
$match: match,
|
|
1689
|
-
name:
|
|
1681
|
+
name: camelCase(paramName),
|
|
1690
1682
|
required: true,
|
|
1691
1683
|
type: "string",
|
|
1692
1684
|
description: "",
|
|
1693
1685
|
schema: { type: "string" },
|
|
1694
1686
|
in: "path"
|
|
1695
1687
|
});
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
return fixedRoute$1.replace(pathParam.$match, `\${${insertion}}`);
|
|
1688
|
+
}
|
|
1689
|
+
let fixedRoute = pathParams.reduce((fixedRoute, pathParam, i, arr) => {
|
|
1690
|
+
const insertion = this.config.hooks.onInsertPathParam(pathParam.name, i, arr, fixedRoute) || pathParam.name;
|
|
1691
|
+
return fixedRoute.replace(pathParam.$match, `\${${insertion}}`);
|
|
1701
1692
|
}, routeName || "");
|
|
1702
1693
|
const queryParamMatches = fixedRoute.match(/(\{\?.*\})/g);
|
|
1703
1694
|
const queryParams = [];
|
|
1704
1695
|
if (queryParamMatches?.length) {
|
|
1705
1696
|
for (const match of queryParamMatches) fixedRoute = fixedRoute.replace(match, "");
|
|
1706
|
-
const paramNames =
|
|
1697
|
+
const paramNames = uniq(queryParamMatches.join(",").replace(/(\{\?)|(\})|\s/g, "").split(","));
|
|
1707
1698
|
for (const paramName of paramNames) {
|
|
1708
|
-
if (paramName.includes("-")) consola.warn("wrong query param name", paramName);
|
|
1699
|
+
if (typeof paramName === "string" && paramName.includes("-")) consola.warn("wrong query param name", paramName);
|
|
1709
1700
|
queryParams.push({
|
|
1710
1701
|
$match: paramName,
|
|
1711
|
-
name:
|
|
1702
|
+
name: typeof paramName === "string" ? camelCase(paramName) : camelCase(String(paramName)),
|
|
1712
1703
|
required: true,
|
|
1713
1704
|
type: "string",
|
|
1714
1705
|
description: "",
|
|
@@ -1718,7 +1709,7 @@ var SchemaRoutes = class {
|
|
|
1718
1709
|
}
|
|
1719
1710
|
}
|
|
1720
1711
|
const result = {
|
|
1721
|
-
originalRoute:
|
|
1712
|
+
originalRoute: rawRoute || "",
|
|
1722
1713
|
route: fixedRoute,
|
|
1723
1714
|
pathParams,
|
|
1724
1715
|
queryParams
|
|
@@ -1735,7 +1726,7 @@ var SchemaRoutes = class {
|
|
|
1735
1726
|
formData: [],
|
|
1736
1727
|
cookie: []
|
|
1737
1728
|
};
|
|
1738
|
-
|
|
1729
|
+
for (const parameter of parameters || []) {
|
|
1739
1730
|
const refTypeInfo = this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);
|
|
1740
1731
|
let routeParam = null;
|
|
1741
1732
|
if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
|
|
@@ -1746,7 +1737,7 @@ var SchemaRoutes = class {
|
|
|
1746
1737
|
};
|
|
1747
1738
|
if (parameter?.required && !routeParam.required) routeParam.required = parameter.required;
|
|
1748
1739
|
} else {
|
|
1749
|
-
if (!parameter.in)
|
|
1740
|
+
if (!parameter.in) continue;
|
|
1750
1741
|
if (!routeParams[parameter.in]) routeParams[parameter.in] = [];
|
|
1751
1742
|
routeParam = {
|
|
1752
1743
|
...parameter,
|
|
@@ -1754,16 +1745,19 @@ var SchemaRoutes = class {
|
|
|
1754
1745
|
};
|
|
1755
1746
|
}
|
|
1756
1747
|
if (routeParam.in === "path") {
|
|
1757
|
-
if (!routeParam.name)
|
|
1758
|
-
routeParam.name =
|
|
1748
|
+
if (!routeParam.name) continue;
|
|
1749
|
+
routeParam.name = camelCase(routeParam.name);
|
|
1759
1750
|
}
|
|
1760
|
-
|
|
1761
|
-
}
|
|
1751
|
+
routeParams[routeParam.in].push(routeParam);
|
|
1752
|
+
}
|
|
1762
1753
|
for (const pathParam of pathParamsFromRouteName) if (!routeParams.path.some((parameter) => parameter.name === pathParam.name)) routeParams.path.push(pathParam);
|
|
1763
1754
|
for (const queryParam of queryParamsFromRouteName) if (!routeParams.query.some((parameter) => parameter.name === queryParam.name)) routeParams.query.push(queryParam);
|
|
1764
1755
|
return routeParams;
|
|
1765
1756
|
};
|
|
1766
|
-
getContentTypes = (requestInfo, extraContentTypes) =>
|
|
1757
|
+
getContentTypes = (requestInfo, extraContentTypes) => {
|
|
1758
|
+
const requestInfoArray = Array.isArray(requestInfo) ? requestInfo : Object.values(requestInfo || {});
|
|
1759
|
+
return uniq(compact([...extraContentTypes || [], ...flattenDeep(requestInfoArray.map((requestInfoData) => requestInfoData && Object.keys(requestInfoData?.content || {})))]));
|
|
1760
|
+
};
|
|
1767
1761
|
getContentKind = (contentTypes) => {
|
|
1768
1762
|
if (contentTypes.includes("application/vnd.api+json")) return CONTENT_KIND.JSON_API;
|
|
1769
1763
|
if (contentTypes.some((contentType) => contentType.startsWith("application/json")) || contentTypes.some((contentType) => contentType.endsWith("+json"))) return CONTENT_KIND.JSON;
|
|
@@ -1775,7 +1769,7 @@ var SchemaRoutes = class {
|
|
|
1775
1769
|
};
|
|
1776
1770
|
isSuccessStatus = (status) => this.config.defaultResponseAsSuccess && status === "default" || +status >= this.config.successResponseStatusRange[0] && +status <= this.config.successResponseStatusRange[1] || status === "2xx";
|
|
1777
1771
|
getSchemaFromRequestType = (requestInfo) => {
|
|
1778
|
-
const content =
|
|
1772
|
+
const content = get(requestInfo, "content");
|
|
1779
1773
|
if (!content) return null;
|
|
1780
1774
|
for (const dataType in content) if (content[dataType]?.schema) return {
|
|
1781
1775
|
...content[dataType].schema,
|
|
@@ -1789,13 +1783,13 @@ var SchemaRoutes = class {
|
|
|
1789
1783
|
if (schema) {
|
|
1790
1784
|
const content = this.schemaParserFabric.getInlineParseContent(schema, typeName, [operationId]);
|
|
1791
1785
|
const foundedSchemaByName = parsedSchemas.find((parsedSchema) => this.typeNameFormatter.format(parsedSchema.name) === content);
|
|
1792
|
-
const foundSchemaByContent = parsedSchemas.find((parsedSchema) =>
|
|
1786
|
+
const foundSchemaByContent = parsedSchemas.find((parsedSchema) => isEqual(parsedSchema.content, content));
|
|
1793
1787
|
const foundSchema = foundedSchemaByName || foundSchemaByContent;
|
|
1794
1788
|
return foundSchema ? this.typeNameFormatter.format(foundSchema.name) : content;
|
|
1795
1789
|
}
|
|
1796
1790
|
if (refTypeInfo) {
|
|
1797
1791
|
const typeNameWithoutOpId = refTypeInfo.typeName.replace(operationId, "");
|
|
1798
|
-
if (parsedSchemas.find((schema
|
|
1792
|
+
if (parsedSchemas.find((schema) => schema.name === typeNameWithoutOpId)) return this.typeNameFormatter.format(typeNameWithoutOpId);
|
|
1799
1793
|
switch (refTypeInfo.componentName) {
|
|
1800
1794
|
case "schemas": return this.typeNameFormatter.format(refTypeInfo.typeName);
|
|
1801
1795
|
case "responses":
|
|
@@ -1805,23 +1799,27 @@ var SchemaRoutes = class {
|
|
|
1805
1799
|
}
|
|
1806
1800
|
return defaultType || this.config.Ts.Keyword.Any;
|
|
1807
1801
|
};
|
|
1808
|
-
getRequestInfoTypes = ({ requestInfos, parsedSchemas, operationId, defaultType }) =>
|
|
1809
|
-
const
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1802
|
+
getRequestInfoTypes = ({ requestInfos, parsedSchemas, operationId, defaultType }) => {
|
|
1803
|
+
const result = [];
|
|
1804
|
+
for (const [status, requestInfo] of Object.entries(requestInfos || {})) {
|
|
1805
|
+
const contentTypes = this.getContentTypes([requestInfo], operationId);
|
|
1806
|
+
result.push({
|
|
1807
|
+
...requestInfo || {},
|
|
1808
|
+
contentTypes,
|
|
1809
|
+
contentKind: this.getContentKind(contentTypes),
|
|
1810
|
+
type: this.schemaParserFabric.schemaUtils.safeAddNullToType(requestInfo, this.getTypeFromRequestInfo({
|
|
1811
|
+
requestInfo,
|
|
1812
|
+
parsedSchemas,
|
|
1813
|
+
operationId,
|
|
1814
|
+
defaultType
|
|
1815
|
+
})),
|
|
1816
|
+
description: this.schemaParserFabric.schemaFormatters.formatDescription(requestInfo.description || "", true),
|
|
1817
|
+
status: Number.isNaN(+status) ? status : +status,
|
|
1818
|
+
isSuccess: this.isSuccessStatus(status)
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
return result;
|
|
1822
|
+
};
|
|
1825
1823
|
getResponseBodyInfo = (routeInfo, parsedSchemas) => {
|
|
1826
1824
|
const { produces, operationId, responses } = routeInfo;
|
|
1827
1825
|
const contentTypes = this.getContentTypes(responses, [...produces || [], routeInfo["x-accepts"]]);
|
|
@@ -1930,13 +1928,12 @@ var SchemaRoutes = class {
|
|
|
1930
1928
|
};
|
|
1931
1929
|
return acc;
|
|
1932
1930
|
}, {});
|
|
1933
|
-
const fixedQueryParams =
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
}, {});
|
|
1931
|
+
const fixedQueryParams = {};
|
|
1932
|
+
const queryObjectProperties = get(queryObjectSchema, "properties") || {};
|
|
1933
|
+
for (const [name, property] of Object.entries(queryObjectProperties)) if (name && typeof property === "object") fixedQueryParams[name] = {
|
|
1934
|
+
...property,
|
|
1935
|
+
in: "query"
|
|
1936
|
+
};
|
|
1940
1937
|
const schema = {
|
|
1941
1938
|
...queryObjectSchema,
|
|
1942
1939
|
properties: {
|
|
@@ -1979,7 +1976,7 @@ var SchemaRoutes = class {
|
|
|
1979
1976
|
successResponse.schema.contentKind = contentKind;
|
|
1980
1977
|
if (successResponse.schema.typeData) successResponse.schema.typeData.isExtractedResponseBody = true;
|
|
1981
1978
|
successResponse.type = this.schemaParserFabric.getInlineParseContent({ $ref: successResponse.schema.$ref });
|
|
1982
|
-
if (idx > -1)
|
|
1979
|
+
if (idx > -1) Object.assign(responseBodyInfo.responses[idx], {
|
|
1983
1980
|
...successResponse.schema,
|
|
1984
1981
|
type: successResponse.type
|
|
1985
1982
|
});
|
|
@@ -1992,18 +1989,18 @@ var SchemaRoutes = class {
|
|
|
1992
1989
|
suffixes: this.config.extractingOptions.responseErrorSuffix,
|
|
1993
1990
|
resolver: this.config.extractingOptions.responseErrorNameResolver
|
|
1994
1991
|
});
|
|
1995
|
-
const errorSchemas = responseBodyInfo.error.schemas.map(this.getSchemaFromRequestType)
|
|
1992
|
+
const errorSchemas = compact(responseBodyInfo.error.schemas.map(this.getSchemaFromRequestType));
|
|
1996
1993
|
if (!errorSchemas.length) return;
|
|
1997
1994
|
const schema = this.schemaParserFabric.parseSchema({
|
|
1998
1995
|
oneOf: errorSchemas,
|
|
1999
|
-
title: errorSchemas.map((schema
|
|
2000
|
-
description: errorSchemas.map((schema
|
|
1996
|
+
title: compact(errorSchemas.map((schema) => schema.title)).join(" "),
|
|
1997
|
+
description: compact(errorSchemas.map((schema) => schema.description)).join("\n")
|
|
2001
1998
|
}, null, [routeInfo.operationId]);
|
|
2002
1999
|
const component = this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef([
|
|
2003
2000
|
"components",
|
|
2004
2001
|
"schemas",
|
|
2005
2002
|
typeName
|
|
2006
|
-
]),
|
|
2003
|
+
]), schema);
|
|
2007
2004
|
responseBodyInfo.error.schemas = [component];
|
|
2008
2005
|
if (component.typeData) component.typeData.isExtractedResponseError = true;
|
|
2009
2006
|
responseBodyInfo.error.type = this.typeNameFormatter.format(component.typeName);
|
|
@@ -2031,11 +2028,11 @@ var SchemaRoutes = class {
|
|
|
2031
2028
|
parseRouteInfo = (rawRouteName, routeInfo, method, usageSchema, parsedSchemas) => {
|
|
2032
2029
|
const { security: globalSecurity } = usageSchema;
|
|
2033
2030
|
const { moduleNameIndex, moduleNameFirstTag, extractRequestParams } = this.config;
|
|
2034
|
-
const { operationId, requestBody, security, parameters, summary, description
|
|
2031
|
+
const { operationId, requestBody, security, parameters, summary, description, tags, responses, requestBodyName, produces, consumes, ...otherInfo } = routeInfo;
|
|
2035
2032
|
const { route, pathParams: pathParamsFromRouteName, queryParams: queryParamsFromRouteName } = this.parseRouteName(rawRouteName);
|
|
2036
2033
|
const routeId = generateId();
|
|
2037
2034
|
const firstTag = tags && tags.length > 0 ? tags[0] : null;
|
|
2038
|
-
const moduleName = moduleNameFirstTag && firstTag ?
|
|
2035
|
+
const moduleName = moduleNameFirstTag && firstTag ? camelCase(firstTag) : camelCase(compact(route.split("/"))[moduleNameIndex] || "");
|
|
2039
2036
|
let hasSecurity = !!globalSecurity?.length;
|
|
2040
2037
|
if (security) hasSecurity = security.length > 0;
|
|
2041
2038
|
const routeParams = this.getRouteParams(routeInfo, pathParamsFromRouteName, queryParamsFromRouteName);
|
|
@@ -2055,7 +2052,7 @@ var SchemaRoutes = class {
|
|
|
2055
2052
|
route: rawRouteName,
|
|
2056
2053
|
moduleName,
|
|
2057
2054
|
responsesTypes: responseBodyInfo.responses,
|
|
2058
|
-
description
|
|
2055
|
+
description,
|
|
2059
2056
|
tags,
|
|
2060
2057
|
summary,
|
|
2061
2058
|
responses,
|
|
@@ -2152,7 +2149,7 @@ var SchemaRoutes = class {
|
|
|
2152
2149
|
};
|
|
2153
2150
|
attachSchema = ({ usageSchema, parsedSchemas }) => {
|
|
2154
2151
|
this.config.routeNameDuplicatesMap.clear();
|
|
2155
|
-
const pathsEntries =
|
|
2152
|
+
const pathsEntries = Object.entries(usageSchema.paths || {});
|
|
2156
2153
|
for (const [rawRouteName, routeInfoByMethodsMap] of pathsEntries) {
|
|
2157
2154
|
const routeInfosMap = this.createRequestsMap(routeInfoByMethodsMap);
|
|
2158
2155
|
for (const [method, routeInfo] of Object.entries(routeInfosMap)) {
|
|
@@ -2176,37 +2173,36 @@ var SchemaRoutes = class {
|
|
|
2176
2173
|
} else modules.$outOfModule.push(route);
|
|
2177
2174
|
return modules;
|
|
2178
2175
|
}, { $outOfModule: [] });
|
|
2179
|
-
const routeGroups =
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2176
|
+
const routeGroups = {
|
|
2177
|
+
outOfModule: void 0,
|
|
2178
|
+
combined: void 0
|
|
2179
|
+
};
|
|
2180
|
+
for (const [moduleName, routesGroup] of Object.entries(groupedRoutes)) if (moduleName === "$outOfModule") routeGroups.outOfModule = routesGroup;
|
|
2181
|
+
else {
|
|
2182
|
+
if (!routeGroups.combined) routeGroups.combined = [];
|
|
2183
|
+
routeGroups.combined.push({
|
|
2184
|
+
moduleName,
|
|
2185
|
+
routes: routesGroup.map((route) => {
|
|
2186
|
+
const { original: originalName, usage: usageName } = route.routeName;
|
|
2187
|
+
if (routesGroup.length > 1 && usageName !== originalName && !routesGroup.some(({ routeName, id }) => id !== route.id && originalName === routeName.original)) return {
|
|
2188
|
+
...route,
|
|
2189
|
+
routeName: {
|
|
2190
|
+
...route.routeName,
|
|
2191
|
+
usage: originalName
|
|
2192
|
+
}
|
|
2193
|
+
};
|
|
2194
|
+
return route;
|
|
2195
|
+
})
|
|
2196
|
+
});
|
|
2197
|
+
}
|
|
2200
2198
|
if (this.config.sortRoutes) {
|
|
2201
2199
|
if (routeGroups.outOfModule) routeGroups.outOfModule = this.sortRoutes(routeGroups.outOfModule);
|
|
2202
|
-
if (routeGroups.combined)
|
|
2203
|
-
routeGroup.routes = this.sortRoutes(routeGroup.routes);
|
|
2204
|
-
});
|
|
2200
|
+
if (routeGroups.combined) for (const routeGroup of routeGroups.combined) routeGroup.routes = this.sortRoutes(routeGroup.routes);
|
|
2205
2201
|
}
|
|
2206
2202
|
return routeGroups;
|
|
2207
2203
|
};
|
|
2208
2204
|
sortRoutes = (routes) => {
|
|
2209
|
-
return
|
|
2205
|
+
return routes.slice().sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
|
|
2210
2206
|
};
|
|
2211
2207
|
};
|
|
2212
2208
|
|
|
@@ -2221,8 +2217,8 @@ var SchemaWalker = class {
|
|
|
2221
2217
|
this.config = config;
|
|
2222
2218
|
this.swaggerSchemaResolver = swaggerSchemaResolver;
|
|
2223
2219
|
}
|
|
2224
|
-
addSchema = (name
|
|
2225
|
-
this.schemas.set(name
|
|
2220
|
+
addSchema = (name, schema) => {
|
|
2221
|
+
this.schemas.set(name, structuredClone(schema));
|
|
2226
2222
|
};
|
|
2227
2223
|
_isLocalRef = (ref) => {
|
|
2228
2224
|
return ref.startsWith("#");
|
|
@@ -2231,8 +2227,7 @@ var SchemaWalker = class {
|
|
|
2231
2227
|
return ref.startsWith("http://") || ref.startsWith("https://");
|
|
2232
2228
|
};
|
|
2233
2229
|
_getRefDataFromSchema = (schema, ref) => {
|
|
2234
|
-
const
|
|
2235
|
-
const refData = lodash.get(schema, path$2);
|
|
2230
|
+
const refData = get(schema, ref.replace("#", "").split("/"));
|
|
2236
2231
|
if (refData) this.caches.set(ref, refData);
|
|
2237
2232
|
return refData;
|
|
2238
2233
|
};
|
|
@@ -2245,14 +2240,14 @@ var Request = class {
|
|
|
2245
2240
|
constructor(config) {
|
|
2246
2241
|
this.config = config;
|
|
2247
2242
|
}
|
|
2248
|
-
async download({ url
|
|
2243
|
+
async download({ url, authToken, ...options }) {
|
|
2249
2244
|
const requestOptions = {};
|
|
2250
2245
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2251
|
-
|
|
2246
|
+
merge(merge(requestOptions, options), this.config.requestOptions || {});
|
|
2252
2247
|
try {
|
|
2253
|
-
return await (await fetch(url
|
|
2248
|
+
return await (await fetch(url, requestOptions)).text();
|
|
2254
2249
|
} catch (error) {
|
|
2255
|
-
const message = `error while fetching data from URL "${url
|
|
2250
|
+
const message = `error while fetching data from URL "${url}"`;
|
|
2256
2251
|
consola.error(message, error);
|
|
2257
2252
|
return message;
|
|
2258
2253
|
}
|
|
@@ -2271,21 +2266,21 @@ var SwaggerSchemaResolver = class {
|
|
|
2271
2266
|
this.request = new Request(config);
|
|
2272
2267
|
}
|
|
2273
2268
|
async create() {
|
|
2274
|
-
const { spec, patch, input, url
|
|
2269
|
+
const { spec, patch, input, url, authorizationToken } = this.config;
|
|
2275
2270
|
if (spec) return await this.convertSwaggerObject(spec, { patch });
|
|
2276
|
-
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url
|
|
2271
|
+
const swaggerSchemaFile = await this.fetchSwaggerSchemaFile(input, url, authorizationToken);
|
|
2277
2272
|
const swaggerSchemaObject = this.processSwaggerSchemaFile(swaggerSchemaFile);
|
|
2278
2273
|
return await this.convertSwaggerObject(swaggerSchemaObject, { patch });
|
|
2279
2274
|
}
|
|
2280
2275
|
convertSwaggerObject(swaggerSchema, converterOptions) {
|
|
2281
2276
|
return new Promise((resolve) => {
|
|
2282
2277
|
const result = structuredClone(swaggerSchema);
|
|
2283
|
-
result.info =
|
|
2278
|
+
result.info = merge({
|
|
2284
2279
|
title: "No title",
|
|
2285
2280
|
version: ""
|
|
2286
|
-
}, result.info);
|
|
2281
|
+
}, result.info || {});
|
|
2287
2282
|
if (!Object.hasOwn(result, "openapi")) {
|
|
2288
|
-
result.paths =
|
|
2283
|
+
result.paths = merge({}, result.paths || {});
|
|
2289
2284
|
swagger2openapi.convertObj(result, {
|
|
2290
2285
|
...converterOptions,
|
|
2291
2286
|
resolveInternal: true,
|
|
@@ -2293,7 +2288,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2293
2288
|
refSiblings: "preserve",
|
|
2294
2289
|
rbname: "requestBodyName"
|
|
2295
2290
|
}, (err, options) => {
|
|
2296
|
-
const parsedSwaggerSchema =
|
|
2291
|
+
const parsedSwaggerSchema = get(err, "options.openapi") ?? get(options, "openapi");
|
|
2297
2292
|
if (!parsedSwaggerSchema && err) throw err;
|
|
2298
2293
|
this.config.update({ convertedFromSwagger2: true });
|
|
2299
2294
|
resolve({
|
|
@@ -2328,23 +2323,21 @@ var SwaggerSchemaResolver = class {
|
|
|
2328
2323
|
}
|
|
2329
2324
|
}
|
|
2330
2325
|
fixSwaggerSchema({ usageSchema, originalSchema }) {
|
|
2331
|
-
const usagePaths =
|
|
2332
|
-
const originalPaths =
|
|
2333
|
-
|
|
2334
|
-
const originalPathObject =
|
|
2335
|
-
|
|
2336
|
-
const originalRouteInfo =
|
|
2337
|
-
const usageRouteParams =
|
|
2338
|
-
const originalRouteParams =
|
|
2326
|
+
const usagePaths = get(usageSchema, "paths") || {};
|
|
2327
|
+
const originalPaths = get(originalSchema, "paths") || {};
|
|
2328
|
+
for (const [route, usagePathObject] of Object.entries(usagePaths)) {
|
|
2329
|
+
const originalPathObject = get(originalPaths, route) || {};
|
|
2330
|
+
for (const [methodName, usageRouteInfo] of Object.entries(usagePathObject)) {
|
|
2331
|
+
const originalRouteInfo = get(originalPathObject, methodName) || {};
|
|
2332
|
+
const usageRouteParams = get(usageRouteInfo, "parameters") || [];
|
|
2333
|
+
const originalRouteParams = get(originalRouteInfo, "parameters") || [];
|
|
2339
2334
|
if (typeof usageRouteInfo === "object") {
|
|
2340
|
-
usageRouteInfo.consumes =
|
|
2341
|
-
usageRouteInfo.produces =
|
|
2335
|
+
usageRouteInfo.consumes = uniq(compact([...usageRouteInfo.consumes || [], ...originalRouteInfo.consumes || []]));
|
|
2336
|
+
usageRouteInfo.produces = uniq(compact([...usageRouteInfo.produces || [], ...originalRouteInfo.produces || []]));
|
|
2342
2337
|
}
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
});
|
|
2347
|
-
});
|
|
2338
|
+
for (const originalRouteParam of originalRouteParams) if (!usageRouteParams.find((param) => originalRouteParam.in === param.in && originalRouteParam.name === param.name)) usageRouteParams.push(originalRouteParam);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2348
2341
|
}
|
|
2349
2342
|
};
|
|
2350
2343
|
|
|
@@ -2364,10 +2357,10 @@ var TemplatesWorker = class {
|
|
|
2364
2357
|
if (this.config.silent) consola.level = 0;
|
|
2365
2358
|
}
|
|
2366
2359
|
getTemplatePaths = (config) => {
|
|
2367
|
-
const __dirname
|
|
2368
|
-
const baseTemplatesPath = path$1.resolve(__dirname
|
|
2369
|
-
const defaultTemplatesPath = path$1.resolve(__dirname
|
|
2370
|
-
const modularTemplatesPath = path$1.resolve(__dirname
|
|
2360
|
+
const __dirname = path$1.dirname(url$1.fileURLToPath(import.meta.url));
|
|
2361
|
+
const baseTemplatesPath = path$1.resolve(__dirname, "../templates/base");
|
|
2362
|
+
const defaultTemplatesPath = path$1.resolve(__dirname, "../templates/default");
|
|
2363
|
+
const modularTemplatesPath = path$1.resolve(__dirname, "../templates/modular");
|
|
2371
2364
|
return {
|
|
2372
2365
|
base: baseTemplatesPath,
|
|
2373
2366
|
default: defaultTemplatesPath,
|
|
@@ -2376,7 +2369,7 @@ var TemplatesWorker = class {
|
|
|
2376
2369
|
custom: config.templates && path$1.resolve(process.cwd(), config.templates)
|
|
2377
2370
|
};
|
|
2378
2371
|
};
|
|
2379
|
-
cropExtension = (path
|
|
2372
|
+
cropExtension = (path) => this.config.templateExtensions.reduce((path, ext) => path.endsWith(ext) ? path.replace(ext, "") : path, path);
|
|
2380
2373
|
getTemplateFullPath = (path_, fileName) => {
|
|
2381
2374
|
const raw = path$1.resolve(path_, "./", this.cropExtension(fileName));
|
|
2382
2375
|
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
@@ -2385,39 +2378,39 @@ var TemplatesWorker = class {
|
|
|
2385
2378
|
if (packageOrPath.startsWith("./") || packageOrPath.startsWith("../")) return require(path$1.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2386
2379
|
return require(packageOrPath);
|
|
2387
2380
|
};
|
|
2388
|
-
getTemplate = (name
|
|
2381
|
+
getTemplate = (name, fileName, path) => {
|
|
2389
2382
|
const { templatePaths } = this.config;
|
|
2390
|
-
if (path
|
|
2383
|
+
if (path) return this.fileSystem.getFileContent(path);
|
|
2391
2384
|
if (!fileName) return "";
|
|
2392
2385
|
const customFullPath = templatePaths.custom && this.getTemplateFullPath(templatePaths.custom, fileName);
|
|
2393
2386
|
let fileContent = customFullPath && this.fileSystem.getFileContent(customFullPath);
|
|
2394
2387
|
if (fileContent) {
|
|
2395
|
-
consola.info(`"${name
|
|
2388
|
+
consola.info(`"${name.toLowerCase()}" template found in "${templatePaths.custom}"`);
|
|
2396
2389
|
return fileContent;
|
|
2397
2390
|
}
|
|
2398
2391
|
const baseFullPath = this.getTemplateFullPath(templatePaths.base, fileName);
|
|
2399
2392
|
if (baseFullPath) fileContent = this.fileSystem.getFileContent(baseFullPath);
|
|
2400
|
-
else if (templatePaths.custom) consola.warn("Code generator will use the default template:", `"${name
|
|
2401
|
-
else consola.info(`Code generator will use the default template for "${name
|
|
2393
|
+
else if (templatePaths.custom) consola.warn("Code generator will use the default template:", `"${name.toLowerCase()}"`, "template not found in", `"${templatePaths.custom}"`);
|
|
2394
|
+
else consola.info(`Code generator will use the default template for "${name.toLowerCase()}"`);
|
|
2402
2395
|
const originalFullPath = this.getTemplateFullPath(templatePaths.original, fileName);
|
|
2403
2396
|
if (originalFullPath) fileContent = this.fileSystem.getFileContent(originalFullPath);
|
|
2404
2397
|
return fileContent;
|
|
2405
2398
|
};
|
|
2406
2399
|
getTemplates = ({ templatePaths }) => {
|
|
2407
2400
|
if (templatePaths.custom) consola.info(`try to read templates from directory "${templatePaths.custom}"`);
|
|
2408
|
-
return
|
|
2401
|
+
return this.config.templateInfos.reduce((acc, { name, fileName }) => ({
|
|
2409
2402
|
...acc,
|
|
2410
|
-
[name
|
|
2403
|
+
[name]: this.getTemplate(name, fileName)
|
|
2411
2404
|
}), {});
|
|
2412
2405
|
};
|
|
2413
|
-
findTemplateWithExt = (path
|
|
2414
|
-
const raw = this.cropExtension(path
|
|
2406
|
+
findTemplateWithExt = (path) => {
|
|
2407
|
+
const raw = this.cropExtension(path);
|
|
2415
2408
|
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2416
2409
|
};
|
|
2417
2410
|
getTemplateContent = (path_) => {
|
|
2418
|
-
const foundTemplatePathKey =
|
|
2411
|
+
const foundTemplatePathKey = Object.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
2419
2412
|
if (foundTemplatePathKey) {
|
|
2420
|
-
const rawPath = path$1.resolve(path_.replace(`@${foundTemplatePathKey}`,
|
|
2413
|
+
const rawPath = path$1.resolve(path_.replace(`@${foundTemplatePathKey}`, get(this.config.templatePaths, foundTemplatePathKey)));
|
|
2421
2414
|
const fixedPath = this.findTemplateWithExt(rawPath);
|
|
2422
2415
|
if (fixedPath) return this.fileSystem.getFileContent(fixedPath);
|
|
2423
2416
|
}
|
|
@@ -2432,7 +2425,7 @@ var TemplatesWorker = class {
|
|
|
2432
2425
|
return eta.render(eta.compile(template, { async: false }), {
|
|
2433
2426
|
...this.getRenderTemplateData(),
|
|
2434
2427
|
...configuration
|
|
2435
|
-
}, { includeFile: (path
|
|
2428
|
+
}, { includeFile: (path, configuration) => this.renderTemplate(this.getTemplateContent(path), configuration) });
|
|
2436
2429
|
};
|
|
2437
2430
|
};
|
|
2438
2431
|
|
|
@@ -2499,51 +2492,50 @@ var TypeNameFormatter = class {
|
|
|
2499
2492
|
constructor(config) {
|
|
2500
2493
|
this.config = config;
|
|
2501
2494
|
}
|
|
2502
|
-
format = (name
|
|
2495
|
+
format = (name, options = {}) => {
|
|
2503
2496
|
const schemaType = options.type ?? "type-name";
|
|
2504
2497
|
const typePrefix = schemaType === "enum-key" ? this.config.enumKeyPrefix : this.config.typePrefix;
|
|
2505
2498
|
const typeSuffix = schemaType === "enum-key" ? this.config.enumKeySuffix : this.config.typeSuffix;
|
|
2506
|
-
const hashKey = `${typePrefix}_${name
|
|
2507
|
-
if (typeof name
|
|
2508
|
-
consola.warn("wrong model name", name
|
|
2509
|
-
return name
|
|
2499
|
+
const hashKey = `${typePrefix}_${name}_${typeSuffix}`;
|
|
2500
|
+
if (typeof name !== "string") {
|
|
2501
|
+
consola.warn("wrong model name", name);
|
|
2502
|
+
return name;
|
|
2510
2503
|
}
|
|
2511
|
-
if (/^(?!\d)([A-Z0-9_]{1,})$/g.test(name
|
|
2504
|
+
if (/^(?!\d)([A-Z0-9_]{1,})$/g.test(name)) return compact([
|
|
2512
2505
|
typePrefix,
|
|
2513
|
-
name
|
|
2506
|
+
name,
|
|
2514
2507
|
typeSuffix
|
|
2515
2508
|
]).join("_");
|
|
2516
2509
|
if (this.formattedModelNamesMap.has(hashKey)) return this.formattedModelNamesMap.get(hashKey);
|
|
2517
|
-
const
|
|
2518
|
-
const
|
|
2519
|
-
const formattedResultName = this.config.hooks.onFormatTypeName(formattedName, name$1, schemaType) || formattedName;
|
|
2510
|
+
const formattedName = startCase(`${typePrefix}_${this.fixModelName(name, { type: schemaType })}_${typeSuffix}`).replace(/\s/g, "");
|
|
2511
|
+
const formattedResultName = this.config.hooks.onFormatTypeName(formattedName, name, schemaType) || formattedName;
|
|
2520
2512
|
this.formattedModelNamesMap.set(hashKey, formattedResultName);
|
|
2521
2513
|
return formattedResultName;
|
|
2522
2514
|
};
|
|
2523
|
-
isValidName = (name
|
|
2524
|
-
fixModelName = (name
|
|
2525
|
-
if (!this.isValidName(name
|
|
2526
|
-
if (!/^[a-zA-Z_$]/g.test(name
|
|
2527
|
-
if (name
|
|
2528
|
-
if (name
|
|
2515
|
+
isValidName = (name) => /^([A-Za-z$_]{1,})$/g.test(name);
|
|
2516
|
+
fixModelName = (name, options) => {
|
|
2517
|
+
if (!this.isValidName(name)) {
|
|
2518
|
+
if (!/^[a-zA-Z_$]/g.test(name)) return `${options.type === "enum-key" ? this.config.fixInvalidEnumKeyPrefix : this.config.fixInvalidTypeNamePrefix} ${name}`;
|
|
2519
|
+
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(/__+$/, "");
|
|
2520
|
+
if (name.includes("-")) return startCase(name).replace(/ /g, "");
|
|
2529
2521
|
}
|
|
2530
|
-
return name
|
|
2522
|
+
return name;
|
|
2531
2523
|
};
|
|
2532
2524
|
};
|
|
2533
2525
|
|
|
2534
2526
|
//#endregion
|
|
2535
2527
|
//#region src/util/file-system.ts
|
|
2536
2528
|
var FileSystem = class {
|
|
2537
|
-
getFileContent = (path
|
|
2538
|
-
return fs.readFileSync(path
|
|
2529
|
+
getFileContent = (path) => {
|
|
2530
|
+
return fs.readFileSync(path, { encoding: "utf8" });
|
|
2539
2531
|
};
|
|
2540
|
-
readDir = (path
|
|
2541
|
-
return fs.readdirSync(path
|
|
2532
|
+
readDir = (path) => {
|
|
2533
|
+
return fs.readdirSync(path);
|
|
2542
2534
|
};
|
|
2543
|
-
pathIsDir = (path
|
|
2544
|
-
if (!path
|
|
2535
|
+
pathIsDir = (path) => {
|
|
2536
|
+
if (!path) return false;
|
|
2545
2537
|
try {
|
|
2546
|
-
return fs.statSync(path
|
|
2538
|
+
return fs.statSync(path).isDirectory();
|
|
2547
2539
|
} catch (e) {
|
|
2548
2540
|
return false;
|
|
2549
2541
|
}
|
|
@@ -2553,36 +2545,45 @@ var FileSystem = class {
|
|
|
2553
2545
|
if (fileNameParts.length > 1) fileNameParts.pop();
|
|
2554
2546
|
return fileNameParts.join(".");
|
|
2555
2547
|
};
|
|
2556
|
-
removeDir = (path
|
|
2548
|
+
removeDir = (path) => {
|
|
2557
2549
|
try {
|
|
2558
|
-
if (typeof fs.rmSync === "function") fs.rmSync(path
|
|
2559
|
-
else fs.rmdirSync(path
|
|
2550
|
+
if (typeof fs.rmSync === "function") fs.rmSync(path, { recursive: true });
|
|
2551
|
+
else fs.rmdirSync(path, { recursive: true });
|
|
2560
2552
|
} catch (e) {
|
|
2561
2553
|
consola.debug("failed to remove dir", e);
|
|
2562
2554
|
}
|
|
2563
2555
|
};
|
|
2564
|
-
createDir = (path
|
|
2556
|
+
createDir = (path) => {
|
|
2565
2557
|
try {
|
|
2566
|
-
fs.mkdirSync(path
|
|
2558
|
+
fs.mkdirSync(path, { recursive: true });
|
|
2567
2559
|
} catch (e) {
|
|
2568
2560
|
consola.debug("failed to create dir", e);
|
|
2569
2561
|
}
|
|
2570
2562
|
};
|
|
2571
|
-
cleanDir = (path
|
|
2572
|
-
this.removeDir(path
|
|
2573
|
-
this.createDir(path
|
|
2563
|
+
cleanDir = (path) => {
|
|
2564
|
+
this.removeDir(path);
|
|
2565
|
+
this.createDir(path);
|
|
2574
2566
|
};
|
|
2575
|
-
pathIsExist = (path
|
|
2576
|
-
return !!path
|
|
2567
|
+
pathIsExist = (path) => {
|
|
2568
|
+
return !!path && fs.existsSync(path);
|
|
2577
2569
|
};
|
|
2578
2570
|
createFile = ({ path: path_, fileName, content, withPrefix }) => {
|
|
2579
|
-
const __dirname
|
|
2580
|
-
const absolutePath = path$1.resolve(__dirname
|
|
2571
|
+
const __dirname = path$1.dirname(url$1.fileURLToPath(import.meta.url));
|
|
2572
|
+
const absolutePath = path$1.resolve(__dirname, path_, `./${fileName}`);
|
|
2581
2573
|
const fileContent = `${withPrefix ? FILE_PREFIX : ""}${content}`;
|
|
2582
2574
|
return fs.writeFileSync(absolutePath, fileContent);
|
|
2583
2575
|
};
|
|
2584
2576
|
};
|
|
2585
2577
|
|
|
2578
|
+
//#endregion
|
|
2579
|
+
//#region src/util/lodash-compat.ts
|
|
2580
|
+
function createLodashCompat() {
|
|
2581
|
+
return {
|
|
2582
|
+
...esToolkit,
|
|
2583
|
+
...esToolkitCompat
|
|
2584
|
+
};
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2586
2587
|
//#endregion
|
|
2587
2588
|
//#region src/code-gen-process.ts
|
|
2588
2589
|
const PATCHABLE_INSTANCES = [
|
|
@@ -2637,16 +2638,14 @@ var CodeGenProcess = class {
|
|
|
2637
2638
|
if (this.config.swaggerSchema) swagger.usageSchema = this.config.swaggerSchema;
|
|
2638
2639
|
if (this.config.originalSchema) swagger.originalSchema = this.config.originalSchema;
|
|
2639
2640
|
this.schemaComponentsMap.clear();
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
]), rawTypeData);
|
|
2646
|
-
}));
|
|
2641
|
+
for (const [componentName, component] of Object.entries(swagger.usageSchema.components || {})) for (const [typeName, rawTypeData] of Object.entries(component)) this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef([
|
|
2642
|
+
"components",
|
|
2643
|
+
componentName,
|
|
2644
|
+
typeName
|
|
2645
|
+
]), rawTypeData);
|
|
2647
2646
|
this.schemaComponentsMap.discriminatorsFirst();
|
|
2648
2647
|
this.schemaComponentsMap.enumsFirst();
|
|
2649
|
-
const parsedSchemas = this.schemaComponentsMap.filter(
|
|
2648
|
+
const parsedSchemas = this.schemaComponentsMap.filter(compact(["schemas", this.config.extractResponses && "responses"])).map((schemaComponent) => {
|
|
2650
2649
|
const parsed = this.schemaParserFabric.parseSchema(schemaComponent.rawTypeData, schemaComponent.typeName);
|
|
2651
2650
|
schemaComponent.typeData = parsed;
|
|
2652
2651
|
return parsed;
|
|
@@ -2704,7 +2703,7 @@ var CodeGenProcess = class {
|
|
|
2704
2703
|
utils: {
|
|
2705
2704
|
Ts: this.config.Ts,
|
|
2706
2705
|
formatDescription: this.schemaParserFabric.schemaFormatters.formatDescription,
|
|
2707
|
-
internalCase,
|
|
2706
|
+
internalCase: camelCase,
|
|
2708
2707
|
classNameCase: pascalCase,
|
|
2709
2708
|
pascalCase,
|
|
2710
2709
|
getInlineParseContent: this.schemaParserFabric.getInlineParseContent,
|
|
@@ -2721,7 +2720,7 @@ var CodeGenProcess = class {
|
|
|
2721
2720
|
return ` * ${line}${eol ? "\n" : ""}`;
|
|
2722
2721
|
},
|
|
2723
2722
|
NameResolver,
|
|
2724
|
-
_:
|
|
2723
|
+
_: createLodashCompat(),
|
|
2725
2724
|
require: this.templatesWorker.requireFnFromTemplate
|
|
2726
2725
|
},
|
|
2727
2726
|
config: this.config
|
|
@@ -2730,7 +2729,7 @@ var CodeGenProcess = class {
|
|
|
2730
2729
|
collectModelTypes = () => {
|
|
2731
2730
|
const components = this.schemaComponentsMap.getComponents();
|
|
2732
2731
|
let modelTypes = [];
|
|
2733
|
-
const modelTypeComponents =
|
|
2732
|
+
const modelTypeComponents = compact(["schemas", this.config.extractResponses && "responses"]);
|
|
2734
2733
|
const getSchemaComponentsCount = () => this.schemaComponentsMap.filter(...modelTypeComponents).length;
|
|
2735
2734
|
let schemaComponentsCount = getSchemaComponentsCount();
|
|
2736
2735
|
let processedCount = 0;
|
|
@@ -2752,14 +2751,14 @@ var CodeGenProcess = class {
|
|
|
2752
2751
|
if (!typeInfo.typeData) typeInfo.typeData = this.schemaParserFabric.parseSchema(typeInfo.rawTypeData, typeInfo.typeName);
|
|
2753
2752
|
const rawTypeData = typeInfo.typeData;
|
|
2754
2753
|
const typeData = this.schemaParserFabric.schemaFormatters.base[rawTypeData.type] ? this.schemaParserFabric.schemaFormatters.base[rawTypeData.type](rawTypeData) : rawTypeData;
|
|
2755
|
-
const { typeIdentifier, name: originalName, content, description
|
|
2756
|
-
const name
|
|
2757
|
-
if (name
|
|
2754
|
+
const { typeIdentifier, name: originalName, content, description } = typeData;
|
|
2755
|
+
const name = this.typeNameFormatter.format(originalName);
|
|
2756
|
+
if (name === null) return null;
|
|
2758
2757
|
const preparedModelType = {
|
|
2759
2758
|
...typeData,
|
|
2760
2759
|
typeIdentifier,
|
|
2761
|
-
name
|
|
2762
|
-
description
|
|
2760
|
+
name,
|
|
2761
|
+
description,
|
|
2763
2762
|
$content: rawTypeData.content,
|
|
2764
2763
|
rawContent: rawTypeData.content,
|
|
2765
2764
|
content,
|
|
@@ -2771,7 +2770,7 @@ var CodeGenProcess = class {
|
|
|
2771
2770
|
generateOutputFiles = async ({ configuration }) => {
|
|
2772
2771
|
const { modular, templatesToRender } = this.config;
|
|
2773
2772
|
const output = modular ? await this.createMultipleFileInfos(templatesToRender, configuration) : await this.createSingleFileInfo(templatesToRender, configuration);
|
|
2774
|
-
if (
|
|
2773
|
+
if (configuration.extraTemplates?.length) for (const extraTemplate of configuration.extraTemplates) {
|
|
2775
2774
|
const content = this.templatesWorker.renderTemplate(this.fileSystem.getFileContent(extraTemplate.path), configuration);
|
|
2776
2775
|
output.push(...await this.createOutputFileInfo(configuration, extraTemplate.name, content));
|
|
2777
2776
|
}
|
|
@@ -2821,7 +2820,7 @@ var CodeGenProcess = class {
|
|
|
2821
2820
|
};
|
|
2822
2821
|
createSingleFileInfo = async (templatesToRender, configuration) => {
|
|
2823
2822
|
const { generateRouteTypes, generateClient } = configuration.config;
|
|
2824
|
-
return await this.createOutputFileInfo(configuration, configuration.fileName,
|
|
2823
|
+
return await this.createOutputFileInfo(configuration, configuration.fileName, compact([
|
|
2825
2824
|
this.templatesWorker.renderTemplate(templatesToRender.dataContracts, configuration),
|
|
2826
2825
|
generateRouteTypes && this.templatesWorker.renderTemplate(templatesToRender.routeTypes, configuration),
|
|
2827
2826
|
generateClient && this.templatesWorker.renderTemplate(templatesToRender.httpClient, configuration),
|
|
@@ -2857,21 +2856,21 @@ var CodeGenProcess = class {
|
|
|
2857
2856
|
createApiConfig = (swaggerSchema) => {
|
|
2858
2857
|
const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
|
|
2859
2858
|
const server = servers?.[0] || { url: "" };
|
|
2860
|
-
const { title = "No title", version
|
|
2859
|
+
const { title = "No title", version } = info || {};
|
|
2861
2860
|
const { url: serverUrl } = server;
|
|
2862
2861
|
return {
|
|
2863
2862
|
info: info || {},
|
|
2864
2863
|
servers: servers || [],
|
|
2865
2864
|
basePath,
|
|
2866
2865
|
host,
|
|
2867
|
-
externalDocs:
|
|
2866
|
+
externalDocs: merge({
|
|
2868
2867
|
url: "",
|
|
2869
2868
|
description: ""
|
|
2870
|
-
}, externalDocs),
|
|
2871
|
-
tags:
|
|
2869
|
+
}, externalDocs || {}),
|
|
2870
|
+
tags: compact(tags || []),
|
|
2872
2871
|
baseUrl: serverUrl,
|
|
2873
2872
|
title,
|
|
2874
|
-
version
|
|
2873
|
+
version
|
|
2875
2874
|
};
|
|
2876
2875
|
};
|
|
2877
2876
|
injectClassInstance = (key, value) => {
|
|
@@ -2882,28 +2881,28 @@ var CodeGenProcess = class {
|
|
|
2882
2881
|
|
|
2883
2882
|
//#endregion
|
|
2884
2883
|
//#region types/index.ts
|
|
2885
|
-
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind
|
|
2886
|
-
RequestContentKind
|
|
2887
|
-
RequestContentKind
|
|
2888
|
-
RequestContentKind
|
|
2889
|
-
RequestContentKind
|
|
2890
|
-
RequestContentKind
|
|
2891
|
-
RequestContentKind
|
|
2892
|
-
return RequestContentKind
|
|
2884
|
+
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind) {
|
|
2885
|
+
RequestContentKind["JSON"] = "JSON";
|
|
2886
|
+
RequestContentKind["URL_ENCODED"] = "URL_ENCODED";
|
|
2887
|
+
RequestContentKind["FORM_DATA"] = "FORM_DATA";
|
|
2888
|
+
RequestContentKind["IMAGE"] = "IMAGE";
|
|
2889
|
+
RequestContentKind["OTHER"] = "OTHER";
|
|
2890
|
+
RequestContentKind["TEXT"] = "TEXT";
|
|
2891
|
+
return RequestContentKind;
|
|
2893
2892
|
}({});
|
|
2894
|
-
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES
|
|
2895
|
-
SCHEMA_TYPES
|
|
2896
|
-
SCHEMA_TYPES
|
|
2897
|
-
SCHEMA_TYPES
|
|
2898
|
-
SCHEMA_TYPES
|
|
2899
|
-
SCHEMA_TYPES
|
|
2900
|
-
SCHEMA_TYPES
|
|
2901
|
-
SCHEMA_TYPES
|
|
2902
|
-
SCHEMA_TYPES
|
|
2903
|
-
SCHEMA_TYPES
|
|
2904
|
-
SCHEMA_TYPES
|
|
2905
|
-
SCHEMA_TYPES
|
|
2906
|
-
return SCHEMA_TYPES
|
|
2893
|
+
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES) {
|
|
2894
|
+
SCHEMA_TYPES["ARRAY"] = "array";
|
|
2895
|
+
SCHEMA_TYPES["OBJECT"] = "object";
|
|
2896
|
+
SCHEMA_TYPES["ENUM"] = "enum";
|
|
2897
|
+
SCHEMA_TYPES["REF"] = "$ref";
|
|
2898
|
+
SCHEMA_TYPES["PRIMITIVE"] = "primitive";
|
|
2899
|
+
SCHEMA_TYPES["COMPLEX"] = "complex";
|
|
2900
|
+
SCHEMA_TYPES["COMPLEX_ONE_OF"] = "oneOf";
|
|
2901
|
+
SCHEMA_TYPES["COMPLEX_ANY_OF"] = "anyOf";
|
|
2902
|
+
SCHEMA_TYPES["COMPLEX_ALL_OF"] = "allOf";
|
|
2903
|
+
SCHEMA_TYPES["COMPLEX_NOT"] = "not";
|
|
2904
|
+
SCHEMA_TYPES["COMPLEX_UNKNOWN"] = "__unknown";
|
|
2905
|
+
return SCHEMA_TYPES;
|
|
2907
2906
|
}({});
|
|
2908
2907
|
|
|
2909
2908
|
//#endregion
|
|
@@ -2921,7 +2920,7 @@ var TemplatesGenConfig = class {
|
|
|
2921
2920
|
this.update(config);
|
|
2922
2921
|
}
|
|
2923
2922
|
update = (update) => {
|
|
2924
|
-
|
|
2923
|
+
Object.assign(this, update);
|
|
2925
2924
|
};
|
|
2926
2925
|
};
|
|
2927
2926
|
|
|
@@ -3036,13 +3035,5 @@ async function generateTemplates(config) {
|
|
|
3036
3035
|
}
|
|
3037
3036
|
|
|
3038
3037
|
//#endregion
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
if (config.debug) consola.level = Number.MAX_SAFE_INTEGER;
|
|
3042
|
-
if (config.silent) consola.level = 0;
|
|
3043
|
-
return await new CodeGenProcess(config).start();
|
|
3044
|
-
}
|
|
3045
|
-
|
|
3046
|
-
//#endregion
|
|
3047
|
-
export { SCHEMA_TYPES as a, constants_exports as c, version as d, RequestContentKind as i, description as l, generateTemplates as n, CodeGenConfig as o, TemplatesGenConfig as r, HTTP_CLIENT as s, generateApi as t, name as u };
|
|
3048
|
-
//# sourceMappingURL=src-D-LZ3PGk.js.map
|
|
3038
|
+
export { CodeGenProcess as a, constants_exports as c, version as d, SCHEMA_TYPES as i, description as l, TemplatesGenConfig as n, CodeGenConfig as o, RequestContentKind as r, HTTP_CLIENT as s, generateTemplates as t, name as u };
|
|
3039
|
+
//# sourceMappingURL=generate-templates-BO-5CKCm.mjs.map
|