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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __export } from "./chunk-
|
|
1
|
+
import { __export } from "./chunk-CTAAG5j7.js";
|
|
2
2
|
import * as module from "node:module";
|
|
3
3
|
import { consola } from "consola";
|
|
4
4
|
import lodash from "lodash";
|
|
@@ -11,7 +11,7 @@ import * as yaml from "js-yaml";
|
|
|
11
11
|
import * as swagger2openapi from "swagger2openapi";
|
|
12
12
|
import * as url$1 from "node:url";
|
|
13
13
|
import url from "node:url";
|
|
14
|
-
import
|
|
14
|
+
import { Eta } from "eta";
|
|
15
15
|
import * as fs from "node:fs";
|
|
16
16
|
|
|
17
17
|
//#region src/code-formatter.ts
|
|
@@ -23,8 +23,7 @@ var CodeFormatter = class {
|
|
|
23
23
|
removeUnusedImports = (content) => {
|
|
24
24
|
const tempFileName = "file.ts";
|
|
25
25
|
const host = new TsLanguageServiceHost(tempFileName, content);
|
|
26
|
-
const
|
|
27
|
-
const fileTextChanges = languageService.organizeImports({
|
|
26
|
+
const fileTextChanges = typescript.createLanguageService(host).organizeImports({
|
|
28
27
|
type: "file",
|
|
29
28
|
fileName: tempFileName
|
|
30
29
|
}, { newLineCharacter: typescript.sys.newLine }, void 0)[0];
|
|
@@ -38,11 +37,10 @@ var CodeFormatter = class {
|
|
|
38
37
|
files: { maxSize: Number.MAX_SAFE_INTEGER },
|
|
39
38
|
formatter: { indentStyle: "space" }
|
|
40
39
|
});
|
|
41
|
-
|
|
40
|
+
return biome.formatContent(biomeProject.projectKey, content, { filePath: path$1.format({
|
|
42
41
|
name: nanoid.nanoid(),
|
|
43
42
|
ext: "ts"
|
|
44
|
-
}) });
|
|
45
|
-
return formatted.content;
|
|
43
|
+
}) }).content;
|
|
46
44
|
};
|
|
47
45
|
formatCode = async (code, { removeUnusedImports = true, format = true } = {}) => {
|
|
48
46
|
if (removeUnusedImports) code = this.removeUnusedImports(code);
|
|
@@ -178,7 +176,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
178
176
|
//#endregion
|
|
179
177
|
//#region package.json
|
|
180
178
|
var name = "swagger-typescript-api";
|
|
181
|
-
var version = "13.2.
|
|
179
|
+
var version = "13.2.11";
|
|
182
180
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
183
181
|
var homepage = "https://github.com/acacode/swagger-typescript-api";
|
|
184
182
|
var bugs = "https://github.com/acacode/swagger-typescript-api/issues";
|
|
@@ -219,12 +217,12 @@ var scripts = {
|
|
|
219
217
|
};
|
|
220
218
|
var dependencies = {
|
|
221
219
|
"@biomejs/js-api": "3.0.0",
|
|
222
|
-
"@biomejs/wasm-nodejs": "2.2.
|
|
220
|
+
"@biomejs/wasm-nodejs": "2.2.4",
|
|
223
221
|
"@types/swagger-schema-official": "^2.0.25",
|
|
224
|
-
"c12": "^3.
|
|
222
|
+
"c12": "^3.3.0",
|
|
225
223
|
"citty": "^0.1.6",
|
|
226
224
|
"consola": "^3.4.2",
|
|
227
|
-
"eta": "^
|
|
225
|
+
"eta": "^4.0.1",
|
|
228
226
|
"js-yaml": "^4.1.0",
|
|
229
227
|
"lodash": "^4.17.21",
|
|
230
228
|
"nanoid": "^5.1.5",
|
|
@@ -233,19 +231,19 @@ var dependencies = {
|
|
|
233
231
|
"typescript": "~5.9.2"
|
|
234
232
|
};
|
|
235
233
|
var devDependencies = {
|
|
236
|
-
"@biomejs/biome": "2.2.
|
|
234
|
+
"@biomejs/biome": "2.2.4",
|
|
237
235
|
"@changesets/changelog-github": "0.5.1",
|
|
238
|
-
"@changesets/cli": "2.29.
|
|
239
|
-
"@tsconfig/
|
|
236
|
+
"@changesets/cli": "2.29.7",
|
|
237
|
+
"@tsconfig/node20": "20.1.6",
|
|
240
238
|
"@tsconfig/strictest": "2.0.5",
|
|
241
239
|
"@types/js-yaml": "4.0.9",
|
|
242
240
|
"@types/lodash": "4.17.20",
|
|
243
|
-
"@types/node": "24.
|
|
241
|
+
"@types/node": "24.5.2",
|
|
244
242
|
"@types/swagger2openapi": "7.0.4",
|
|
245
|
-
"axios": "1.
|
|
243
|
+
"axios": "1.12.2",
|
|
246
244
|
"openapi-types": "12.1.3",
|
|
247
|
-
"tsdown": "0.
|
|
248
|
-
"typedoc": "0.28.
|
|
245
|
+
"tsdown": "0.15.2",
|
|
246
|
+
"typedoc": "0.28.13",
|
|
249
247
|
"vitest": "3.2.4"
|
|
250
248
|
};
|
|
251
249
|
var packageManager = "yarn@4.9.4";
|
|
@@ -287,8 +285,7 @@ var package_default = {
|
|
|
287
285
|
|
|
288
286
|
//#endregion
|
|
289
287
|
//#region src/constants.ts
|
|
290
|
-
var constants_exports = {
|
|
291
|
-
__export(constants_exports, {
|
|
288
|
+
var constants_exports = /* @__PURE__ */ __export({
|
|
292
289
|
DEFAULT_BODY_ARG_NAME: () => DEFAULT_BODY_ARG_NAME,
|
|
293
290
|
FILE_PREFIX: () => FILE_PREFIX,
|
|
294
291
|
HTTP_CLIENT: () => HTTP_CLIENT,
|
|
@@ -298,7 +295,7 @@ __export(constants_exports, {
|
|
|
298
295
|
RESERVED_PATH_ARG_NAMES: () => RESERVED_PATH_ARG_NAMES,
|
|
299
296
|
RESERVED_QUERY_ARG_NAMES: () => RESERVED_QUERY_ARG_NAMES,
|
|
300
297
|
RESERVED_REQ_PARAMS_ARG_NAMES: () => RESERVED_REQ_PARAMS_ARG_NAMES,
|
|
301
|
-
SCHEMA_TYPES: () => SCHEMA_TYPES
|
|
298
|
+
SCHEMA_TYPES: () => SCHEMA_TYPES$1
|
|
302
299
|
});
|
|
303
300
|
const DEFAULT_BODY_ARG_NAME = "data";
|
|
304
301
|
const FILE_PREFIX = `/* eslint-disable */
|
|
@@ -337,7 +334,7 @@ const RESERVED_REQ_PARAMS_ARG_NAMES = [
|
|
|
337
334
|
"reqParams",
|
|
338
335
|
"httpParams"
|
|
339
336
|
];
|
|
340
|
-
const SCHEMA_TYPES = {
|
|
337
|
+
const SCHEMA_TYPES$1 = {
|
|
341
338
|
ARRAY: "array",
|
|
342
339
|
OBJECT: "object",
|
|
343
340
|
ENUM: "enum",
|
|
@@ -738,9 +735,9 @@ var SchemaComponentsMap = class {
|
|
|
738
735
|
filter(...componentNames) {
|
|
739
736
|
return this._data.filter((it) => componentNames.some((componentName) => it.$ref.startsWith(`#/components/${componentName}`)));
|
|
740
737
|
}
|
|
741
|
-
get($ref) {
|
|
738
|
+
get = ($ref) => {
|
|
742
739
|
return this._data.find((c) => c.$ref === $ref) || null;
|
|
743
|
-
}
|
|
740
|
+
};
|
|
744
741
|
enumsFirst() {
|
|
745
742
|
this._data.sort((a, b) => {
|
|
746
743
|
if (Object.keys(a.rawTypeData || {}).includes("enum")) return -1;
|
|
@@ -748,6 +745,13 @@ var SchemaComponentsMap = class {
|
|
|
748
745
|
return 0;
|
|
749
746
|
});
|
|
750
747
|
}
|
|
748
|
+
discriminatorsFirst() {
|
|
749
|
+
this._data.sort((a, b) => {
|
|
750
|
+
if (Object.keys(a.rawTypeData || {}).includes("discriminator")) return -1;
|
|
751
|
+
if (Object.keys(b.rawTypeData || {}).includes("discriminator")) return 1;
|
|
752
|
+
return 0;
|
|
753
|
+
});
|
|
754
|
+
}
|
|
751
755
|
};
|
|
752
756
|
|
|
753
757
|
//#endregion
|
|
@@ -762,7 +766,7 @@ var SchemaFormatters = class {
|
|
|
762
766
|
this.templatesWorker = schemaParser.templatesWorker;
|
|
763
767
|
}
|
|
764
768
|
base = {
|
|
765
|
-
[SCHEMA_TYPES.ENUM]: (parsedSchema) => {
|
|
769
|
+
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
766
770
|
if (this.config.generateUnionEnums) return {
|
|
767
771
|
...parsedSchema,
|
|
768
772
|
$content: parsedSchema.content,
|
|
@@ -774,15 +778,15 @@ var SchemaFormatters = class {
|
|
|
774
778
|
content: this.config.Ts.EnumFieldsWrapper(parsedSchema.content)
|
|
775
779
|
};
|
|
776
780
|
},
|
|
777
|
-
[SCHEMA_TYPES.OBJECT]: (parsedSchema) => {
|
|
778
|
-
if (parsedSchema.nullable) return this.inline[SCHEMA_TYPES.OBJECT](parsedSchema);
|
|
781
|
+
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
782
|
+
if (parsedSchema.nullable) return this.inline[SCHEMA_TYPES$1.OBJECT](parsedSchema);
|
|
779
783
|
return {
|
|
780
784
|
...parsedSchema,
|
|
781
785
|
$content: parsedSchema.content,
|
|
782
786
|
content: this.formatObjectContent(parsedSchema.content)
|
|
783
787
|
};
|
|
784
788
|
},
|
|
785
|
-
[SCHEMA_TYPES.PRIMITIVE]: (parsedSchema) => {
|
|
789
|
+
[SCHEMA_TYPES$1.PRIMITIVE]: (parsedSchema) => {
|
|
786
790
|
return {
|
|
787
791
|
...parsedSchema,
|
|
788
792
|
$content: parsedSchema.content
|
|
@@ -790,13 +794,13 @@ var SchemaFormatters = class {
|
|
|
790
794
|
}
|
|
791
795
|
};
|
|
792
796
|
inline = {
|
|
793
|
-
[SCHEMA_TYPES.ENUM]: (parsedSchema) => {
|
|
797
|
+
[SCHEMA_TYPES$1.ENUM]: (parsedSchema) => {
|
|
794
798
|
return {
|
|
795
799
|
...parsedSchema,
|
|
796
800
|
content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType(lodash.compact([...parsedSchema.content.map(({ value }) => `${value}`), parsedSchema.nullable && this.config.Ts.Keyword.Null])) || this.config.Ts.Keyword.Any
|
|
797
801
|
};
|
|
798
802
|
},
|
|
799
|
-
[SCHEMA_TYPES.OBJECT]: (parsedSchema) => {
|
|
803
|
+
[SCHEMA_TYPES$1.OBJECT]: (parsedSchema) => {
|
|
800
804
|
if (typeof parsedSchema.content === "string") return {
|
|
801
805
|
...parsedSchema,
|
|
802
806
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
@@ -811,13 +815,11 @@ var SchemaFormatters = class {
|
|
|
811
815
|
};
|
|
812
816
|
formatSchema = (parsedSchema, formatType = "base") => {
|
|
813
817
|
const schemaType = lodash.get(parsedSchema, ["schemaType"]) || lodash.get(parsedSchema, ["$parsed", "schemaType"]);
|
|
814
|
-
|
|
815
|
-
return formatterFn?.(parsedSchema) || parsedSchema;
|
|
818
|
+
return lodash.get(this, [formatType, schemaType])?.(parsedSchema) || parsedSchema;
|
|
816
819
|
};
|
|
817
820
|
formatDescription = (description$1, inline) => {
|
|
818
821
|
if (!description$1) return "";
|
|
819
|
-
|
|
820
|
-
if (!hasMultipleLines) return description$1;
|
|
822
|
+
if (!description$1.includes("\n")) return description$1;
|
|
821
823
|
if (inline) return lodash._(description$1).split(/\n/g).map((part) => part.trim()).compact().join(" ").valueOf();
|
|
822
824
|
return description$1.replace(/\n$/g, "");
|
|
823
825
|
};
|
|
@@ -826,8 +828,7 @@ var SchemaFormatters = class {
|
|
|
826
828
|
for (const part of content) {
|
|
827
829
|
const extraSpace = " ";
|
|
828
830
|
const result = `${extraSpace}${part.field},\n`;
|
|
829
|
-
const
|
|
830
|
-
const routeNameFromTemplate = renderedJsDoc.split("\n").map((c) => `${extraSpace}${c}`).join("\n");
|
|
831
|
+
const routeNameFromTemplate = this.templatesWorker.renderTemplate(this.config.templatesToRender.dataContractJsDoc, { data: part }).split("\n").map((c) => `${extraSpace}${c}`).join("\n");
|
|
831
832
|
if (routeNameFromTemplate) fields.push(`${routeNameFromTemplate}${result}`);
|
|
832
833
|
else fields.push(`${result}`);
|
|
833
834
|
}
|
|
@@ -882,7 +883,7 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
882
883
|
parse() {
|
|
883
884
|
let contentType;
|
|
884
885
|
const { type: type$1, description: description$1, items } = this.schema || {};
|
|
885
|
-
if (Array.isArray(items) && type$1 === SCHEMA_TYPES.ARRAY) {
|
|
886
|
+
if (Array.isArray(items) && type$1 === SCHEMA_TYPES$1.ARRAY) {
|
|
886
887
|
const tupleContent = [];
|
|
887
888
|
for (const item of items) tupleContent.push(this.schemaParserFabric.createSchemaParser({
|
|
888
889
|
schema: item,
|
|
@@ -900,8 +901,8 @@ var ArraySchemaParser = class extends MonoSchemaParser {
|
|
|
900
901
|
...typeof this.schema === "object" ? this.schema : {},
|
|
901
902
|
$schemaPath: this.schemaPath.slice(),
|
|
902
903
|
$parsedSchema: true,
|
|
903
|
-
schemaType: SCHEMA_TYPES.PRIMITIVE,
|
|
904
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
904
|
+
schemaType: SCHEMA_TYPES$1.PRIMITIVE,
|
|
905
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
905
906
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
906
907
|
name: this.typeName,
|
|
907
908
|
description: this.schemaFormatters.formatDescription(description$1),
|
|
@@ -921,12 +922,12 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
|
|
|
921
922
|
...typeof this.schema === "object" ? this.schema : {},
|
|
922
923
|
$schemaPath: this.schemaPath.slice(),
|
|
923
924
|
$parsedSchema: true,
|
|
924
|
-
schemaType: SCHEMA_TYPES.COMPLEX,
|
|
925
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
925
|
+
schemaType: SCHEMA_TYPES$1.COMPLEX,
|
|
926
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
926
927
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
927
928
|
name: this.typeName,
|
|
928
929
|
description: this.schemaFormatters.formatDescription(this.schema.description || lodash.compact(lodash.map(this.schema[complexType], "description"))[0] || ""),
|
|
929
|
-
content: this.config.Ts.IntersectionType(lodash.compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
930
|
+
content: this.config.Ts.IntersectionType(lodash.compact([this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES$1.OBJECT && this.config.Ts.ExpressionGroup(this.schemaParserFabric.createSchemaParser({
|
|
930
931
|
schema: simpleSchema,
|
|
931
932
|
schemaPath: this.schemaPath
|
|
932
933
|
}).getInlineParseContent())])) || this.config.Ts.Keyword.Any
|
|
@@ -956,8 +957,8 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
956
957
|
...typeof this.schema === "object" ? this.schema : {},
|
|
957
958
|
$schemaPath: this.schemaPath.slice(),
|
|
958
959
|
$parsedSchema: true,
|
|
959
|
-
schemaType: SCHEMA_TYPES.COMPLEX,
|
|
960
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
960
|
+
schemaType: SCHEMA_TYPES$1.COMPLEX,
|
|
961
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
961
962
|
typeIdentifier: ts.Keyword.Type,
|
|
962
963
|
name: this.typeName,
|
|
963
964
|
description: this.schemaFormatters.formatDescription(this.schema.description),
|
|
@@ -987,7 +988,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
987
988
|
suffixes: this.config.extractingOptions.discriminatorMappingSuffix,
|
|
988
989
|
resolver: this.config.extractingOptions.discriminatorMappingNameResolver
|
|
989
990
|
});
|
|
990
|
-
const content
|
|
991
|
+
const content = ts.IntersectionType([ts.ObjectWrapper(ts.TypeField({
|
|
991
992
|
key: ts.StringValue(discriminator.propertyName),
|
|
992
993
|
value: "Key"
|
|
993
994
|
})), "Type"]);
|
|
@@ -1000,21 +1001,21 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1000
1001
|
internal: true
|
|
1001
1002
|
}
|
|
1002
1003
|
});
|
|
1003
|
-
component.typeData.content = content
|
|
1004
|
+
component.typeData.content = content;
|
|
1004
1005
|
mappingTypeName = this.typeNameFormatter.format(component.typeName);
|
|
1005
1006
|
}
|
|
1006
1007
|
/** returns (GenericType<"mapping_key", MappingType>) or ({ discriminatorProperty: "mapping_key" } & MappingType) */
|
|
1007
1008
|
const createMappingContent = (mappingSchema, mappingKey) => {
|
|
1008
|
-
const content
|
|
1009
|
+
const content = this.schemaParserFabric.createSchemaParser({
|
|
1009
1010
|
schema: mappingSchema,
|
|
1010
1011
|
schemaPath: this.schemaPath
|
|
1011
1012
|
}).getInlineParseContent();
|
|
1012
1013
|
const mappingUsageKey = mappingPropertySchemaEnumKeysMap[mappingKey] || ts.StringValue(mappingKey);
|
|
1013
|
-
if (ableToCreateMappingType) return ts.TypeWithGeneric(mappingTypeName, [mappingUsageKey, content
|
|
1014
|
+
if (ableToCreateMappingType) return ts.TypeWithGeneric(mappingTypeName, [mappingUsageKey, content]);
|
|
1014
1015
|
return ts.ExpressionGroup(ts.IntersectionType([ts.ObjectWrapper(ts.TypeField({
|
|
1015
1016
|
key: discriminator.propertyName,
|
|
1016
1017
|
value: mappingUsageKey
|
|
1017
|
-
})), content
|
|
1018
|
+
})), content]));
|
|
1018
1019
|
};
|
|
1019
1020
|
for (const [mappingKey, schema] of mappingEntries) {
|
|
1020
1021
|
const mappingSchema = typeof schema === "string" ? { $ref: schema } : schema;
|
|
@@ -1028,15 +1029,14 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1028
1029
|
mappingContents.push(createMappingContent(mappingSchema, mappingKey));
|
|
1029
1030
|
}
|
|
1030
1031
|
if (skipMappingType) return null;
|
|
1031
|
-
|
|
1032
|
-
return { content };
|
|
1032
|
+
return { content: ts.ExpressionGroup(ts.UnionType(mappingContents)) };
|
|
1033
1033
|
};
|
|
1034
1034
|
createMappingPropertySchemaEnumKeys = ({ abstractSchemaStruct, discPropertyName }) => {
|
|
1035
1035
|
const ts = this.config.Ts;
|
|
1036
1036
|
let mappingPropertySchemaEnumKeysMap = {};
|
|
1037
1037
|
let mappingPropertySchema = lodash.get(abstractSchemaStruct?.component?.rawTypeData, ["properties", discPropertyName]);
|
|
1038
1038
|
if (this.schemaUtils.isRefSchema(mappingPropertySchema)) mappingPropertySchema = this.schemaUtils.getSchemaRefType(mappingPropertySchema);
|
|
1039
|
-
if (mappingPropertySchema?.rawTypeData?.$parsed?.type === SCHEMA_TYPES.ENUM) mappingPropertySchemaEnumKeysMap = lodash.reduce(mappingPropertySchema.rawTypeData.$parsed.enum, (acc, key, index) => {
|
|
1039
|
+
if (mappingPropertySchema?.rawTypeData?.$parsed?.type === SCHEMA_TYPES$1.ENUM) mappingPropertySchemaEnumKeysMap = lodash.reduce(mappingPropertySchema.rawTypeData.$parsed.enum, (acc, key, index) => {
|
|
1040
1040
|
const enumKey = mappingPropertySchema.rawTypeData.$parsed.content[index].key;
|
|
1041
1041
|
acc[key] = ts.EnumUsageKey(mappingPropertySchema.rawTypeData.$parsed.typeName, enumKey);
|
|
1042
1042
|
return acc;
|
|
@@ -1053,9 +1053,9 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1053
1053
|
...schema,
|
|
1054
1054
|
$ref: abstractSchemaStruct.component.$ref
|
|
1055
1055
|
};
|
|
1056
|
-
if (this.schemaUtils.getInternalSchemaType(schema) === SCHEMA_TYPES.OBJECT) for (const schemaPropertyName in schema.properties) {
|
|
1056
|
+
if (this.schemaUtils.getInternalSchemaType(schema) === SCHEMA_TYPES$1.OBJECT) for (const schemaPropertyName in schema.properties) {
|
|
1057
1057
|
const schemaProperty = schema.properties[schemaPropertyName];
|
|
1058
|
-
if (schemaPropertyName === discPropertyName && this.schemaUtils.getInternalSchemaType(schemaProperty) === SCHEMA_TYPES.ENUM && schemaProperty.enum.length === 1 && mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]]) schema.properties[schemaPropertyName] = this.schemaParserFabric.createSchema({ content: mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]] });
|
|
1058
|
+
if (schemaPropertyName === discPropertyName && this.schemaUtils.getInternalSchemaType(schemaProperty) === SCHEMA_TYPES$1.ENUM && schemaProperty.enum.length === 1 && mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]]) schema.properties[schemaPropertyName] = this.schemaParserFabric.createSchema({ content: mappingPropertySchemaEnumKeysMap[schemaProperty.enum[0]] });
|
|
1059
1059
|
}
|
|
1060
1060
|
return schema;
|
|
1061
1061
|
});
|
|
@@ -1067,8 +1067,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1067
1067
|
const complexSchemaKeys = lodash.keys(this.schemaParser._complexSchemaParsers);
|
|
1068
1068
|
const schema = lodash.omit(structuredClone(noDiscriminatorSchema), complexSchemaKeys);
|
|
1069
1069
|
const schemaIsAny = this.schemaParserFabric.getInlineParseContent(structuredClone(schema)) === this.config.Ts.Keyword.Any;
|
|
1070
|
-
|
|
1071
|
-
if (schemaIsEmpty || schemaIsAny) return null;
|
|
1070
|
+
if (!lodash.keys(schema).length || schemaIsAny) return null;
|
|
1072
1071
|
const typeName = this.schemaUtils.resolveTypeName(this.typeName, {
|
|
1073
1072
|
prefixes: this.config.extractingOptions.discriminatorAbstractPrefix,
|
|
1074
1073
|
resolver: this.config.extractingOptions.discriminatorAbstractResolver
|
|
@@ -1094,7 +1093,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
|
|
|
1094
1093
|
createComplexSchemaStruct = () => {
|
|
1095
1094
|
const ts = this.config.Ts;
|
|
1096
1095
|
const complexType = this.schemaUtils.getComplexType(this.schema);
|
|
1097
|
-
if (complexType === SCHEMA_TYPES.COMPLEX_UNKNOWN) return null;
|
|
1096
|
+
if (complexType === SCHEMA_TYPES$1.COMPLEX_UNKNOWN) return null;
|
|
1098
1097
|
return { content: ts.ExpressionGroup(this.schemaParser._complexSchemaParsers[complexType](this.schema)) };
|
|
1099
1098
|
};
|
|
1100
1099
|
};
|
|
@@ -1197,8 +1196,8 @@ var EnumSchemaParser = class extends MonoSchemaParser {
|
|
|
1197
1196
|
$ref,
|
|
1198
1197
|
typeName: this.typeName || $ref && refType.typeName || null,
|
|
1199
1198
|
$parsedSchema: true,
|
|
1200
|
-
schemaType: SCHEMA_TYPES.ENUM,
|
|
1201
|
-
type: SCHEMA_TYPES.ENUM,
|
|
1199
|
+
schemaType: SCHEMA_TYPES$1.ENUM,
|
|
1200
|
+
type: SCHEMA_TYPES$1.ENUM,
|
|
1202
1201
|
keyType,
|
|
1203
1202
|
typeIdentifier: this.config.generateUnionEnums ? this.config.Ts.Keyword.Type : this.config.Ts.Keyword.Enum,
|
|
1204
1203
|
name: this.typeName,
|
|
@@ -1223,8 +1222,8 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1223
1222
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1224
1223
|
$schemaPath: this.schemaPath.slice(),
|
|
1225
1224
|
$parsedSchema: true,
|
|
1226
|
-
schemaType: SCHEMA_TYPES.OBJECT,
|
|
1227
|
-
type: SCHEMA_TYPES.OBJECT,
|
|
1225
|
+
schemaType: SCHEMA_TYPES$1.OBJECT,
|
|
1226
|
+
type: SCHEMA_TYPES$1.OBJECT,
|
|
1228
1227
|
typeIdentifier: this.config.Ts.Keyword.Interface,
|
|
1229
1228
|
name: this.typeName,
|
|
1230
1229
|
description: this.schemaFormatters.formatDescription(this.schema.description),
|
|
@@ -1306,7 +1305,7 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1306
1305
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1307
1306
|
oneOf: type$1.map((type$2) => ({ type: type$2 }))
|
|
1308
1307
|
});
|
|
1309
|
-
if (Array.isArray(items) && type$1 === SCHEMA_TYPES.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1308
|
+
if (Array.isArray(items) && type$1 === SCHEMA_TYPES$1.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
|
|
1310
1309
|
schema: item,
|
|
1311
1310
|
schemaPath: this.schemaPath
|
|
1312
1311
|
}).getInlineParseContent()));
|
|
@@ -1314,8 +1313,8 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
|
|
|
1314
1313
|
...typeof this.schema === "object" ? this.schema : {},
|
|
1315
1314
|
$schemaPath: this.schemaPath.slice(),
|
|
1316
1315
|
$parsedSchema: true,
|
|
1317
|
-
schemaType: SCHEMA_TYPES.PRIMITIVE,
|
|
1318
|
-
type: SCHEMA_TYPES.PRIMITIVE,
|
|
1316
|
+
schemaType: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1317
|
+
type: SCHEMA_TYPES$1.PRIMITIVE,
|
|
1319
1318
|
typeIdentifier: this.config.Ts.Keyword.Type,
|
|
1320
1319
|
name: this.typeName,
|
|
1321
1320
|
description: this.schemaFormatters.formatDescription(description$1),
|
|
@@ -1396,67 +1395,47 @@ var SchemaParser = class {
|
|
|
1396
1395
|
this.schemaPath = [...schemaPath || []];
|
|
1397
1396
|
}
|
|
1398
1397
|
_complexSchemaParsers = {
|
|
1399
|
-
[SCHEMA_TYPES.COMPLEX_ONE_OF]: (schema) => {
|
|
1400
|
-
|
|
1401
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1402
|
-
return schemaParser.parse();
|
|
1398
|
+
[SCHEMA_TYPES$1.COMPLEX_ONE_OF]: (schema) => {
|
|
1399
|
+
return new (this.config.schemaParsers.complexOneOf || OneOfSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1403
1400
|
},
|
|
1404
|
-
[SCHEMA_TYPES.COMPLEX_ALL_OF]: (schema) => {
|
|
1405
|
-
|
|
1406
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1407
|
-
return schemaParser.parse();
|
|
1401
|
+
[SCHEMA_TYPES$1.COMPLEX_ALL_OF]: (schema) => {
|
|
1402
|
+
return new (this.config.schemaParsers.complexAllOf || AllOfSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1408
1403
|
},
|
|
1409
|
-
[SCHEMA_TYPES.COMPLEX_ANY_OF]: (schema) => {
|
|
1410
|
-
|
|
1411
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1412
|
-
return schemaParser.parse();
|
|
1404
|
+
[SCHEMA_TYPES$1.COMPLEX_ANY_OF]: (schema) => {
|
|
1405
|
+
return new (this.config.schemaParsers.complexAnyOf || AnyOfSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1413
1406
|
},
|
|
1414
|
-
[SCHEMA_TYPES.COMPLEX_NOT]: (schema) => {
|
|
1415
|
-
|
|
1416
|
-
const schemaParser = new SchemaParser$1(this, schema, null, this.schemaPath);
|
|
1417
|
-
return schemaParser.parse();
|
|
1407
|
+
[SCHEMA_TYPES$1.COMPLEX_NOT]: (schema) => {
|
|
1408
|
+
return new (this.config.schemaParsers.complexNot || NotSchemaParser)(this, schema, null, this.schemaPath).parse();
|
|
1418
1409
|
}
|
|
1419
1410
|
};
|
|
1420
1411
|
_baseSchemaParsers = {
|
|
1421
|
-
[SCHEMA_TYPES.ENUM]: (schema, typeName) => {
|
|
1422
|
-
|
|
1423
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1424
|
-
return schemaParser.parse();
|
|
1412
|
+
[SCHEMA_TYPES$1.ENUM]: (schema, typeName) => {
|
|
1413
|
+
return new (this.config.schemaParsers.enum || EnumSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1425
1414
|
},
|
|
1426
|
-
[SCHEMA_TYPES.OBJECT]: (schema, typeName) => {
|
|
1427
|
-
|
|
1428
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1429
|
-
return schemaParser.parse();
|
|
1415
|
+
[SCHEMA_TYPES$1.OBJECT]: (schema, typeName) => {
|
|
1416
|
+
return new (this.config.schemaParsers.object || ObjectSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1430
1417
|
},
|
|
1431
|
-
[SCHEMA_TYPES.COMPLEX]: (schema, typeName) => {
|
|
1432
|
-
|
|
1433
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1434
|
-
return schemaParser.parse();
|
|
1418
|
+
[SCHEMA_TYPES$1.COMPLEX]: (schema, typeName) => {
|
|
1419
|
+
return new (this.config.schemaParsers.complex || ComplexSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1435
1420
|
},
|
|
1436
|
-
[SCHEMA_TYPES.PRIMITIVE]: (schema, typeName) => {
|
|
1437
|
-
|
|
1438
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1439
|
-
return schemaParser.parse();
|
|
1421
|
+
[SCHEMA_TYPES$1.PRIMITIVE]: (schema, typeName) => {
|
|
1422
|
+
return new (this.config.schemaParsers.primitive || PrimitiveSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1440
1423
|
},
|
|
1441
|
-
[SCHEMA_TYPES.DISCRIMINATOR]: (schema, typeName) => {
|
|
1442
|
-
|
|
1443
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1444
|
-
return schemaParser.parse();
|
|
1424
|
+
[SCHEMA_TYPES$1.DISCRIMINATOR]: (schema, typeName) => {
|
|
1425
|
+
return new (this.config.schemaParsers.discriminator || DiscriminatorSchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1445
1426
|
},
|
|
1446
|
-
[SCHEMA_TYPES.ARRAY]: (schema, typeName) => {
|
|
1447
|
-
|
|
1448
|
-
const schemaParser = new SchemaParser$1(this, schema, typeName, this.schemaPath);
|
|
1449
|
-
return schemaParser.parse();
|
|
1427
|
+
[SCHEMA_TYPES$1.ARRAY]: (schema, typeName) => {
|
|
1428
|
+
return new (this.config.schemaParsers.array || ArraySchemaParser)(this, schema, typeName, this.schemaPath).parse();
|
|
1450
1429
|
}
|
|
1451
1430
|
};
|
|
1452
1431
|
parseSchema = () => {
|
|
1453
|
-
if (!this.schema) return this._baseSchemaParsers[SCHEMA_TYPES.PRIMITIVE](null, this.typeName);
|
|
1432
|
+
if (!this.schema) return this._baseSchemaParsers[SCHEMA_TYPES$1.PRIMITIVE](null, this.typeName);
|
|
1454
1433
|
let schemaType = null;
|
|
1455
1434
|
let parsedSchema = null;
|
|
1456
1435
|
if (typeof this.schema === "string") return this.schema;
|
|
1457
1436
|
if (!this.schema.$parsed) {
|
|
1458
1437
|
if (!this.typeName && this.schemaUtils.isRefSchema(this.schema)) this.typeName = this.schemaUtils.getSchemaType(this.schema);
|
|
1459
|
-
if (this.schema.items && !Array.isArray(this.schema.items) && !this.schema.type) this.schema.type = SCHEMA_TYPES.ARRAY;
|
|
1438
|
+
if (this.schema.items && !Array.isArray(this.schema.items) && !this.schema.type) this.schema.type = SCHEMA_TYPES$1.ARRAY;
|
|
1460
1439
|
if (Array.isArray(this.schema.enum) && this.schema.enum.length === 1 && this.schema.enum[0] == null) {
|
|
1461
1440
|
consola.debug("invalid enum schema", this.schema);
|
|
1462
1441
|
this.schema = { type: this.config.Ts.Keyword.Null };
|
|
@@ -1483,13 +1462,11 @@ var SchemaParser = class {
|
|
|
1483
1462
|
};
|
|
1484
1463
|
getInlineParseContent = () => {
|
|
1485
1464
|
const parsedSchema = this.parseSchema();
|
|
1486
|
-
|
|
1487
|
-
return formattedSchema.content;
|
|
1465
|
+
return this.schemaFormatters.formatSchema(parsedSchema, "inline").content;
|
|
1488
1466
|
};
|
|
1489
1467
|
getParseContent = () => {
|
|
1490
1468
|
const parsedSchema = this.parseSchema();
|
|
1491
|
-
|
|
1492
|
-
return formattedSchema.content;
|
|
1469
|
+
return this.schemaFormatters.formatSchema(parsedSchema, "base").content;
|
|
1493
1470
|
};
|
|
1494
1471
|
extractSchemaFromResponseStruct = (responseStruct) => {
|
|
1495
1472
|
const { content,...extras } = responseStruct;
|
|
@@ -1571,8 +1548,8 @@ var SchemaUtils = class {
|
|
|
1571
1548
|
if (enumFieldType === this.config.Ts.Keyword.Undefined) return;
|
|
1572
1549
|
return internalCase(enumFieldType);
|
|
1573
1550
|
}
|
|
1574
|
-
if (lodash.keys(schema.properties).length) return SCHEMA_TYPES.OBJECT;
|
|
1575
|
-
if (schema.items) return SCHEMA_TYPES.ARRAY;
|
|
1551
|
+
if (lodash.keys(schema.properties).length) return SCHEMA_TYPES$1.OBJECT;
|
|
1552
|
+
if (schema.items) return SCHEMA_TYPES$1.ARRAY;
|
|
1576
1553
|
return null;
|
|
1577
1554
|
};
|
|
1578
1555
|
checkAndAddRequiredKeys = (schema, resultType) => {
|
|
@@ -1587,8 +1564,7 @@ var SchemaUtils = class {
|
|
|
1587
1564
|
const required = lodash.uniq([...this.getRequiredProperties(parentSchema), ...this.getRequiredProperties(childSchema)]);
|
|
1588
1565
|
const refData = this.getSchemaRefType(childSchema);
|
|
1589
1566
|
if (refData) {
|
|
1590
|
-
const
|
|
1591
|
-
const existedRequiredKeys = refObjectProperties.filter((key) => required.includes(key));
|
|
1567
|
+
const existedRequiredKeys = lodash.keys(refData.rawTypeData?.properties || {}).filter((key) => required.includes(key));
|
|
1592
1568
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1593
1569
|
return {
|
|
1594
1570
|
...childSchema,
|
|
@@ -1596,8 +1572,7 @@ var SchemaUtils = class {
|
|
|
1596
1572
|
};
|
|
1597
1573
|
}
|
|
1598
1574
|
if (childSchema.properties) {
|
|
1599
|
-
const
|
|
1600
|
-
const existedRequiredKeys = childSchemaProperties.filter((key) => required.includes(key));
|
|
1575
|
+
const existedRequiredKeys = lodash.keys(childSchema.properties).filter((key) => required.includes(key));
|
|
1601
1576
|
if (!existedRequiredKeys.length) return childSchema;
|
|
1602
1577
|
return {
|
|
1603
1578
|
required: lodash.uniq([...this.getRequiredProperties(childSchema), ...existedRequiredKeys]),
|
|
@@ -1616,19 +1591,19 @@ var SchemaUtils = class {
|
|
|
1616
1591
|
return this.config.componentTypeNameResolver.resolve([...(prefixes || []).map((prefix) => pascalCase(`${prefix} ${typeName}`)), ...(suffixes || []).map((suffix) => pascalCase(`${typeName} ${suffix}`))], shouldReserve);
|
|
1617
1592
|
};
|
|
1618
1593
|
getComplexType = (schema) => {
|
|
1619
|
-
if (schema.oneOf) return SCHEMA_TYPES.COMPLEX_ONE_OF;
|
|
1620
|
-
if (schema.allOf) return SCHEMA_TYPES.COMPLEX_ALL_OF;
|
|
1621
|
-
if (schema.anyOf) return SCHEMA_TYPES.COMPLEX_ANY_OF;
|
|
1622
|
-
if (schema.not) return SCHEMA_TYPES.COMPLEX_NOT;
|
|
1623
|
-
return SCHEMA_TYPES.COMPLEX_UNKNOWN;
|
|
1594
|
+
if (schema.oneOf) return SCHEMA_TYPES$1.COMPLEX_ONE_OF;
|
|
1595
|
+
if (schema.allOf) return SCHEMA_TYPES$1.COMPLEX_ALL_OF;
|
|
1596
|
+
if (schema.anyOf) return SCHEMA_TYPES$1.COMPLEX_ANY_OF;
|
|
1597
|
+
if (schema.not) return SCHEMA_TYPES$1.COMPLEX_NOT;
|
|
1598
|
+
return SCHEMA_TYPES$1.COMPLEX_UNKNOWN;
|
|
1624
1599
|
};
|
|
1625
1600
|
getInternalSchemaType = (schema) => {
|
|
1626
|
-
if (!lodash.isEmpty(schema.enum) || !lodash.isEmpty(this.getEnumNames(schema))) return SCHEMA_TYPES.ENUM;
|
|
1627
|
-
if (schema.discriminator) return SCHEMA_TYPES.DISCRIMINATOR;
|
|
1628
|
-
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES.COMPLEX;
|
|
1629
|
-
if (!lodash.isEmpty(schema.properties)) return SCHEMA_TYPES.OBJECT;
|
|
1630
|
-
if (schema.type === SCHEMA_TYPES.ARRAY) return SCHEMA_TYPES.ARRAY;
|
|
1631
|
-
return SCHEMA_TYPES.PRIMITIVE;
|
|
1601
|
+
if (!lodash.isEmpty(schema.enum) || !lodash.isEmpty(this.getEnumNames(schema))) return SCHEMA_TYPES$1.ENUM;
|
|
1602
|
+
if (schema.discriminator) return SCHEMA_TYPES$1.DISCRIMINATOR;
|
|
1603
|
+
if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) return SCHEMA_TYPES$1.COMPLEX;
|
|
1604
|
+
if (!lodash.isEmpty(schema.properties)) return SCHEMA_TYPES$1.OBJECT;
|
|
1605
|
+
if (schema.type === SCHEMA_TYPES$1.ARRAY) return SCHEMA_TYPES$1.ARRAY;
|
|
1606
|
+
return SCHEMA_TYPES$1.PRIMITIVE;
|
|
1632
1607
|
};
|
|
1633
1608
|
getSchemaType = (schema) => {
|
|
1634
1609
|
if (!schema) return this.config.Ts.Keyword.Any;
|
|
@@ -1716,28 +1691,25 @@ var SchemaParserFabric = class {
|
|
|
1716
1691
|
return customComponent;
|
|
1717
1692
|
};
|
|
1718
1693
|
parseSchema = (schema, typeName = null, schemaPath = []) => {
|
|
1719
|
-
|
|
1694
|
+
return this.createSchemaParser({
|
|
1720
1695
|
schema,
|
|
1721
1696
|
typeName,
|
|
1722
1697
|
schemaPath
|
|
1723
|
-
});
|
|
1724
|
-
return schemaParser.parseSchema();
|
|
1698
|
+
}).parseSchema();
|
|
1725
1699
|
};
|
|
1726
1700
|
getInlineParseContent = (schema, typeName, schemaPath) => {
|
|
1727
|
-
|
|
1701
|
+
return this.createSchemaParser({
|
|
1728
1702
|
schema,
|
|
1729
1703
|
typeName,
|
|
1730
1704
|
schemaPath
|
|
1731
|
-
});
|
|
1732
|
-
return parser.getInlineParseContent();
|
|
1705
|
+
}).getInlineParseContent();
|
|
1733
1706
|
};
|
|
1734
1707
|
getParseContent = (schema, typeName, schemaPath) => {
|
|
1735
|
-
|
|
1708
|
+
return this.createSchemaParser({
|
|
1736
1709
|
schema,
|
|
1737
1710
|
typeName,
|
|
1738
1711
|
schemaPath
|
|
1739
|
-
});
|
|
1740
|
-
return parser.getParseContent();
|
|
1712
|
+
}).getParseContent();
|
|
1741
1713
|
};
|
|
1742
1714
|
};
|
|
1743
1715
|
|
|
@@ -1890,14 +1862,8 @@ var SchemaRoutes = class {
|
|
|
1890
1862
|
}
|
|
1891
1863
|
if (routeParam) routeParams[routeParam.in].push(routeParam);
|
|
1892
1864
|
});
|
|
1893
|
-
for (const pathParam of pathParamsFromRouteName)
|
|
1894
|
-
|
|
1895
|
-
if (!alreadyExist) routeParams.path.push(pathParam);
|
|
1896
|
-
}
|
|
1897
|
-
for (const queryParam of queryParamsFromRouteName) {
|
|
1898
|
-
const alreadyExist = routeParams.query.some((parameter) => parameter.name === queryParam.name);
|
|
1899
|
-
if (!alreadyExist) routeParams.query.push(queryParam);
|
|
1900
|
-
}
|
|
1865
|
+
for (const pathParam of pathParamsFromRouteName) if (!routeParams.path.some((parameter) => parameter.name === pathParam.name)) routeParams.path.push(pathParam);
|
|
1866
|
+
for (const queryParam of queryParamsFromRouteName) if (!routeParams.query.some((parameter) => parameter.name === queryParam.name)) routeParams.query.push(queryParam);
|
|
1901
1867
|
return routeParams;
|
|
1902
1868
|
};
|
|
1903
1869
|
getContentTypes = (requestInfo, extraContentTypes) => lodash.uniq(lodash.compact([...extraContentTypes || [], ...lodash.flatten(lodash.map(requestInfo, (requestInfoData) => requestInfoData && lodash.keys(requestInfoData.content)))]));
|
|
@@ -1975,8 +1941,7 @@ var SchemaRoutes = class {
|
|
|
1975
1941
|
const headerTypes = Object.fromEntries(Object.entries(src).map(([k, v]) => {
|
|
1976
1942
|
return [k, this.schemaUtils.getSchemaType(v)];
|
|
1977
1943
|
}));
|
|
1978
|
-
|
|
1979
|
-
return r;
|
|
1944
|
+
return `headers: { ${Object.entries(headerTypes).map(([k, v]) => `"${k}": ${v}`).join(",")} },`;
|
|
1980
1945
|
};
|
|
1981
1946
|
return {
|
|
1982
1947
|
contentTypes,
|
|
@@ -2388,8 +2353,7 @@ var Request = class {
|
|
|
2388
2353
|
if (authToken) requestOptions.headers = { Authorization: authToken };
|
|
2389
2354
|
lodash.merge(requestOptions, options, this.config.requestOptions);
|
|
2390
2355
|
try {
|
|
2391
|
-
|
|
2392
|
-
return await response.text();
|
|
2356
|
+
return await (await fetch(url$2, requestOptions)).text();
|
|
2393
2357
|
} catch (error) {
|
|
2394
2358
|
const message = `error while fetching data from URL "${url$2}"`;
|
|
2395
2359
|
consola.error(message, error);
|
|
@@ -2480,8 +2444,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2480
2444
|
usageRouteInfo.produces = lodash.uniq(lodash.compact([...usageRouteInfo.produces || [], ...originalRouteInfo.produces || []]));
|
|
2481
2445
|
}
|
|
2482
2446
|
lodash.each(originalRouteParams, (originalRouteParam) => {
|
|
2483
|
-
|
|
2484
|
-
if (!existUsageParam) usageRouteParams.push(originalRouteParam);
|
|
2447
|
+
if (!usageRouteParams.find((param) => originalRouteParam.in === param.in && originalRouteParam.name === param.name)) usageRouteParams.push(originalRouteParam);
|
|
2485
2448
|
});
|
|
2486
2449
|
});
|
|
2487
2450
|
});
|
|
@@ -2491,6 +2454,7 @@ var SwaggerSchemaResolver = class {
|
|
|
2491
2454
|
//#endregion
|
|
2492
2455
|
//#region src/templates-worker.ts
|
|
2493
2456
|
const require = module.createRequire(import.meta.url);
|
|
2457
|
+
const eta = new Eta({ functionHeader: "const includeFile = options.includeFile;" });
|
|
2494
2458
|
var TemplatesWorker = class {
|
|
2495
2459
|
config;
|
|
2496
2460
|
fileSystem;
|
|
@@ -2520,12 +2484,10 @@ var TemplatesWorker = class {
|
|
|
2520
2484
|
cropExtension = (path$2) => this.config.templateExtensions.reduce((path$3, ext) => path$3.endsWith(ext) ? path$3.replace(ext, "") : path$3, path$2);
|
|
2521
2485
|
getTemplateFullPath = (path_, fileName) => {
|
|
2522
2486
|
const raw = path$1.resolve(path_, "./", this.cropExtension(fileName));
|
|
2523
|
-
|
|
2524
|
-
return pathVariants.find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
2487
|
+
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => !!this.fileSystem.pathIsExist(variant));
|
|
2525
2488
|
};
|
|
2526
2489
|
requireFnFromTemplate = (packageOrPath) => {
|
|
2527
|
-
|
|
2528
|
-
if (isPath) return require(path$1.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2490
|
+
if (packageOrPath.startsWith("./") || packageOrPath.startsWith("../")) return require(path$1.resolve(this.config.templatePaths.custom || this.config.templatePaths.original, packageOrPath));
|
|
2529
2491
|
return require(packageOrPath);
|
|
2530
2492
|
};
|
|
2531
2493
|
getTemplate = (name$1, fileName, path$2) => {
|
|
@@ -2555,8 +2517,7 @@ var TemplatesWorker = class {
|
|
|
2555
2517
|
};
|
|
2556
2518
|
findTemplateWithExt = (path$2) => {
|
|
2557
2519
|
const raw = this.cropExtension(path$2);
|
|
2558
|
-
|
|
2559
|
-
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2520
|
+
return this.config.templateExtensions.map((extension) => `${raw}${extension}`).find((variant) => this.fileSystem.pathIsExist(variant));
|
|
2560
2521
|
};
|
|
2561
2522
|
getTemplateContent = (path_) => {
|
|
2562
2523
|
const foundTemplatePathKey = lodash.keys(this.config.templatePaths).find((key) => path_.startsWith(`@${key}`));
|
|
@@ -2571,18 +2532,12 @@ var TemplatesWorker = class {
|
|
|
2571
2532
|
if (originalPath) return this.fileSystem.getFileContent(originalPath);
|
|
2572
2533
|
return "";
|
|
2573
2534
|
};
|
|
2574
|
-
renderTemplate = (template, configuration
|
|
2535
|
+
renderTemplate = (template, configuration) => {
|
|
2575
2536
|
if (!template) return "";
|
|
2576
|
-
return
|
|
2537
|
+
return eta.render(eta.compile(template, { async: false }), {
|
|
2577
2538
|
...this.getRenderTemplateData(),
|
|
2578
2539
|
...configuration
|
|
2579
|
-
}, {
|
|
2580
|
-
async: false,
|
|
2581
|
-
...options,
|
|
2582
|
-
includeFile: (path$2, configuration$1, options$1 = {}) => {
|
|
2583
|
-
return this.renderTemplate(this.getTemplateContent(path$2), configuration$1, options$1);
|
|
2584
|
-
}
|
|
2585
|
-
});
|
|
2540
|
+
}, { includeFile: (path$2, configuration$1) => this.renderTemplate(this.getTemplateContent(path$2), configuration$1) });
|
|
2586
2541
|
};
|
|
2587
2542
|
};
|
|
2588
2543
|
|
|
@@ -2673,10 +2628,7 @@ var TypeNameFormatter = class {
|
|
|
2673
2628
|
isValidName = (name$1) => /^([A-Za-z$_]{1,})$/g.test(name$1);
|
|
2674
2629
|
fixModelName = (name$1, options) => {
|
|
2675
2630
|
if (!this.isValidName(name$1)) {
|
|
2676
|
-
if (!/^[a-zA-Z_$]/g.test(name$1)) {
|
|
2677
|
-
const fixPrefix = options.type === "enum-key" ? this.config.fixInvalidEnumKeyPrefix : this.config.fixInvalidTypeNamePrefix;
|
|
2678
|
-
return `${fixPrefix} ${name$1}`;
|
|
2679
|
-
}
|
|
2631
|
+
if (!/^[a-zA-Z_$]/g.test(name$1)) return `${options.type === "enum-key" ? this.config.fixInvalidEnumKeyPrefix : this.config.fixInvalidTypeNamePrefix} ${name$1}`;
|
|
2680
2632
|
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(/__+$/, "");
|
|
2681
2633
|
if (name$1.includes("-")) return lodash.startCase(name$1).replace(/ /g, "");
|
|
2682
2634
|
}
|
|
@@ -2696,8 +2648,7 @@ var FileSystem = class {
|
|
|
2696
2648
|
pathIsDir = (path$2) => {
|
|
2697
2649
|
if (!path$2) return false;
|
|
2698
2650
|
try {
|
|
2699
|
-
|
|
2700
|
-
return stat.isDirectory();
|
|
2651
|
+
return fs.statSync(path$2).isDirectory();
|
|
2701
2652
|
} catch (e) {
|
|
2702
2653
|
return false;
|
|
2703
2654
|
}
|
|
@@ -2796,9 +2747,9 @@ var CodeGenProcess = class {
|
|
|
2796
2747
|
typeName
|
|
2797
2748
|
]), rawTypeData);
|
|
2798
2749
|
}));
|
|
2750
|
+
this.schemaComponentsMap.discriminatorsFirst();
|
|
2799
2751
|
this.schemaComponentsMap.enumsFirst();
|
|
2800
|
-
const
|
|
2801
|
-
const parsedSchemas = componentsToParse.map((schemaComponent) => {
|
|
2752
|
+
const parsedSchemas = this.schemaComponentsMap.filter(lodash.compact(["schemas", this.config.extractResponses && "responses"])).map((schemaComponent) => {
|
|
2802
2753
|
const parsed = this.schemaParserFabric.parseSchema(schemaComponent.rawTypeData, schemaComponent.typeName);
|
|
2803
2754
|
schemaComponent.typeData = parsed;
|
|
2804
2755
|
return parsed;
|
|
@@ -2833,8 +2784,7 @@ var CodeGenProcess = class {
|
|
|
2833
2784
|
this.fileSystem.createDir(this.config.output);
|
|
2834
2785
|
}
|
|
2835
2786
|
const files$1 = await this.generateOutputFiles({ configuration });
|
|
2836
|
-
|
|
2837
|
-
if (isDirPath) for (const file of files$1) {
|
|
2787
|
+
if (this.fileSystem.pathIsDir(this.config.output)) for (const file of files$1) {
|
|
2838
2788
|
this.fileSystem.createFile({
|
|
2839
2789
|
path: this.config.output,
|
|
2840
2790
|
fileName: `${file.fileName}${file.fileExtension}`,
|
|
@@ -3033,6 +2983,32 @@ var CodeGenProcess = class {
|
|
|
3033
2983
|
};
|
|
3034
2984
|
};
|
|
3035
2985
|
|
|
2986
|
+
//#endregion
|
|
2987
|
+
//#region types/index.ts
|
|
2988
|
+
let RequestContentKind = /* @__PURE__ */ function(RequestContentKind$1) {
|
|
2989
|
+
RequestContentKind$1["JSON"] = "JSON";
|
|
2990
|
+
RequestContentKind$1["URL_ENCODED"] = "URL_ENCODED";
|
|
2991
|
+
RequestContentKind$1["FORM_DATA"] = "FORM_DATA";
|
|
2992
|
+
RequestContentKind$1["IMAGE"] = "IMAGE";
|
|
2993
|
+
RequestContentKind$1["OTHER"] = "OTHER";
|
|
2994
|
+
RequestContentKind$1["TEXT"] = "TEXT";
|
|
2995
|
+
return RequestContentKind$1;
|
|
2996
|
+
}({});
|
|
2997
|
+
let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES$2) {
|
|
2998
|
+
SCHEMA_TYPES$2["ARRAY"] = "array";
|
|
2999
|
+
SCHEMA_TYPES$2["OBJECT"] = "object";
|
|
3000
|
+
SCHEMA_TYPES$2["ENUM"] = "enum";
|
|
3001
|
+
SCHEMA_TYPES$2["REF"] = "$ref";
|
|
3002
|
+
SCHEMA_TYPES$2["PRIMITIVE"] = "primitive";
|
|
3003
|
+
SCHEMA_TYPES$2["COMPLEX"] = "complex";
|
|
3004
|
+
SCHEMA_TYPES$2["COMPLEX_ONE_OF"] = "oneOf";
|
|
3005
|
+
SCHEMA_TYPES$2["COMPLEX_ANY_OF"] = "anyOf";
|
|
3006
|
+
SCHEMA_TYPES$2["COMPLEX_ALL_OF"] = "allOf";
|
|
3007
|
+
SCHEMA_TYPES$2["COMPLEX_NOT"] = "not";
|
|
3008
|
+
SCHEMA_TYPES$2["COMPLEX_UNKNOWN"] = "__unknown";
|
|
3009
|
+
return SCHEMA_TYPES$2;
|
|
3010
|
+
}({});
|
|
3011
|
+
|
|
3036
3012
|
//#endregion
|
|
3037
3013
|
//#region src/commands/generate-templates/configuration.ts
|
|
3038
3014
|
var TemplatesGenConfig = class {
|
|
@@ -3089,8 +3065,7 @@ var TemplatesGenProcess = class {
|
|
|
3089
3065
|
const templateEtaPath = path.resolve(outputPath, `${templateName}.eta`);
|
|
3090
3066
|
const templateEjsPathExist = this.fileSystem.pathIsExist(templateEjsPath);
|
|
3091
3067
|
const templateEtaPathExist = this.fileSystem.pathIsExist(templateEtaPath);
|
|
3092
|
-
|
|
3093
|
-
if (templateNotExist) this.fileSystem.createFile({
|
|
3068
|
+
if (!templateEjsPathExist && !templateEtaPathExist) this.fileSystem.createFile({
|
|
3094
3069
|
path: outputPath,
|
|
3095
3070
|
fileName: template.name,
|
|
3096
3071
|
content: template.content,
|
|
@@ -3160,8 +3135,7 @@ var TemplatesGenProcess = class {
|
|
|
3160
3135
|
async function generateTemplates(config) {
|
|
3161
3136
|
if (config.debug) consola.level = Number.MAX_SAFE_INTEGER;
|
|
3162
3137
|
if (config.silent) consola.level = 0;
|
|
3163
|
-
|
|
3164
|
-
return await codeGenProcess.start();
|
|
3138
|
+
return await new TemplatesGenProcess(config).start();
|
|
3165
3139
|
}
|
|
3166
3140
|
|
|
3167
3141
|
//#endregion
|
|
@@ -3169,10 +3143,9 @@ async function generateTemplates(config) {
|
|
|
3169
3143
|
async function generateApi(config) {
|
|
3170
3144
|
if (config.debug) consola.level = Number.MAX_SAFE_INTEGER;
|
|
3171
3145
|
if (config.silent) consola.level = 0;
|
|
3172
|
-
|
|
3173
|
-
return await codeGenProcess.start();
|
|
3146
|
+
return await new CodeGenProcess(config).start();
|
|
3174
3147
|
}
|
|
3175
3148
|
|
|
3176
3149
|
//#endregion
|
|
3177
|
-
export { CodeGenConfig, HTTP_CLIENT, TemplatesGenConfig, constants_exports, generateApi, generateTemplates, package_default };
|
|
3178
|
-
//# sourceMappingURL=src-
|
|
3150
|
+
export { CodeGenConfig, HTTP_CLIENT, RequestContentKind, SCHEMA_TYPES, TemplatesGenConfig, constants_exports, generateApi, generateTemplates, package_default };
|
|
3151
|
+
//# sourceMappingURL=src-BRCAbt5v.js.map
|