swagger-typescript-api 13.3.0 → 13.4.0

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/index.mjs CHANGED
@@ -1,13 +1,2 @@
1
- import { a as CodeGenProcess, c as constants_exports, i as SCHEMA_TYPES, r as RequestContentKind, t as generateTemplates } from "./generate-templates-BaT2BiRR.mjs";
2
- import { consola as consola$1 } from "consola";
3
-
4
- //#region src/index.ts
5
- async function generateApi(config) {
6
- if (config.debug) consola$1.level = Number.MAX_SAFE_INTEGER;
7
- if (config.silent) consola$1.level = 0;
8
- return await new CodeGenProcess(config).start();
9
- }
10
-
11
- //#endregion
1
+ import { a as SCHEMA_TYPES, c as constants_exports, i as RequestContentKind, n as generateTemplates, t as generateApi } from "./src-BPFXd2rf.mjs";
12
2
  export { RequestContentKind, SCHEMA_TYPES, constants_exports as constants, generateApi, generateTemplates };
13
- //# sourceMappingURL=index.mjs.map
@@ -1,4 +1,4 @@
1
- import { t as __exportAll } from "./chunk-DQk6qfdC.mjs";
1
+ import { t as __exportAll } from "./chunk-CfYAbeIz.mjs";
2
2
  import * as module from "node:module";
3
3
  import consola, { consola as consola$1 } from "consola";
4
4
  import * as esToolkit from "es-toolkit";
@@ -19,7 +19,6 @@ import SwaggerParser from "@apidevtools/swagger-parser";
19
19
  import * as url$1 from "node:url";
20
20
  import url from "node:url";
21
21
  import { Eta } from "eta";
22
-
23
22
  //#region src/code-formatter.ts
24
23
  var CodeFormatter = class {
25
24
  config;
@@ -93,7 +92,6 @@ var TsLanguageServiceHost = class {
93
92
  return typescript.sys.fileExists(path);
94
93
  }
95
94
  };
96
-
97
95
  //#endregion
98
96
  //#region src/util/name-resolver.ts
99
97
  var NameResolver = class {
@@ -144,14 +142,12 @@ var NameResolver = class {
144
142
  return null;
145
143
  }
146
144
  };
147
-
148
145
  //#endregion
149
146
  //#region src/util/random.ts
150
147
  const getRandomInt = (min = 0, max = 1) => {
151
148
  if (min === max) return min;
152
149
  return Math.round(Math.random() * (max - min) + min);
153
150
  };
154
-
155
151
  //#endregion
156
152
  //#region src/component-type-name-resolver.ts
157
153
  var ComponentTypeNameResolver = class extends NameResolver {
@@ -175,13 +171,11 @@ var ComponentTypeNameResolver = class extends NameResolver {
175
171
  });
176
172
  }
177
173
  };
178
-
179
174
  //#endregion
180
175
  //#region package.json
181
176
  var name = "swagger-typescript-api";
182
- var version = "13.3.0";
177
+ var version = "13.4.0";
183
178
  var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
184
-
185
179
  //#endregion
186
180
  //#region src/constants.ts
187
181
  var constants_exports = /* @__PURE__ */ __exportAll({
@@ -247,7 +241,6 @@ const SCHEMA_TYPES$1 = {
247
241
  COMPLEX_NOT: "not",
248
242
  COMPLEX_UNKNOWN: "__unknown"
249
243
  };
250
-
251
244
  //#endregion
252
245
  //#region src/util/object-assign.ts
253
246
  const objectAssign = (target, updater) => {
@@ -258,7 +251,6 @@ const objectAssign = (target, updater) => {
258
251
  merge(target, update);
259
252
  for (const key of undefinedKeys) target[key] = void 0;
260
253
  };
261
-
262
254
  //#endregion
263
255
  //#region src/configuration.ts
264
256
  const TsKeyword = {
@@ -272,6 +264,7 @@ const TsKeyword = {
272
264
  Undefined: "undefined",
273
265
  Object: "object",
274
266
  File: "File",
267
+ Blob: "Blob",
275
268
  Date: "Date",
276
269
  Type: "type",
277
270
  Enum: "enum",
@@ -595,13 +588,11 @@ var CodeGenConfig = class {
595
588
  if (this.enumNamesAsValues) this.extractEnums = true;
596
589
  };
597
590
  };
598
-
599
591
  //#endregion
600
592
  //#region src/util/pascal-case.ts
601
593
  function pascalCase(value) {
602
594
  return upperFirst(camelCase(value));
603
595
  }
604
-
605
596
  //#endregion
606
597
  //#region src/schema-components-map.ts
607
598
  var SchemaComponentsMap = class {
@@ -678,7 +669,6 @@ var SchemaComponentsMap = class {
678
669
  });
679
670
  }
680
671
  };
681
-
682
672
  //#endregion
683
673
  //#region src/schema-parser/schema-formatters.ts
684
674
  var SchemaFormatters = class {
@@ -769,7 +759,6 @@ var SchemaFormatters = class {
769
759
  return fields.join("");
770
760
  };
771
761
  };
772
-
773
762
  //#endregion
774
763
  //#region src/util/sort-by-property.ts
775
764
  const sortByProperty = (propertyName) => (o1, o2) => {
@@ -777,7 +766,6 @@ const sortByProperty = (propertyName) => (o1, o2) => {
777
766
  if (o1[propertyName] < o2[propertyName]) return -1;
778
767
  return 0;
779
768
  };
780
-
781
769
  //#endregion
782
770
  //#region src/schema-parser/mono-schema-parser.ts
783
771
  var MonoSchemaParser = class {
@@ -810,7 +798,6 @@ var MonoSchemaParser = class {
810
798
  return this.schemaUtils.buildTypeNameFromPath(this.schemaPath);
811
799
  };
812
800
  };
813
-
814
801
  //#endregion
815
802
  //#region src/schema-parser/base-schema-parsers/array.ts
816
803
  var ArraySchemaParser = class extends MonoSchemaParser {
@@ -844,7 +831,6 @@ var ArraySchemaParser = class extends MonoSchemaParser {
844
831
  };
845
832
  }
846
833
  };
847
-
848
834
  //#endregion
849
835
  //#region src/schema-parser/base-schema-parsers/complex.ts
850
836
  var ComplexSchemaParser = class extends MonoSchemaParser {
@@ -868,7 +854,6 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
868
854
  };
869
855
  }
870
856
  };
871
-
872
857
  //#endregion
873
858
  //#region src/schema-parser/base-schema-parsers/discriminator.ts
874
859
  var DiscriminatorSchemaParser = class extends MonoSchemaParser {
@@ -947,7 +932,7 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
947
932
  const mappingUsageKey = mappingPropertySchemaEnumKeysMap[mappingKey] || ts.StringValue(mappingKey);
948
933
  if (ableToCreateMappingType) return ts.TypeWithGeneric(mappingTypeName, [mappingUsageKey, content]);
949
934
  return ts.ExpressionGroup(ts.IntersectionType([ts.ObjectWrapper(ts.TypeField({
950
- key: discriminator.propertyName,
935
+ key: ts.StringValue(discriminator.propertyName),
951
936
  value: mappingUsageKey
952
937
  })), content]));
953
938
  };
@@ -1036,7 +1021,6 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
1036
1021
  return { content: ts.ExpressionGroup(this.schemaParser._complexSchemaParsers[complexType](this.schema)) };
1037
1022
  };
1038
1023
  };
1039
-
1040
1024
  //#endregion
1041
1025
  //#region src/schema-parser/util/enum-key-resolver.ts
1042
1026
  var EnumKeyResolver = class extends NameResolver {
@@ -1049,7 +1033,6 @@ var EnumKeyResolver = class extends NameResolver {
1049
1033
  });
1050
1034
  }
1051
1035
  };
1052
-
1053
1036
  //#endregion
1054
1037
  //#region src/schema-parser/base-schema-parsers/enum.ts
1055
1038
  var EnumSchemaParser = class extends MonoSchemaParser {
@@ -1151,7 +1134,6 @@ var EnumSchemaParser = class extends MonoSchemaParser {
1151
1134
  return this.enumKeyResolver.resolve([formatted]);
1152
1135
  };
1153
1136
  };
1154
-
1155
1137
  //#endregion
1156
1138
  //#region src/schema-parser/base-schema-parsers/object.ts
1157
1139
  var ObjectSchemaParser = class extends MonoSchemaParser {
@@ -1220,7 +1202,6 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
1220
1202
  return propertiesContent;
1221
1203
  };
1222
1204
  };
1223
-
1224
1205
  //#endregion
1225
1206
  //#region src/schema-parser/base-schema-parsers/primitive.ts
1226
1207
  var PrimitiveSchemaParser = class extends MonoSchemaParser {
@@ -1241,11 +1222,17 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
1241
1222
  schemaPath: this.schemaPath
1242
1223
  }).getInlineParseContent();
1243
1224
  else recordValuesContent = this.config.Ts.Keyword.Any;
1244
- contentType = this.config.Ts.RecordType(recordKeysContent, recordValuesContent);
1225
+ const recordType = this.config.Ts.RecordType(recordKeysContent, recordValuesContent);
1226
+ contentType = propertyNamesSchema ? this.config.Ts.TypeWithGeneric("Partial", [recordType]) : recordType;
1245
1227
  }
1246
1228
  if (Array.isArray(type) && type.length) contentType = this.schemaParser._complexSchemaParsers.oneOf({
1247
1229
  ...typeof this.schema === "object" ? this.schema : {},
1248
- oneOf: type.map((type) => ({ type }))
1230
+ oneOf: type.map((t) => {
1231
+ const branch = { type: t };
1232
+ Object.assign(branch, this.schema);
1233
+ branch.type = t;
1234
+ return branch;
1235
+ })
1249
1236
  });
1250
1237
  if (Array.isArray(items) && type === SCHEMA_TYPES$1.ARRAY) contentType = this.config.Ts.Tuple(items.map((item) => this.schemaParserFabric.createSchemaParser({
1251
1238
  schema: item,
@@ -1264,7 +1251,6 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
1264
1251
  };
1265
1252
  }
1266
1253
  };
1267
-
1268
1254
  //#endregion
1269
1255
  //#region src/schema-parser/complex-schema-parsers/all-of.ts
1270
1256
  var AllOfSchemaParser = class extends MonoSchemaParser {
@@ -1276,7 +1262,6 @@ var AllOfSchemaParser = class extends MonoSchemaParser {
1276
1262
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1277
1263
  }
1278
1264
  };
1279
-
1280
1265
  //#endregion
1281
1266
  //#region src/schema-parser/complex-schema-parsers/any-of.ts
1282
1267
  var AnyOfSchemaParser = class extends MonoSchemaParser {
@@ -1288,7 +1273,6 @@ var AnyOfSchemaParser = class extends MonoSchemaParser {
1288
1273
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1289
1274
  }
1290
1275
  };
1291
-
1292
1276
  //#endregion
1293
1277
  //#region src/schema-parser/complex-schema-parsers/not.ts
1294
1278
  var NotSchemaParser = class extends MonoSchemaParser {
@@ -1296,7 +1280,6 @@ var NotSchemaParser = class extends MonoSchemaParser {
1296
1280
  return this.config.Ts.Keyword.Any;
1297
1281
  }
1298
1282
  };
1299
-
1300
1283
  //#endregion
1301
1284
  //#region src/schema-parser/complex-schema-parsers/one-of.ts
1302
1285
  var OneOfSchemaParser = class extends MonoSchemaParser {
@@ -1308,7 +1291,6 @@ var OneOfSchemaParser = class extends MonoSchemaParser {
1308
1291
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1309
1292
  }
1310
1293
  };
1311
-
1312
1294
  //#endregion
1313
1295
  //#region src/schema-parser/schema-parser.ts
1314
1296
  var SchemaParser = class {
@@ -1421,7 +1403,6 @@ var SchemaParser = class {
1421
1403
  };
1422
1404
  };
1423
1405
  };
1424
-
1425
1406
  //#endregion
1426
1407
  //#region src/schema-parser/schema-utils.ts
1427
1408
  var SchemaUtils = class {
@@ -1430,6 +1411,22 @@ var SchemaUtils = class {
1430
1411
  this.schemaComponentsMap = schemaComponentsMap;
1431
1412
  this.typeNameFormatter = typeNameFormatter;
1432
1413
  }
1414
+ isBinaryLikeContentMediaType = (contentMediaType) => {
1415
+ if (typeof contentMediaType !== "string" || !contentMediaType) return false;
1416
+ const mediaType = contentMediaType.split(";")[0]?.trim().toLowerCase();
1417
+ if (!mediaType) return false;
1418
+ /**
1419
+ * `contentMediaType` comes from JSON Schema. In practice it is often used to
1420
+ * signal "this string is a file/blob", but it may also be used for textual
1421
+ * payloads (json/xml/etc). We treat only binary-ish media types as `File`.
1422
+ */
1423
+ if (mediaType.startsWith("text/")) return false;
1424
+ if (mediaType.includes("json") || mediaType.includes("+json")) return false;
1425
+ if (mediaType.includes("xml") || mediaType.includes("+xml")) return false;
1426
+ if (mediaType === "application/x-www-form-urlencoded") return false;
1427
+ if (mediaType === "application/javascript" || mediaType === "application/ecmascript" || mediaType === "application/graphql" || mediaType === "application/yaml" || mediaType === "application/x-yaml") return false;
1428
+ return mediaType === "application/octet-stream" || mediaType.startsWith("image/") || mediaType.startsWith("audio/") || mediaType.startsWith("video/") || mediaType.startsWith("font/") || mediaType.startsWith("model/") || mediaType.startsWith("application/");
1429
+ };
1433
1430
  getRequiredProperties = (schema) => {
1434
1431
  return uniq(schema && Array.isArray(schema.required) && schema.required || []);
1435
1432
  };
@@ -1538,9 +1535,12 @@ var SchemaUtils = class {
1538
1535
  else {
1539
1536
  const primitiveType = this.getSchemaPrimitiveType(schema);
1540
1537
  if (primitiveType == null) return this.config.Ts.Keyword.Any;
1541
- const typeAlias = get(this.config.primitiveTypes, [primitiveType, schema.format]) || get(this.config.primitiveTypes, [primitiveType, "$default"]) || this.config.primitiveTypes[primitiveType];
1542
- if (typeof typeAlias === "function") resultType = typeAlias(schema, this);
1543
- else resultType = typeAlias || primitiveType;
1538
+ if (primitiveType === this.config.Ts.Keyword.String && !schema.format && this.isBinaryLikeContentMediaType(schema.contentMediaType)) resultType = this.config.Ts.UnionType([this.config.Ts.Keyword.File, this.config.Ts.Keyword.Blob]);
1539
+ else {
1540
+ const typeAlias = get(this.config.primitiveTypes, [primitiveType, schema.format]) || get(this.config.primitiveTypes, [primitiveType, "$default"]) || this.config.primitiveTypes[primitiveType];
1541
+ if (typeof typeAlias === "function") resultType = typeAlias(schema, this);
1542
+ else resultType = typeAlias || primitiveType;
1543
+ }
1544
1544
  }
1545
1545
  if (!resultType) return this.config.Ts.Keyword.Any;
1546
1546
  return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, resultType));
@@ -1564,7 +1564,6 @@ var SchemaUtils = class {
1564
1564
  }
1565
1565
  };
1566
1566
  };
1567
-
1568
1567
  //#endregion
1569
1568
  //#region src/schema-parser/schema-parser-fabric.ts
1570
1569
  var SchemaParserFabric = class {
@@ -1634,11 +1633,9 @@ var SchemaParserFabric = class {
1634
1633
  }).getParseContent();
1635
1634
  };
1636
1635
  };
1637
-
1638
1636
  //#endregion
1639
1637
  //#region src/util/id.ts
1640
1638
  const generateId = () => crypto.randomUUID();
1641
-
1642
1639
  //#endregion
1643
1640
  //#region src/schema-routes/util/specific-arg-name-resolver.ts
1644
1641
  var SpecificArgNameResolver = class extends NameResolver {
@@ -1651,7 +1648,6 @@ var SpecificArgNameResolver = class extends NameResolver {
1651
1648
  });
1652
1649
  }
1653
1650
  };
1654
-
1655
1651
  //#endregion
1656
1652
  //#region src/schema-routes/schema-routes.ts
1657
1653
  const CONTENT_KIND = {
@@ -1974,7 +1970,7 @@ var SchemaRoutes = class {
1974
1970
  if (schema && schema.typeData && !schema.typeData.description && requestBody?.description) schema.typeData.description = requestBody.description;
1975
1971
  return {
1976
1972
  ...requestBody || {},
1977
- paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
1973
+ paramName: requestBodyName || requestBody?.name || "data",
1978
1974
  contentTypes,
1979
1975
  contentKind,
1980
1976
  schema,
@@ -2269,7 +2265,6 @@ var SchemaRoutes = class {
2269
2265
  return routes.slice().sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
2270
2266
  };
2271
2267
  };
2272
-
2273
2268
  //#endregion
2274
2269
  //#region src/resolved-swagger-schema.ts
2275
2270
  var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
@@ -2619,7 +2614,6 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2619
2614
  return resolvedSwaggerSchema;
2620
2615
  }
2621
2616
  };
2622
-
2623
2617
  //#endregion
2624
2618
  //#region src/util/request.ts
2625
2619
  var Request = class {
@@ -2640,7 +2634,6 @@ var Request = class {
2640
2634
  }
2641
2635
  }
2642
2636
  };
2643
-
2644
2637
  //#endregion
2645
2638
  //#region src/swagger-schema-resolver.ts
2646
2639
  var SwaggerSchemaResolver = class {
@@ -2752,7 +2745,6 @@ var SwaggerSchemaResolver = class {
2752
2745
  }
2753
2746
  }
2754
2747
  };
2755
-
2756
2748
  //#endregion
2757
2749
  //#region src/templates-worker.ts
2758
2750
  const require = module.createRequire(import.meta.url);
@@ -2840,7 +2832,6 @@ var TemplatesWorker = class {
2840
2832
  }, { includeFile: (path, configuration) => this.renderTemplate(this.getTemplateContent(path), configuration) });
2841
2833
  };
2842
2834
  };
2843
-
2844
2835
  //#endregion
2845
2836
  //#region src/translators/translator.ts
2846
2837
  var Translator = class {
@@ -2854,7 +2845,6 @@ var Translator = class {
2854
2845
  throw new Error("not implemented");
2855
2846
  }
2856
2847
  };
2857
-
2858
2848
  //#endregion
2859
2849
  //#region src/translators/javascript.ts
2860
2850
  var JavascriptTranslator = class extends Translator {
@@ -2895,7 +2885,6 @@ var JavascriptTranslator = class extends Translator {
2895
2885
  }];
2896
2886
  };
2897
2887
  };
2898
-
2899
2888
  //#endregion
2900
2889
  //#region src/type-name-formatter.ts
2901
2890
  var TypeNameFormatter = class {
@@ -2934,7 +2923,6 @@ var TypeNameFormatter = class {
2934
2923
  return name;
2935
2924
  };
2936
2925
  };
2937
-
2938
2926
  //#endregion
2939
2927
  //#region src/util/file-system.ts
2940
2928
  var FileSystem = class {
@@ -2986,7 +2974,6 @@ var FileSystem = class {
2986
2974
  return fs.writeFileSync(absolutePath, fileContent);
2987
2975
  };
2988
2976
  };
2989
-
2990
2977
  //#endregion
2991
2978
  //#region src/util/lodash-compat.ts
2992
2979
  function createLodashCompat() {
@@ -2995,7 +2982,6 @@ function createLodashCompat() {
2995
2982
  ...esToolkitCompat
2996
2983
  };
2997
2984
  }
2998
-
2999
2985
  //#endregion
3000
2986
  //#region src/code-gen-process.ts
3001
2987
  const PATCHABLE_INSTANCES = [
@@ -3285,7 +3271,6 @@ var CodeGenProcess = class {
3285
3271
  for (const instanceKey of PATCHABLE_INSTANCES) if (instanceKey !== key && key in this[instanceKey]) this[instanceKey][key] = value;
3286
3272
  };
3287
3273
  };
3288
-
3289
3274
  //#endregion
3290
3275
  //#region types/index.ts
3291
3276
  let RequestContentKind = /* @__PURE__ */ function(RequestContentKind) {
@@ -3311,7 +3296,6 @@ let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES) {
3311
3296
  SCHEMA_TYPES["COMPLEX_UNKNOWN"] = "__unknown";
3312
3297
  return SCHEMA_TYPES;
3313
3298
  }({});
3314
-
3315
3299
  //#endregion
3316
3300
  //#region src/commands/generate-templates/configuration.ts
3317
3301
  var TemplatesGenConfig = class {
@@ -3330,7 +3314,6 @@ var TemplatesGenConfig = class {
3330
3314
  objectAssign(this, update);
3331
3315
  };
3332
3316
  };
3333
-
3334
3317
  //#endregion
3335
3318
  //#region src/commands/generate-templates/templates-gen-process.ts
3336
3319
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
@@ -3432,7 +3415,6 @@ var TemplatesGenProcess = class {
3432
3415
  return this.fileSystem.getFileContent(path.resolve(this.rootDir, pathToFile));
3433
3416
  };
3434
3417
  };
3435
-
3436
3418
  //#endregion
3437
3419
  //#region src/commands/generate-templates/index.ts
3438
3420
  async function generateTemplates(config) {
@@ -3440,7 +3422,14 @@ async function generateTemplates(config) {
3440
3422
  if (config.silent) consola$1.level = 0;
3441
3423
  return await new TemplatesGenProcess(config).start();
3442
3424
  }
3443
-
3444
3425
  //#endregion
3445
- 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 };
3446
- //# sourceMappingURL=generate-templates-BaT2BiRR.mjs.map
3426
+ //#region src/index.ts
3427
+ async function generateApi(config) {
3428
+ if (config.debug) consola$1.level = Number.MAX_SAFE_INTEGER;
3429
+ if (config.silent) consola$1.level = 0;
3430
+ return await new CodeGenProcess(config).start();
3431
+ }
3432
+ //#endregion
3433
+ 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 };
3434
+
3435
+ //# sourceMappingURL=src-BPFXd2rf.mjs.map