swagger-typescript-api 13.3.1 → 13.5.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.
@@ -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.1";
177
+ var version = "13.5.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",
@@ -507,6 +500,7 @@ var CodeGenConfig = class {
507
500
  string: {
508
501
  $default: this.Ts.Keyword.String,
509
502
  binary: () => this.Ts.Keyword.File,
503
+ byte: () => this.Ts.Keyword.Blob,
510
504
  file: () => this.Ts.Keyword.File,
511
505
  "date-time": () => this.Ts.Keyword.String,
512
506
  time: () => this.Ts.Keyword.String,
@@ -595,13 +589,11 @@ var CodeGenConfig = class {
595
589
  if (this.enumNamesAsValues) this.extractEnums = true;
596
590
  };
597
591
  };
598
-
599
592
  //#endregion
600
593
  //#region src/util/pascal-case.ts
601
594
  function pascalCase(value) {
602
595
  return upperFirst(camelCase(value));
603
596
  }
604
-
605
597
  //#endregion
606
598
  //#region src/schema-components-map.ts
607
599
  var SchemaComponentsMap = class {
@@ -678,7 +670,6 @@ var SchemaComponentsMap = class {
678
670
  });
679
671
  }
680
672
  };
681
-
682
673
  //#endregion
683
674
  //#region src/schema-parser/schema-formatters.ts
684
675
  var SchemaFormatters = class {
@@ -769,7 +760,6 @@ var SchemaFormatters = class {
769
760
  return fields.join("");
770
761
  };
771
762
  };
772
-
773
763
  //#endregion
774
764
  //#region src/util/sort-by-property.ts
775
765
  const sortByProperty = (propertyName) => (o1, o2) => {
@@ -777,7 +767,6 @@ const sortByProperty = (propertyName) => (o1, o2) => {
777
767
  if (o1[propertyName] < o2[propertyName]) return -1;
778
768
  return 0;
779
769
  };
780
-
781
770
  //#endregion
782
771
  //#region src/schema-parser/mono-schema-parser.ts
783
772
  var MonoSchemaParser = class {
@@ -810,7 +799,6 @@ var MonoSchemaParser = class {
810
799
  return this.schemaUtils.buildTypeNameFromPath(this.schemaPath);
811
800
  };
812
801
  };
813
-
814
802
  //#endregion
815
803
  //#region src/schema-parser/base-schema-parsers/array.ts
816
804
  var ArraySchemaParser = class extends MonoSchemaParser {
@@ -844,7 +832,6 @@ var ArraySchemaParser = class extends MonoSchemaParser {
844
832
  };
845
833
  }
846
834
  };
847
-
848
835
  //#endregion
849
836
  //#region src/schema-parser/base-schema-parsers/complex.ts
850
837
  var ComplexSchemaParser = class extends MonoSchemaParser {
@@ -868,7 +855,6 @@ var ComplexSchemaParser = class extends MonoSchemaParser {
868
855
  };
869
856
  }
870
857
  };
871
-
872
858
  //#endregion
873
859
  //#region src/schema-parser/base-schema-parsers/discriminator.ts
874
860
  var DiscriminatorSchemaParser = class extends MonoSchemaParser {
@@ -1036,7 +1022,6 @@ var DiscriminatorSchemaParser = class extends MonoSchemaParser {
1036
1022
  return { content: ts.ExpressionGroup(this.schemaParser._complexSchemaParsers[complexType](this.schema)) };
1037
1023
  };
1038
1024
  };
1039
-
1040
1025
  //#endregion
1041
1026
  //#region src/schema-parser/util/enum-key-resolver.ts
1042
1027
  var EnumKeyResolver = class extends NameResolver {
@@ -1049,7 +1034,6 @@ var EnumKeyResolver = class extends NameResolver {
1049
1034
  });
1050
1035
  }
1051
1036
  };
1052
-
1053
1037
  //#endregion
1054
1038
  //#region src/schema-parser/base-schema-parsers/enum.ts
1055
1039
  var EnumSchemaParser = class extends MonoSchemaParser {
@@ -1151,7 +1135,6 @@ var EnumSchemaParser = class extends MonoSchemaParser {
1151
1135
  return this.enumKeyResolver.resolve([formatted]);
1152
1136
  };
1153
1137
  };
1154
-
1155
1138
  //#endregion
1156
1139
  //#region src/schema-parser/base-schema-parsers/object.ts
1157
1140
  var ObjectSchemaParser = class extends MonoSchemaParser {
@@ -1220,7 +1203,6 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
1220
1203
  return propertiesContent;
1221
1204
  };
1222
1205
  };
1223
-
1224
1206
  //#endregion
1225
1207
  //#region src/schema-parser/base-schema-parsers/primitive.ts
1226
1208
  var PrimitiveSchemaParser = class extends MonoSchemaParser {
@@ -1241,7 +1223,8 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
1241
1223
  schemaPath: this.schemaPath
1242
1224
  }).getInlineParseContent();
1243
1225
  else recordValuesContent = this.config.Ts.Keyword.Any;
1244
- contentType = this.config.Ts.RecordType(recordKeysContent, recordValuesContent);
1226
+ const recordType = this.config.Ts.RecordType(recordKeysContent, recordValuesContent);
1227
+ contentType = propertyNamesSchema ? this.config.Ts.TypeWithGeneric("Partial", [recordType]) : recordType;
1245
1228
  }
1246
1229
  if (Array.isArray(type) && type.length) contentType = this.schemaParser._complexSchemaParsers.oneOf({
1247
1230
  ...typeof this.schema === "object" ? this.schema : {},
@@ -1269,7 +1252,6 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
1269
1252
  };
1270
1253
  }
1271
1254
  };
1272
-
1273
1255
  //#endregion
1274
1256
  //#region src/schema-parser/complex-schema-parsers/all-of.ts
1275
1257
  var AllOfSchemaParser = class extends MonoSchemaParser {
@@ -1281,7 +1263,6 @@ var AllOfSchemaParser = class extends MonoSchemaParser {
1281
1263
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1282
1264
  }
1283
1265
  };
1284
-
1285
1266
  //#endregion
1286
1267
  //#region src/schema-parser/complex-schema-parsers/any-of.ts
1287
1268
  var AnyOfSchemaParser = class extends MonoSchemaParser {
@@ -1293,7 +1274,6 @@ var AnyOfSchemaParser = class extends MonoSchemaParser {
1293
1274
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1294
1275
  }
1295
1276
  };
1296
-
1297
1277
  //#endregion
1298
1278
  //#region src/schema-parser/complex-schema-parsers/not.ts
1299
1279
  var NotSchemaParser = class extends MonoSchemaParser {
@@ -1301,7 +1281,6 @@ var NotSchemaParser = class extends MonoSchemaParser {
1301
1281
  return this.config.Ts.Keyword.Any;
1302
1282
  }
1303
1283
  };
1304
-
1305
1284
  //#endregion
1306
1285
  //#region src/schema-parser/complex-schema-parsers/one-of.ts
1307
1286
  var OneOfSchemaParser = class extends MonoSchemaParser {
@@ -1313,7 +1292,6 @@ var OneOfSchemaParser = class extends MonoSchemaParser {
1313
1292
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1314
1293
  }
1315
1294
  };
1316
-
1317
1295
  //#endregion
1318
1296
  //#region src/schema-parser/schema-parser.ts
1319
1297
  var SchemaParser = class {
@@ -1426,7 +1404,6 @@ var SchemaParser = class {
1426
1404
  };
1427
1405
  };
1428
1406
  };
1429
-
1430
1407
  //#endregion
1431
1408
  //#region src/schema-parser/schema-utils.ts
1432
1409
  var SchemaUtils = class {
@@ -1435,6 +1412,22 @@ var SchemaUtils = class {
1435
1412
  this.schemaComponentsMap = schemaComponentsMap;
1436
1413
  this.typeNameFormatter = typeNameFormatter;
1437
1414
  }
1415
+ isBinaryLikeContentMediaType = (contentMediaType) => {
1416
+ if (typeof contentMediaType !== "string" || !contentMediaType) return false;
1417
+ const mediaType = contentMediaType.split(";")[0]?.trim().toLowerCase();
1418
+ if (!mediaType) return false;
1419
+ /**
1420
+ * `contentMediaType` comes from JSON Schema. In practice it is often used to
1421
+ * signal "this string is a file/blob", but it may also be used for textual
1422
+ * payloads (json/xml/etc). We treat only binary-ish media types as `File`.
1423
+ */
1424
+ if (mediaType.startsWith("text/")) return false;
1425
+ if (mediaType.includes("json") || mediaType.includes("+json")) return false;
1426
+ if (mediaType.includes("xml") || mediaType.includes("+xml")) return false;
1427
+ if (mediaType === "application/x-www-form-urlencoded") return false;
1428
+ if (mediaType === "application/javascript" || mediaType === "application/ecmascript" || mediaType === "application/graphql" || mediaType === "application/yaml" || mediaType === "application/x-yaml") return false;
1429
+ return mediaType === "application/octet-stream" || mediaType.startsWith("image/") || mediaType.startsWith("audio/") || mediaType.startsWith("video/") || mediaType.startsWith("font/") || mediaType.startsWith("model/") || mediaType.startsWith("application/");
1430
+ };
1438
1431
  getRequiredProperties = (schema) => {
1439
1432
  return uniq(schema && Array.isArray(schema.required) && schema.required || []);
1440
1433
  };
@@ -1543,9 +1536,12 @@ var SchemaUtils = class {
1543
1536
  else {
1544
1537
  const primitiveType = this.getSchemaPrimitiveType(schema);
1545
1538
  if (primitiveType == null) return this.config.Ts.Keyword.Any;
1546
- const typeAlias = get(this.config.primitiveTypes, [primitiveType, schema.format]) || get(this.config.primitiveTypes, [primitiveType, "$default"]) || this.config.primitiveTypes[primitiveType];
1547
- if (typeof typeAlias === "function") resultType = typeAlias(schema, this);
1548
- else resultType = typeAlias || primitiveType;
1539
+ 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]);
1540
+ else {
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;
1544
+ }
1549
1545
  }
1550
1546
  if (!resultType) return this.config.Ts.Keyword.Any;
1551
1547
  return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, resultType));
@@ -1569,7 +1565,6 @@ var SchemaUtils = class {
1569
1565
  }
1570
1566
  };
1571
1567
  };
1572
-
1573
1568
  //#endregion
1574
1569
  //#region src/schema-parser/schema-parser-fabric.ts
1575
1570
  var SchemaParserFabric = class {
@@ -1639,11 +1634,9 @@ var SchemaParserFabric = class {
1639
1634
  }).getParseContent();
1640
1635
  };
1641
1636
  };
1642
-
1643
1637
  //#endregion
1644
1638
  //#region src/util/id.ts
1645
1639
  const generateId = () => crypto.randomUUID();
1646
-
1647
1640
  //#endregion
1648
1641
  //#region src/schema-routes/util/specific-arg-name-resolver.ts
1649
1642
  var SpecificArgNameResolver = class extends NameResolver {
@@ -1656,7 +1649,6 @@ var SpecificArgNameResolver = class extends NameResolver {
1656
1649
  });
1657
1650
  }
1658
1651
  };
1659
-
1660
1652
  //#endregion
1661
1653
  //#region src/schema-routes/schema-routes.ts
1662
1654
  const CONTENT_KIND = {
@@ -1979,7 +1971,7 @@ var SchemaRoutes = class {
1979
1971
  if (schema && schema.typeData && !schema.typeData.description && requestBody?.description) schema.typeData.description = requestBody.description;
1980
1972
  return {
1981
1973
  ...requestBody || {},
1982
- paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
1974
+ paramName: requestBodyName || requestBody?.name || "data",
1983
1975
  contentTypes,
1984
1976
  contentKind,
1985
1977
  schema,
@@ -2274,7 +2266,6 @@ var SchemaRoutes = class {
2274
2266
  return routes.slice().sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
2275
2267
  };
2276
2268
  };
2277
-
2278
2269
  //#endregion
2279
2270
  //#region src/resolved-swagger-schema.ts
2280
2271
  var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
@@ -2624,7 +2615,6 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2624
2615
  return resolvedSwaggerSchema;
2625
2616
  }
2626
2617
  };
2627
-
2628
2618
  //#endregion
2629
2619
  //#region src/util/request.ts
2630
2620
  var Request = class {
@@ -2645,7 +2635,6 @@ var Request = class {
2645
2635
  }
2646
2636
  }
2647
2637
  };
2648
-
2649
2638
  //#endregion
2650
2639
  //#region src/swagger-schema-resolver.ts
2651
2640
  var SwaggerSchemaResolver = class {
@@ -2757,7 +2746,6 @@ var SwaggerSchemaResolver = class {
2757
2746
  }
2758
2747
  }
2759
2748
  };
2760
-
2761
2749
  //#endregion
2762
2750
  //#region src/templates-worker.ts
2763
2751
  const require = module.createRequire(import.meta.url);
@@ -2845,7 +2833,6 @@ var TemplatesWorker = class {
2845
2833
  }, { includeFile: (path, configuration) => this.renderTemplate(this.getTemplateContent(path), configuration) });
2846
2834
  };
2847
2835
  };
2848
-
2849
2836
  //#endregion
2850
2837
  //#region src/translators/translator.ts
2851
2838
  var Translator = class {
@@ -2859,7 +2846,6 @@ var Translator = class {
2859
2846
  throw new Error("not implemented");
2860
2847
  }
2861
2848
  };
2862
-
2863
2849
  //#endregion
2864
2850
  //#region src/translators/javascript.ts
2865
2851
  var JavascriptTranslator = class extends Translator {
@@ -2900,7 +2886,6 @@ var JavascriptTranslator = class extends Translator {
2900
2886
  }];
2901
2887
  };
2902
2888
  };
2903
-
2904
2889
  //#endregion
2905
2890
  //#region src/type-name-formatter.ts
2906
2891
  var TypeNameFormatter = class {
@@ -2939,7 +2924,6 @@ var TypeNameFormatter = class {
2939
2924
  return name;
2940
2925
  };
2941
2926
  };
2942
-
2943
2927
  //#endregion
2944
2928
  //#region src/util/file-system.ts
2945
2929
  var FileSystem = class {
@@ -2991,7 +2975,6 @@ var FileSystem = class {
2991
2975
  return fs.writeFileSync(absolutePath, fileContent);
2992
2976
  };
2993
2977
  };
2994
-
2995
2978
  //#endregion
2996
2979
  //#region src/util/lodash-compat.ts
2997
2980
  function createLodashCompat() {
@@ -3000,7 +2983,6 @@ function createLodashCompat() {
3000
2983
  ...esToolkitCompat
3001
2984
  };
3002
2985
  }
3003
-
3004
2986
  //#endregion
3005
2987
  //#region src/code-gen-process.ts
3006
2988
  const PATCHABLE_INSTANCES = [
@@ -3290,7 +3272,6 @@ var CodeGenProcess = class {
3290
3272
  for (const instanceKey of PATCHABLE_INSTANCES) if (instanceKey !== key && key in this[instanceKey]) this[instanceKey][key] = value;
3291
3273
  };
3292
3274
  };
3293
-
3294
3275
  //#endregion
3295
3276
  //#region types/index.ts
3296
3277
  let RequestContentKind = /* @__PURE__ */ function(RequestContentKind) {
@@ -3316,7 +3297,6 @@ let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES) {
3316
3297
  SCHEMA_TYPES["COMPLEX_UNKNOWN"] = "__unknown";
3317
3298
  return SCHEMA_TYPES;
3318
3299
  }({});
3319
-
3320
3300
  //#endregion
3321
3301
  //#region src/commands/generate-templates/configuration.ts
3322
3302
  var TemplatesGenConfig = class {
@@ -3335,7 +3315,6 @@ var TemplatesGenConfig = class {
3335
3315
  objectAssign(this, update);
3336
3316
  };
3337
3317
  };
3338
-
3339
3318
  //#endregion
3340
3319
  //#region src/commands/generate-templates/templates-gen-process.ts
3341
3320
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
@@ -3437,7 +3416,6 @@ var TemplatesGenProcess = class {
3437
3416
  return this.fileSystem.getFileContent(path.resolve(this.rootDir, pathToFile));
3438
3417
  };
3439
3418
  };
3440
-
3441
3419
  //#endregion
3442
3420
  //#region src/commands/generate-templates/index.ts
3443
3421
  async function generateTemplates(config) {
@@ -3445,7 +3423,14 @@ async function generateTemplates(config) {
3445
3423
  if (config.silent) consola$1.level = 0;
3446
3424
  return await new TemplatesGenProcess(config).start();
3447
3425
  }
3448
-
3449
3426
  //#endregion
3450
- 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 };
3451
- //# sourceMappingURL=generate-templates-P84KxC-K.mjs.map
3427
+ //#region src/index.ts
3428
+ async function generateApi(config) {
3429
+ if (config.debug) consola$1.level = Number.MAX_SAFE_INTEGER;
3430
+ if (config.silent) consola$1.level = 0;
3431
+ return await new CodeGenProcess(config).start();
3432
+ }
3433
+ //#endregion
3434
+ 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 };
3435
+
3436
+ //# sourceMappingURL=src-eXqnNGnl.mjs.map