swagger-typescript-api 13.3.1 → 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-P84KxC-K.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.1";
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 {
@@ -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,7 +1222,8 @@ 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 : {},
@@ -1269,7 +1251,6 @@ var PrimitiveSchemaParser = class extends MonoSchemaParser {
1269
1251
  };
1270
1252
  }
1271
1253
  };
1272
-
1273
1254
  //#endregion
1274
1255
  //#region src/schema-parser/complex-schema-parsers/all-of.ts
1275
1256
  var AllOfSchemaParser = class extends MonoSchemaParser {
@@ -1281,7 +1262,6 @@ var AllOfSchemaParser = class extends MonoSchemaParser {
1281
1262
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1282
1263
  }
1283
1264
  };
1284
-
1285
1265
  //#endregion
1286
1266
  //#region src/schema-parser/complex-schema-parsers/any-of.ts
1287
1267
  var AnyOfSchemaParser = class extends MonoSchemaParser {
@@ -1293,7 +1273,6 @@ var AnyOfSchemaParser = class extends MonoSchemaParser {
1293
1273
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1294
1274
  }
1295
1275
  };
1296
-
1297
1276
  //#endregion
1298
1277
  //#region src/schema-parser/complex-schema-parsers/not.ts
1299
1278
  var NotSchemaParser = class extends MonoSchemaParser {
@@ -1301,7 +1280,6 @@ var NotSchemaParser = class extends MonoSchemaParser {
1301
1280
  return this.config.Ts.Keyword.Any;
1302
1281
  }
1303
1282
  };
1304
-
1305
1283
  //#endregion
1306
1284
  //#region src/schema-parser/complex-schema-parsers/one-of.ts
1307
1285
  var OneOfSchemaParser = class extends MonoSchemaParser {
@@ -1313,7 +1291,6 @@ var OneOfSchemaParser = class extends MonoSchemaParser {
1313
1291
  return this.schemaUtils.safeAddNullToType(this.schema, type);
1314
1292
  }
1315
1293
  };
1316
-
1317
1294
  //#endregion
1318
1295
  //#region src/schema-parser/schema-parser.ts
1319
1296
  var SchemaParser = class {
@@ -1426,7 +1403,6 @@ var SchemaParser = class {
1426
1403
  };
1427
1404
  };
1428
1405
  };
1429
-
1430
1406
  //#endregion
1431
1407
  //#region src/schema-parser/schema-utils.ts
1432
1408
  var SchemaUtils = class {
@@ -1435,6 +1411,22 @@ var SchemaUtils = class {
1435
1411
  this.schemaComponentsMap = schemaComponentsMap;
1436
1412
  this.typeNameFormatter = typeNameFormatter;
1437
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
+ };
1438
1430
  getRequiredProperties = (schema) => {
1439
1431
  return uniq(schema && Array.isArray(schema.required) && schema.required || []);
1440
1432
  };
@@ -1543,9 +1535,12 @@ var SchemaUtils = class {
1543
1535
  else {
1544
1536
  const primitiveType = this.getSchemaPrimitiveType(schema);
1545
1537
  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;
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
+ }
1549
1544
  }
1550
1545
  if (!resultType) return this.config.Ts.Keyword.Any;
1551
1546
  return this.checkAndAddRequiredKeys(schema, this.safeAddNullToType(schema, resultType));
@@ -1569,7 +1564,6 @@ var SchemaUtils = class {
1569
1564
  }
1570
1565
  };
1571
1566
  };
1572
-
1573
1567
  //#endregion
1574
1568
  //#region src/schema-parser/schema-parser-fabric.ts
1575
1569
  var SchemaParserFabric = class {
@@ -1639,11 +1633,9 @@ var SchemaParserFabric = class {
1639
1633
  }).getParseContent();
1640
1634
  };
1641
1635
  };
1642
-
1643
1636
  //#endregion
1644
1637
  //#region src/util/id.ts
1645
1638
  const generateId = () => crypto.randomUUID();
1646
-
1647
1639
  //#endregion
1648
1640
  //#region src/schema-routes/util/specific-arg-name-resolver.ts
1649
1641
  var SpecificArgNameResolver = class extends NameResolver {
@@ -1656,7 +1648,6 @@ var SpecificArgNameResolver = class extends NameResolver {
1656
1648
  });
1657
1649
  }
1658
1650
  };
1659
-
1660
1651
  //#endregion
1661
1652
  //#region src/schema-routes/schema-routes.ts
1662
1653
  const CONTENT_KIND = {
@@ -1979,7 +1970,7 @@ var SchemaRoutes = class {
1979
1970
  if (schema && schema.typeData && !schema.typeData.description && requestBody?.description) schema.typeData.description = requestBody.description;
1980
1971
  return {
1981
1972
  ...requestBody || {},
1982
- paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
1973
+ paramName: requestBodyName || requestBody?.name || "data",
1983
1974
  contentTypes,
1984
1975
  contentKind,
1985
1976
  schema,
@@ -2274,7 +2265,6 @@ var SchemaRoutes = class {
2274
2265
  return routes.slice().sort((routeA, routeB) => routeA.routeName.usage.localeCompare(routeB.routeName.usage));
2275
2266
  };
2276
2267
  };
2277
-
2278
2268
  //#endregion
2279
2269
  //#region src/resolved-swagger-schema.ts
2280
2270
  var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
@@ -2624,7 +2614,6 @@ var ResolvedSwaggerSchema = class ResolvedSwaggerSchema {
2624
2614
  return resolvedSwaggerSchema;
2625
2615
  }
2626
2616
  };
2627
-
2628
2617
  //#endregion
2629
2618
  //#region src/util/request.ts
2630
2619
  var Request = class {
@@ -2645,7 +2634,6 @@ var Request = class {
2645
2634
  }
2646
2635
  }
2647
2636
  };
2648
-
2649
2637
  //#endregion
2650
2638
  //#region src/swagger-schema-resolver.ts
2651
2639
  var SwaggerSchemaResolver = class {
@@ -2757,7 +2745,6 @@ var SwaggerSchemaResolver = class {
2757
2745
  }
2758
2746
  }
2759
2747
  };
2760
-
2761
2748
  //#endregion
2762
2749
  //#region src/templates-worker.ts
2763
2750
  const require = module.createRequire(import.meta.url);
@@ -2845,7 +2832,6 @@ var TemplatesWorker = class {
2845
2832
  }, { includeFile: (path, configuration) => this.renderTemplate(this.getTemplateContent(path), configuration) });
2846
2833
  };
2847
2834
  };
2848
-
2849
2835
  //#endregion
2850
2836
  //#region src/translators/translator.ts
2851
2837
  var Translator = class {
@@ -2859,7 +2845,6 @@ var Translator = class {
2859
2845
  throw new Error("not implemented");
2860
2846
  }
2861
2847
  };
2862
-
2863
2848
  //#endregion
2864
2849
  //#region src/translators/javascript.ts
2865
2850
  var JavascriptTranslator = class extends Translator {
@@ -2900,7 +2885,6 @@ var JavascriptTranslator = class extends Translator {
2900
2885
  }];
2901
2886
  };
2902
2887
  };
2903
-
2904
2888
  //#endregion
2905
2889
  //#region src/type-name-formatter.ts
2906
2890
  var TypeNameFormatter = class {
@@ -2939,7 +2923,6 @@ var TypeNameFormatter = class {
2939
2923
  return name;
2940
2924
  };
2941
2925
  };
2942
-
2943
2926
  //#endregion
2944
2927
  //#region src/util/file-system.ts
2945
2928
  var FileSystem = class {
@@ -2991,7 +2974,6 @@ var FileSystem = class {
2991
2974
  return fs.writeFileSync(absolutePath, fileContent);
2992
2975
  };
2993
2976
  };
2994
-
2995
2977
  //#endregion
2996
2978
  //#region src/util/lodash-compat.ts
2997
2979
  function createLodashCompat() {
@@ -3000,7 +2982,6 @@ function createLodashCompat() {
3000
2982
  ...esToolkitCompat
3001
2983
  };
3002
2984
  }
3003
-
3004
2985
  //#endregion
3005
2986
  //#region src/code-gen-process.ts
3006
2987
  const PATCHABLE_INSTANCES = [
@@ -3290,7 +3271,6 @@ var CodeGenProcess = class {
3290
3271
  for (const instanceKey of PATCHABLE_INSTANCES) if (instanceKey !== key && key in this[instanceKey]) this[instanceKey][key] = value;
3291
3272
  };
3292
3273
  };
3293
-
3294
3274
  //#endregion
3295
3275
  //#region types/index.ts
3296
3276
  let RequestContentKind = /* @__PURE__ */ function(RequestContentKind) {
@@ -3316,7 +3296,6 @@ let SCHEMA_TYPES = /* @__PURE__ */ function(SCHEMA_TYPES) {
3316
3296
  SCHEMA_TYPES["COMPLEX_UNKNOWN"] = "__unknown";
3317
3297
  return SCHEMA_TYPES;
3318
3298
  }({});
3319
-
3320
3299
  //#endregion
3321
3300
  //#region src/commands/generate-templates/configuration.ts
3322
3301
  var TemplatesGenConfig = class {
@@ -3335,7 +3314,6 @@ var TemplatesGenConfig = class {
3335
3314
  objectAssign(this, update);
3336
3315
  };
3337
3316
  };
3338
-
3339
3317
  //#endregion
3340
3318
  //#region src/commands/generate-templates/templates-gen-process.ts
3341
3319
  const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
@@ -3437,7 +3415,6 @@ var TemplatesGenProcess = class {
3437
3415
  return this.fileSystem.getFileContent(path.resolve(this.rootDir, pathToFile));
3438
3416
  };
3439
3417
  };
3440
-
3441
3418
  //#endregion
3442
3419
  //#region src/commands/generate-templates/index.ts
3443
3420
  async function generateTemplates(config) {
@@ -3445,7 +3422,14 @@ async function generateTemplates(config) {
3445
3422
  if (config.silent) consola$1.level = 0;
3446
3423
  return await new TemplatesGenProcess(config).start();
3447
3424
  }
3448
-
3449
3425
  //#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
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