@orval/core 8.8.0 → 8.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-BpYLSNr0.mjs +14 -0
- package/dist/index.d.mts +16 -3
- package/dist/index.mjs +97 -127
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-C7Uep-_p.mjs +0 -20
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-
|
|
1
|
+
import { t as __exportAll } from "./chunk-BpYLSNr0.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { entries, groupBy, isArray, isBoolean, isBoolean as isBoolean$1, isEmptyish, isFunction, isNullish, isNullish as isNullish$1, isNumber, isString, isString as isString$1, prop, unique, uniqueBy, uniqueWith } from "remeda";
|
|
4
4
|
import { keyword } from "esutils";
|
|
5
|
-
import
|
|
5
|
+
import nodePath from "node:path";
|
|
6
6
|
import { compare } from "compare-versions";
|
|
7
7
|
import debug from "debug";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
@@ -15,7 +15,6 @@ import { isDereferenced } from "@scalar/openapi-types/helpers";
|
|
|
15
15
|
import fs$1 from "fs-extra";
|
|
16
16
|
import { Parser } from "acorn";
|
|
17
17
|
import { build } from "esbuild";
|
|
18
|
-
|
|
19
18
|
//#region src/types.ts
|
|
20
19
|
const SupportedFormatter = {
|
|
21
20
|
PRETTIER: "prettier",
|
|
@@ -103,7 +102,6 @@ var ErrorWithTag = class extends Error {
|
|
|
103
102
|
this.tag = tag;
|
|
104
103
|
}
|
|
105
104
|
};
|
|
106
|
-
|
|
107
105
|
//#endregion
|
|
108
106
|
//#region src/constants.ts
|
|
109
107
|
const generalJSTypes = [
|
|
@@ -128,7 +126,6 @@ const VERBS_WITH_BODY = [
|
|
|
128
126
|
];
|
|
129
127
|
const URL_REGEX = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+$/;
|
|
130
128
|
const TEMPLATE_TAG_REGEX = /\${(.+?)}/g;
|
|
131
|
-
|
|
132
129
|
//#endregion
|
|
133
130
|
//#region src/utils/assertion.ts
|
|
134
131
|
/**
|
|
@@ -140,7 +137,7 @@ function isReference(obj) {
|
|
|
140
137
|
return !isNullish$1(obj) && Object.hasOwn(obj, "$ref");
|
|
141
138
|
}
|
|
142
139
|
function isDirectory(pathValue) {
|
|
143
|
-
return !
|
|
140
|
+
return !nodePath.extname(pathValue);
|
|
144
141
|
}
|
|
145
142
|
function isObject(x) {
|
|
146
143
|
return Object.prototype.toString.call(x) === "[object Object]";
|
|
@@ -176,7 +173,6 @@ function isUrl(str) {
|
|
|
176
173
|
return false;
|
|
177
174
|
}
|
|
178
175
|
}
|
|
179
|
-
|
|
180
176
|
//#endregion
|
|
181
177
|
//#region src/utils/async-reduce.ts
|
|
182
178
|
async function asyncReduce(array, reducer, initValue) {
|
|
@@ -184,7 +180,6 @@ async function asyncReduce(array, reducer, initValue) {
|
|
|
184
180
|
for (const item of array) accumulate = await reducer(accumulate, item);
|
|
185
181
|
return accumulate;
|
|
186
182
|
}
|
|
187
|
-
|
|
188
183
|
//#endregion
|
|
189
184
|
//#region src/utils/case.ts
|
|
190
185
|
const unicodes = function(s, prefix = "") {
|
|
@@ -275,7 +270,6 @@ function conventionName(name, convention) {
|
|
|
275
270
|
}
|
|
276
271
|
return nameConventionTransform(name);
|
|
277
272
|
}
|
|
278
|
-
|
|
279
273
|
//#endregion
|
|
280
274
|
//#region src/utils/compare-version.ts
|
|
281
275
|
function compareVersions(firstVersion, secondVersions, operator = ">=") {
|
|
@@ -283,7 +277,6 @@ function compareVersions(firstVersion, secondVersions, operator = ">=") {
|
|
|
283
277
|
if (firstVersion.startsWith("catalog:")) return true;
|
|
284
278
|
return compare(firstVersion.replace(/(\s(.*))/, ""), secondVersions, operator);
|
|
285
279
|
}
|
|
286
|
-
|
|
287
280
|
//#endregion
|
|
288
281
|
//#region src/utils/content-type.ts
|
|
289
282
|
const binaryApplicationTypes = new Set(["application/octet-stream", "application/pdf"]);
|
|
@@ -346,7 +339,6 @@ function filterByContentType(items, filter) {
|
|
|
346
339
|
return shouldInclude && !shouldExclude;
|
|
347
340
|
});
|
|
348
341
|
}
|
|
349
|
-
|
|
350
342
|
//#endregion
|
|
351
343
|
//#region src/utils/debug.ts
|
|
352
344
|
const filter = process.env.ORVAL_DEBUG_FILTER;
|
|
@@ -361,7 +353,6 @@ function createDebugger(ns, options = {}) {
|
|
|
361
353
|
log(msg, ...args);
|
|
362
354
|
};
|
|
363
355
|
}
|
|
364
|
-
|
|
365
356
|
//#endregion
|
|
366
357
|
//#region src/utils/doc.ts
|
|
367
358
|
const search = String.raw`\*/`;
|
|
@@ -442,7 +433,6 @@ function keyValuePairsToJsDoc(keyValues) {
|
|
|
442
433
|
doc += " */\n";
|
|
443
434
|
return doc;
|
|
444
435
|
}
|
|
445
|
-
|
|
446
436
|
//#endregion
|
|
447
437
|
//#region src/utils/dynamic-import.ts
|
|
448
438
|
const TS_MODULE_EXTENSIONS = new Set([
|
|
@@ -456,8 +446,8 @@ async function dynamicImport(toImport, from = process.cwd(), takeDefault = true)
|
|
|
456
446
|
if (!toImport) return toImport;
|
|
457
447
|
try {
|
|
458
448
|
if (isString(toImport)) {
|
|
459
|
-
const filePath =
|
|
460
|
-
const extension =
|
|
449
|
+
const filePath = nodePath.resolve(from, toImport);
|
|
450
|
+
const extension = nodePath.extname(filePath);
|
|
461
451
|
if (TS_MODULE_EXTENSIONS.has(extension)) {
|
|
462
452
|
const data = await createJiti(from, { interopDefault: true }).import(filePath);
|
|
463
453
|
if (takeDefault && (isObject(data) || isModule(data)) && data.default) return data.default;
|
|
@@ -473,25 +463,23 @@ async function dynamicImport(toImport, from = process.cwd(), takeDefault = true)
|
|
|
473
463
|
throw new Error(`Oups... 🍻. Path: ${String(toImport)} => ${String(error)}`, { cause: error });
|
|
474
464
|
}
|
|
475
465
|
}
|
|
476
|
-
|
|
477
466
|
//#endregion
|
|
478
467
|
//#region src/utils/extension.ts
|
|
479
468
|
function getExtension(path) {
|
|
480
469
|
return path.toLowerCase().includes(".yaml") || path.toLowerCase().includes(".yml") ? "yaml" : "json";
|
|
481
470
|
}
|
|
482
|
-
|
|
483
471
|
//#endregion
|
|
484
472
|
//#region src/utils/file.ts
|
|
485
473
|
function getFileInfo(target = "", { backupFilename = "filename", extension = ".ts" } = {}) {
|
|
486
474
|
const isDir = isDirectory(target);
|
|
487
|
-
const filePath = isDir ?
|
|
475
|
+
const filePath = isDir ? nodePath.join(target, backupFilename + extension) : target;
|
|
488
476
|
return {
|
|
489
477
|
path: filePath,
|
|
490
478
|
pathWithoutExtension: filePath.replace(/\.[^/.]+$/, ""),
|
|
491
479
|
extension,
|
|
492
480
|
isDirectory: isDir,
|
|
493
|
-
dirname:
|
|
494
|
-
filename:
|
|
481
|
+
dirname: nodePath.dirname(filePath),
|
|
482
|
+
filename: nodePath.basename(filePath, extension.startsWith(".") ? extension : `.${extension}`)
|
|
495
483
|
};
|
|
496
484
|
}
|
|
497
485
|
async function removeFilesAndEmptyFolders(patterns, dir) {
|
|
@@ -512,7 +500,6 @@ async function removeFilesAndEmptyFolders(patterns, dir) {
|
|
|
512
500
|
if ((await fs.promises.readdir(directory)).length === 0) await fs.promises.rmdir(directory);
|
|
513
501
|
} catch {}
|
|
514
502
|
}
|
|
515
|
-
|
|
516
503
|
//#endregion
|
|
517
504
|
//#region src/utils/file-extensions.ts
|
|
518
505
|
function getMockFileExtensionByTypeName(mock) {
|
|
@@ -521,7 +508,6 @@ function getMockFileExtensionByTypeName(mock) {
|
|
|
521
508
|
default: return "msw";
|
|
522
509
|
}
|
|
523
510
|
}
|
|
524
|
-
|
|
525
511
|
//#endregion
|
|
526
512
|
//#region src/utils/get-property-safe.ts
|
|
527
513
|
/**
|
|
@@ -543,13 +529,11 @@ function getPropertySafe(obj, propertyName) {
|
|
|
543
529
|
value: void 0
|
|
544
530
|
};
|
|
545
531
|
}
|
|
546
|
-
|
|
547
532
|
//#endregion
|
|
548
533
|
//#region src/utils/is-body-verb.ts
|
|
549
534
|
function getIsBodyVerb(verb) {
|
|
550
535
|
return VERBS_WITH_BODY.includes(verb);
|
|
551
536
|
}
|
|
552
|
-
|
|
553
537
|
//#endregion
|
|
554
538
|
//#region src/utils/logger.ts
|
|
555
539
|
const log = console.log;
|
|
@@ -666,7 +650,6 @@ function createLogger(level = "info", options = {}) {
|
|
|
666
650
|
};
|
|
667
651
|
return logger;
|
|
668
652
|
}
|
|
669
|
-
|
|
670
653
|
//#endregion
|
|
671
654
|
//#region src/utils/merge-deep.ts
|
|
672
655
|
function mergeDeep(source, target) {
|
|
@@ -680,14 +663,12 @@ function mergeDeep(source, target) {
|
|
|
680
663
|
}
|
|
681
664
|
return acc;
|
|
682
665
|
}
|
|
683
|
-
|
|
684
666
|
//#endregion
|
|
685
667
|
//#region src/utils/occurrence.ts
|
|
686
668
|
function count(str = "", key) {
|
|
687
669
|
if (!str) return 0;
|
|
688
670
|
return (str.match(new RegExp(key, "g")) ?? []).length;
|
|
689
671
|
}
|
|
690
|
-
|
|
691
672
|
//#endregion
|
|
692
673
|
//#region src/utils/path.ts
|
|
693
674
|
var path_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -697,7 +678,7 @@ var path_exports = /* @__PURE__ */ __exportAll({
|
|
|
697
678
|
joinSafe: () => joinSafe,
|
|
698
679
|
normalizeSafe: () => normalizeSafe,
|
|
699
680
|
relativeSafe: () => relativeSafe,
|
|
700
|
-
separator: () =>
|
|
681
|
+
separator: () => "/",
|
|
701
682
|
toUnix: () => toUnix
|
|
702
683
|
});
|
|
703
684
|
function toUnix(value) {
|
|
@@ -706,28 +687,27 @@ function toUnix(value) {
|
|
|
706
687
|
return value;
|
|
707
688
|
}
|
|
708
689
|
function join(...args) {
|
|
709
|
-
return toUnix(
|
|
690
|
+
return toUnix(nodePath.join(...args.map((a) => toUnix(a))));
|
|
710
691
|
}
|
|
711
692
|
/**
|
|
712
693
|
* Behaves exactly like `path.relative(from, to)`, but keeps the first meaningful "./"
|
|
713
694
|
*/
|
|
714
695
|
function relativeSafe(from, to) {
|
|
715
|
-
return normalizeSafe(
|
|
696
|
+
return normalizeSafe(`./${toUnix(nodePath.relative(toUnix(from), toUnix(to)))}`);
|
|
716
697
|
}
|
|
717
698
|
function getSchemaFileName(path) {
|
|
718
699
|
return path.replace(`.${getExtension(path)}`, "").slice(path.lastIndexOf("/") + 1);
|
|
719
700
|
}
|
|
720
|
-
const separator = "/";
|
|
721
701
|
function normalizeSafe(value) {
|
|
722
702
|
let result;
|
|
723
703
|
value = toUnix(value);
|
|
724
|
-
result = toUnix(
|
|
704
|
+
result = toUnix(nodePath.normalize(value));
|
|
725
705
|
if (value.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
726
706
|
else if (value.startsWith("//") && !result.startsWith("//")) result = value.startsWith("//./") ? "//." + result : "/" + result;
|
|
727
707
|
return result;
|
|
728
708
|
}
|
|
729
709
|
function joinSafe(...values) {
|
|
730
|
-
let result = toUnix(
|
|
710
|
+
let result = toUnix(nodePath.join(...values.map((v) => toUnix(v))));
|
|
731
711
|
if (values.length > 0) {
|
|
732
712
|
const firstValue = toUnix(values[0]);
|
|
733
713
|
if (firstValue.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
@@ -758,37 +738,36 @@ function joinSafe(...values) {
|
|
|
758
738
|
* @returns The relative import path string.
|
|
759
739
|
*/
|
|
760
740
|
function getRelativeImportPath(importerFilePath, exporterFilePath, includeFileExtension = false) {
|
|
761
|
-
if (!
|
|
762
|
-
if (!
|
|
763
|
-
const importerDir =
|
|
764
|
-
const relativePath =
|
|
765
|
-
let posixPath =
|
|
741
|
+
if (!nodePath.isAbsolute(importerFilePath)) throw new Error(`'importerFilePath' is not an absolute path. "${importerFilePath}"`);
|
|
742
|
+
if (!nodePath.isAbsolute(exporterFilePath)) throw new Error(`'exporterFilePath' is not an absolute path. "${exporterFilePath}"`);
|
|
743
|
+
const importerDir = nodePath.dirname(importerFilePath);
|
|
744
|
+
const relativePath = nodePath.relative(importerDir, exporterFilePath);
|
|
745
|
+
let posixPath = nodePath.posix.join(...relativePath.split(nodePath.sep));
|
|
766
746
|
if (!posixPath.startsWith("./") && !posixPath.startsWith("../")) posixPath = `./${posixPath}`;
|
|
767
747
|
if (!includeFileExtension) {
|
|
768
|
-
const ext =
|
|
748
|
+
const ext = nodePath.extname(posixPath);
|
|
769
749
|
if (ext && posixPath.endsWith(ext)) posixPath = posixPath.slice(0, -ext.length);
|
|
770
750
|
}
|
|
771
751
|
return posixPath;
|
|
772
752
|
}
|
|
773
|
-
|
|
774
753
|
//#endregion
|
|
775
754
|
//#region src/utils/resolve-version.ts
|
|
776
755
|
function resolveInstalledVersion(packageName, fromDir) {
|
|
777
756
|
try {
|
|
778
|
-
const require = createRequire(
|
|
757
|
+
const require = createRequire(nodePath.join(fromDir, "noop.js"));
|
|
779
758
|
try {
|
|
780
759
|
return require(`${packageName}/package.json`).version;
|
|
781
760
|
} catch (directError) {
|
|
782
761
|
if (directError instanceof Error && "code" in directError && directError.code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
783
762
|
const entryPath = require.resolve(packageName);
|
|
784
|
-
let dir =
|
|
785
|
-
while (dir !==
|
|
786
|
-
const pkgPath =
|
|
763
|
+
let dir = nodePath.dirname(entryPath);
|
|
764
|
+
while (dir !== nodePath.parse(dir).root) {
|
|
765
|
+
const pkgPath = nodePath.join(dir, "package.json");
|
|
787
766
|
if (existsSync(pkgPath)) {
|
|
788
767
|
const pkgData = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
789
768
|
if (pkgData.name === packageName) return pkgData.version;
|
|
790
769
|
}
|
|
791
|
-
dir =
|
|
770
|
+
dir = nodePath.dirname(dir);
|
|
792
771
|
}
|
|
793
772
|
return;
|
|
794
773
|
}
|
|
@@ -811,7 +790,6 @@ function resolveInstalledVersions(packageJson, fromDir) {
|
|
|
811
790
|
}
|
|
812
791
|
return resolved;
|
|
813
792
|
}
|
|
814
|
-
|
|
815
793
|
//#endregion
|
|
816
794
|
//#region src/utils/sort.ts
|
|
817
795
|
const sortByPriority = (arr) => arr.toSorted((a, b) => {
|
|
@@ -822,7 +800,6 @@ const sortByPriority = (arr) => arr.toSorted((a, b) => {
|
|
|
822
800
|
if (b.required) return 1;
|
|
823
801
|
return 0;
|
|
824
802
|
});
|
|
825
|
-
|
|
826
803
|
//#endregion
|
|
827
804
|
//#region src/utils/string.ts
|
|
828
805
|
/**
|
|
@@ -1014,14 +991,12 @@ function dedupeUnionType(unionType) {
|
|
|
1014
991
|
if (current.trim()) parts.push(current.trim());
|
|
1015
992
|
return [...new Set(parts)].join(" | ");
|
|
1016
993
|
}
|
|
1017
|
-
|
|
1018
994
|
//#endregion
|
|
1019
995
|
//#region src/utils/tsconfig.ts
|
|
1020
996
|
function isSyntheticDefaultImportsAllow(config) {
|
|
1021
997
|
if (!config) return true;
|
|
1022
998
|
return !!(config.compilerOptions?.allowSyntheticDefaultImports ?? config.compilerOptions?.esModuleInterop);
|
|
1023
999
|
}
|
|
1024
|
-
|
|
1025
1000
|
//#endregion
|
|
1026
1001
|
//#region src/getters/enum.ts
|
|
1027
1002
|
/**
|
|
@@ -1221,7 +1196,6 @@ function getCombinedEnumValue(inputs) {
|
|
|
1221
1196
|
hasNull
|
|
1222
1197
|
};
|
|
1223
1198
|
}
|
|
1224
|
-
|
|
1225
1199
|
//#endregion
|
|
1226
1200
|
//#region src/getters/ref.ts
|
|
1227
1201
|
const RefComponentSuffix = {
|
|
@@ -1267,7 +1241,6 @@ function getRefInfo($ref, context) {
|
|
|
1267
1241
|
refPaths
|
|
1268
1242
|
};
|
|
1269
1243
|
}
|
|
1270
|
-
|
|
1271
1244
|
//#endregion
|
|
1272
1245
|
//#region src/resolvers/ref.ts
|
|
1273
1246
|
const REF_NOT_FOUND_PREFIX = "Oops... 🍻. Ref not found";
|
|
@@ -1369,7 +1342,6 @@ function resolveExampleRefs(examples, context) {
|
|
|
1369
1342
|
return result;
|
|
1370
1343
|
})();
|
|
1371
1344
|
}
|
|
1372
|
-
|
|
1373
1345
|
//#endregion
|
|
1374
1346
|
//#region src/resolvers/value.ts
|
|
1375
1347
|
function resolveValue({ schema, name, context, formDataContext }) {
|
|
@@ -1415,7 +1387,6 @@ function resolveValue({ schema, name, context, formDataContext }) {
|
|
|
1415
1387
|
isRef: false
|
|
1416
1388
|
};
|
|
1417
1389
|
}
|
|
1418
|
-
|
|
1419
1390
|
//#endregion
|
|
1420
1391
|
//#region src/resolvers/object.ts
|
|
1421
1392
|
/**
|
|
@@ -1509,7 +1480,6 @@ function resolveObject({ schema, propName, combined = false, context, formDataCo
|
|
|
1509
1480
|
resolveObjectCacheMap.set(hashKey, result);
|
|
1510
1481
|
return result;
|
|
1511
1482
|
}
|
|
1512
|
-
|
|
1513
1483
|
//#endregion
|
|
1514
1484
|
//#region src/getters/array.ts
|
|
1515
1485
|
/**
|
|
@@ -1584,7 +1554,6 @@ function getArray({ schema, name, context, formDataContext }) {
|
|
|
1584
1554
|
};
|
|
1585
1555
|
else throw new Error(`All arrays must have an \`items\` key defined (name=${name}, schema=${JSON.stringify(schema)})`);
|
|
1586
1556
|
}
|
|
1587
|
-
|
|
1588
1557
|
//#endregion
|
|
1589
1558
|
//#region src/getters/res-req-types.ts
|
|
1590
1559
|
const getSchemaType = (s) => s.type;
|
|
@@ -1709,6 +1678,17 @@ function getResReqTypes(responsesOrRequests, name, context, defaultType = "unkno
|
|
|
1709
1678
|
if (mediaType.schema && isReference(mediaType.schema)) {
|
|
1710
1679
|
const { imports } = resolveSchemaRef(mediaType.schema, context);
|
|
1711
1680
|
if (imports[0]?.name) effectivePropName = imports[0].name;
|
|
1681
|
+
} else if (mediaType.schema) {
|
|
1682
|
+
const combinedRefs = getSchemaOneOf(mediaType.schema) ?? getSchemaAnyOf(mediaType.schema);
|
|
1683
|
+
if (combinedRefs) {
|
|
1684
|
+
const names = [];
|
|
1685
|
+
for (const ref of combinedRefs) {
|
|
1686
|
+
if (!isReference(ref)) continue;
|
|
1687
|
+
const refName = resolveSchemaRef(ref, context).imports[0]?.name;
|
|
1688
|
+
if (refName) names.push(refName);
|
|
1689
|
+
}
|
|
1690
|
+
if (names.length > 0) effectivePropName = names.join("");
|
|
1691
|
+
}
|
|
1712
1692
|
}
|
|
1713
1693
|
const isFormData = formDataContentTypes.has(contentType);
|
|
1714
1694
|
const resolvedValue = getResReqContentTypes({
|
|
@@ -1846,26 +1826,45 @@ function getFormDataAdditionalImports({ schemaObject, context }) {
|
|
|
1846
1826
|
function getSchemaFormDataAndUrlEncoded({ name, schemaObject, context, isRequestBodyOptional, isUrlEncoded, isRef, encoding }) {
|
|
1847
1827
|
const { schema, imports } = resolveSchemaRef(schemaObject, context);
|
|
1848
1828
|
const propName = camel(!isRef && isReference(schemaObject) ? imports[0].name : name);
|
|
1849
|
-
const additionalImports = [];
|
|
1850
1829
|
const variableName = isUrlEncoded ? "formUrlEncoded" : "formData";
|
|
1851
1830
|
let form = isUrlEncoded ? `const ${variableName} = new URLSearchParams();\n` : `const ${variableName} = new FormData();\n`;
|
|
1852
1831
|
const combinedSchemas = getSchemaCombined(schema);
|
|
1853
1832
|
if (schema.type === "object" || schema.type === void 0 && combinedSchemas) {
|
|
1854
|
-
if (combinedSchemas) {
|
|
1855
|
-
const
|
|
1833
|
+
if (combinedSchemas) if (!!getSchemaOneOf(schema) || !!getSchemaAnyOf(schema)) {
|
|
1834
|
+
const directProperties = getSchemaProperties(schema);
|
|
1835
|
+
const directKeys = directProperties ? Object.entries(directProperties).filter(([, value]) => !resolveSchemaRef(value, context).schema.readOnly).map(([key]) => key) : [];
|
|
1836
|
+
const skipLine = directKeys.length > 0 ? ` if ([${directKeys.map((k) => JSON.stringify(k)).join(", ")}].includes(key)) return;\n` : "";
|
|
1837
|
+
form += `Object.entries(${propName} ?? {}).forEach(([key, value]) => {\n`;
|
|
1838
|
+
form += skipLine;
|
|
1839
|
+
form += ` if (value !== undefined && value !== null) {\n`;
|
|
1840
|
+
form += ` if ((typeof File !== 'undefined' && value instanceof File) || value instanceof Blob) {\n`;
|
|
1841
|
+
form += ` ${variableName}.append(key, value);\n`;
|
|
1842
|
+
form += ` } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {\n`;
|
|
1843
|
+
form += ` ${variableName}.append(key, new Blob([Uint8Array.from(value)]));\n`;
|
|
1844
|
+
form += ` } else if (Array.isArray(value)) {\n`;
|
|
1845
|
+
form += ` value.forEach(v => {\n`;
|
|
1846
|
+
form += ` if ((typeof File !== 'undefined' && v instanceof File) || v instanceof Blob) {\n`;
|
|
1847
|
+
form += ` ${variableName}.append(key, v);\n`;
|
|
1848
|
+
form += ` } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(v)) {\n`;
|
|
1849
|
+
form += ` ${variableName}.append(key, new Blob([Uint8Array.from(v)]));\n`;
|
|
1850
|
+
form += ` } else {\n`;
|
|
1851
|
+
form += ` ${variableName}.append(key, typeof v === 'object' ? JSON.stringify(v) : String(v));\n`;
|
|
1852
|
+
form += ` }\n`;
|
|
1853
|
+
form += ` });\n`;
|
|
1854
|
+
form += ` } else if (typeof value === 'object') {\n`;
|
|
1855
|
+
form += ` ${variableName}.append(key, JSON.stringify(value));\n`;
|
|
1856
|
+
form += ` } else {\n`;
|
|
1857
|
+
form += ` ${variableName}.append(key, String(value));\n`;
|
|
1858
|
+
form += ` }\n`;
|
|
1859
|
+
form += ` }\n`;
|
|
1860
|
+
form += `});\n`;
|
|
1861
|
+
} else {
|
|
1856
1862
|
const combinedSchemasFormData = combinedSchemas.map((subSchema) => {
|
|
1857
|
-
const { schema: combinedSchema
|
|
1858
|
-
|
|
1859
|
-
let newPropDefinition = "";
|
|
1860
|
-
if (shouldCast && imports[0]) {
|
|
1861
|
-
additionalImports.push(imports[0]);
|
|
1862
|
-
newPropName = `${propName}${pascal(imports[0].name)}`;
|
|
1863
|
-
newPropDefinition = `const ${newPropName} = (${propName} as ${imports[0].name}${isRequestBodyOptional ? " | undefined" : ""});\n`;
|
|
1864
|
-
}
|
|
1865
|
-
return newPropDefinition + resolveSchemaPropertiesToFormData({
|
|
1863
|
+
const { schema: combinedSchema } = resolveSchemaRef(subSchema, context);
|
|
1864
|
+
return resolveSchemaPropertiesToFormData({
|
|
1866
1865
|
schema: combinedSchema,
|
|
1867
1866
|
variableName,
|
|
1868
|
-
propName
|
|
1867
|
+
propName,
|
|
1869
1868
|
context,
|
|
1870
1869
|
isRequestBodyOptional,
|
|
1871
1870
|
encoding
|
|
@@ -1995,7 +1994,6 @@ function resolveSchemaPropertiesToFormData({ schema, variableName, propName, con
|
|
|
1995
1994
|
}
|
|
1996
1995
|
return formDataValues;
|
|
1997
1996
|
}
|
|
1998
|
-
|
|
1999
1997
|
//#endregion
|
|
2000
1998
|
//#region src/getters/body.ts
|
|
2001
1999
|
function buildBody(filteredBodyTypes, requestBody, operationName, context) {
|
|
@@ -2070,7 +2068,6 @@ function getContentTypeSuffix(contentType) {
|
|
|
2070
2068
|
if (CONTENT_TYPE_SUFFIX_MAP[contentType]) return CONTENT_TYPE_SUFFIX_MAP[contentType];
|
|
2071
2069
|
return (contentType.split("/")[1] ?? contentType).split(/[-+.]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
2072
2070
|
}
|
|
2073
|
-
|
|
2074
2071
|
//#endregion
|
|
2075
2072
|
//#region src/getters/imports.ts
|
|
2076
2073
|
function getAliasedImports({ name, resolvedValue, context }) {
|
|
@@ -2092,13 +2089,11 @@ function getImportAliasForRefOrValue({ context, imports, resolvedValue }) {
|
|
|
2092
2089
|
if (!context.output.schemas || !resolvedValue.isRef) return resolvedValue.value;
|
|
2093
2090
|
return imports.find((imp) => imp.name === resolvedValue.value)?.alias ?? resolvedValue.value;
|
|
2094
2091
|
}
|
|
2095
|
-
|
|
2096
2092
|
//#endregion
|
|
2097
2093
|
//#region src/getters/keys.ts
|
|
2098
2094
|
function getKey(key) {
|
|
2099
2095
|
return keyword.isIdentifierNameES5(key) ? key : `'${key}'`;
|
|
2100
2096
|
}
|
|
2101
|
-
|
|
2102
2097
|
//#endregion
|
|
2103
2098
|
//#region src/getters/object.ts
|
|
2104
2099
|
/**
|
|
@@ -2384,7 +2379,6 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
2384
2379
|
dependencies: []
|
|
2385
2380
|
};
|
|
2386
2381
|
}
|
|
2387
|
-
|
|
2388
2382
|
//#endregion
|
|
2389
2383
|
//#region src/getters/scalar.ts
|
|
2390
2384
|
/**
|
|
@@ -2543,7 +2537,6 @@ function getScalar({ item, name, context, formDataContext }) {
|
|
|
2543
2537
|
}
|
|
2544
2538
|
}
|
|
2545
2539
|
}
|
|
2546
|
-
|
|
2547
2540
|
//#endregion
|
|
2548
2541
|
//#region src/getters/combine.ts
|
|
2549
2542
|
const mergeableAllOfKeys = new Set([
|
|
@@ -2749,7 +2742,6 @@ function combineSchemas({ name, schema, separator, context, nullable, formDataCo
|
|
|
2749
2742
|
examples: resolveExampleRefs(schema.examples, context)
|
|
2750
2743
|
};
|
|
2751
2744
|
}
|
|
2752
|
-
|
|
2753
2745
|
//#endregion
|
|
2754
2746
|
//#region src/getters/discriminators.ts
|
|
2755
2747
|
function resolveDiscriminators(schemas, context) {
|
|
@@ -2801,7 +2793,6 @@ function resolveDiscriminators(schemas, context) {
|
|
|
2801
2793
|
}
|
|
2802
2794
|
return transformedSchemas;
|
|
2803
2795
|
}
|
|
2804
|
-
|
|
2805
2796
|
//#endregion
|
|
2806
2797
|
//#region src/getters/operation.ts
|
|
2807
2798
|
function getOperationId(operation, route, verb) {
|
|
@@ -2813,7 +2804,6 @@ function getOperationId(operation, route, verb) {
|
|
|
2813
2804
|
whitespace: "-"
|
|
2814
2805
|
}))].join("-"));
|
|
2815
2806
|
}
|
|
2816
|
-
|
|
2817
2807
|
//#endregion
|
|
2818
2808
|
//#region src/getters/parameters.ts
|
|
2819
2809
|
function getParameters({ parameters, context }) {
|
|
@@ -2836,7 +2826,6 @@ function getParameters({ parameters, context }) {
|
|
|
2836
2826
|
});
|
|
2837
2827
|
return result;
|
|
2838
2828
|
}
|
|
2839
|
-
|
|
2840
2829
|
//#endregion
|
|
2841
2830
|
//#region src/getters/params.ts
|
|
2842
2831
|
/**
|
|
@@ -2893,7 +2882,6 @@ function getParams({ route, pathParams = [], operationId, context, output }) {
|
|
|
2893
2882
|
};
|
|
2894
2883
|
});
|
|
2895
2884
|
}
|
|
2896
|
-
|
|
2897
2885
|
//#endregion
|
|
2898
2886
|
//#region src/getters/props.ts
|
|
2899
2887
|
function getProps({ body, queryParams, params, operationName, headers, context }) {
|
|
@@ -2958,7 +2946,6 @@ function getQueryParamDefinition(queryParams, context) {
|
|
|
2958
2946
|
const paramType = queryParams?.schema.name;
|
|
2959
2947
|
return `params${(queryParams?.isOptional || context.output.allParamsOptional) && !context.output.optionsParamRequired ? "?" : ""}: ${paramType}`;
|
|
2960
2948
|
}
|
|
2961
|
-
|
|
2962
2949
|
//#endregion
|
|
2963
2950
|
//#region src/getters/query-params.ts
|
|
2964
2951
|
const isOpenApiSchemaObject = (value) => {
|
|
@@ -3053,7 +3040,6 @@ function getQueryParams({ queryParams, operationName, context, suffix = "params"
|
|
|
3053
3040
|
requiredNullableKeys
|
|
3054
3041
|
};
|
|
3055
3042
|
}
|
|
3056
|
-
|
|
3057
3043
|
//#endregion
|
|
3058
3044
|
//#region src/getters/response.ts
|
|
3059
3045
|
function getResponse({ responses, operationName, context, contentType }) {
|
|
@@ -3083,7 +3069,6 @@ function getResponse({ responses, operationName, context, contentType }) {
|
|
|
3083
3069
|
originalSchema: responses
|
|
3084
3070
|
};
|
|
3085
3071
|
}
|
|
3086
|
-
|
|
3087
3072
|
//#endregion
|
|
3088
3073
|
//#region src/getters/route.ts
|
|
3089
3074
|
function isBaseUrlRuntime(baseUrl) {
|
|
@@ -3157,11 +3142,18 @@ function getFullRoute(route, servers, baseUrl) {
|
|
|
3157
3142
|
}
|
|
3158
3143
|
/**
|
|
3159
3144
|
* Returns `GeneratorImport` entries for {@link BaseUrlRuntime.imports} when `baseUrl` is a runtime config.
|
|
3145
|
+
*
|
|
3146
|
+
* Defaults `values` to true so symbols in `runtime` emit as value imports in the
|
|
3147
|
+
* generated client. Set `values: false` explicitly only for unusual cases (e.g.
|
|
3148
|
+
* type-only symbols referenced from the expression).
|
|
3160
3149
|
*/
|
|
3161
3150
|
function getBaseUrlRuntimeImports(baseUrl) {
|
|
3162
3151
|
if (!baseUrl) return [];
|
|
3163
3152
|
if (!isBaseUrlRuntime(baseUrl)) return [];
|
|
3164
|
-
return baseUrl.imports ?? []
|
|
3153
|
+
return (baseUrl.imports ?? []).map((imp) => ({
|
|
3154
|
+
...imp,
|
|
3155
|
+
values: imp.values ?? true
|
|
3156
|
+
}));
|
|
3165
3157
|
}
|
|
3166
3158
|
function getRouteAsArray(route) {
|
|
3167
3159
|
return route.split("/").filter((i) => i !== "").flatMap((segment) => {
|
|
@@ -3172,7 +3164,6 @@ function getRouteAsArray(route) {
|
|
|
3172
3164
|
});
|
|
3173
3165
|
}).join(",");
|
|
3174
3166
|
}
|
|
3175
|
-
|
|
3176
3167
|
//#endregion
|
|
3177
3168
|
//#region src/generators/component-definition.ts
|
|
3178
3169
|
function generateComponentDefinition(responses = {}, context, suffix) {
|
|
@@ -3200,7 +3191,6 @@ function generateComponentDefinition(responses = {}, context, suffix) {
|
|
|
3200
3191
|
}
|
|
3201
3192
|
return generatorSchemas;
|
|
3202
3193
|
}
|
|
3203
|
-
|
|
3204
3194
|
//#endregion
|
|
3205
3195
|
//#region src/generators/imports.ts
|
|
3206
3196
|
function generateImports({ imports, namingConvention = NamingConvention.CAMEL_CASE }) {
|
|
@@ -3335,7 +3325,6 @@ function generateVerbImports({ response, body, queryParams, props, headers, para
|
|
|
3335
3325
|
}];
|
|
3336
3326
|
});
|
|
3337
3327
|
}
|
|
3338
|
-
|
|
3339
3328
|
//#endregion
|
|
3340
3329
|
//#region src/generators/models-inline.ts
|
|
3341
3330
|
function generateModelInline(acc, model) {
|
|
@@ -3347,7 +3336,6 @@ function generateModelsInline(obj) {
|
|
|
3347
3336
|
for (const { model } of schemas) result = generateModelInline(result, model);
|
|
3348
3337
|
return result;
|
|
3349
3338
|
}
|
|
3350
|
-
|
|
3351
3339
|
//#endregion
|
|
3352
3340
|
//#region src/generators/mutator-info.ts
|
|
3353
3341
|
async function getMutatorInfo(filePath, options) {
|
|
@@ -3444,7 +3432,6 @@ function getEcmaVersion(target) {
|
|
|
3444
3432
|
return;
|
|
3445
3433
|
}
|
|
3446
3434
|
}
|
|
3447
|
-
|
|
3448
3435
|
//#endregion
|
|
3449
3436
|
//#region src/generators/mutator.ts
|
|
3450
3437
|
const BODY_TYPE_NAME = "BodyType";
|
|
@@ -3462,7 +3449,7 @@ async function generateMutator({ output, mutator, name, workspace, tsconfig }) {
|
|
|
3462
3449
|
let rawFile = await fs$1.readFile(importPath, "utf8");
|
|
3463
3450
|
rawFile = removeComments(rawFile);
|
|
3464
3451
|
const hasErrorType = rawFile.includes("export type ErrorType") || rawFile.includes("export interface ErrorType");
|
|
3465
|
-
const hasBodyType = rawFile.includes(`export type
|
|
3452
|
+
const hasBodyType = rawFile.includes(`export type BodyType`) || rawFile.includes(`export interface BodyType`);
|
|
3466
3453
|
const errorTypeName = mutator.default ? `${pascal(name)}ErrorType` : "ErrorType";
|
|
3467
3454
|
const bodyTypeName = mutator.default ? `${pascal(name)}${BODY_TYPE_NAME}` : BODY_TYPE_NAME;
|
|
3468
3455
|
const mutatorInfo = await getMutatorInfo(importPath, {
|
|
@@ -3490,7 +3477,6 @@ async function generateMutator({ output, mutator, name, workspace, tsconfig }) {
|
|
|
3490
3477
|
function removeComments(file) {
|
|
3491
3478
|
return file.replaceAll(/\/\/.*|\/\*[\s\S]*?\*\//g, "");
|
|
3492
3479
|
}
|
|
3493
|
-
|
|
3494
3480
|
//#endregion
|
|
3495
3481
|
//#region src/generators/options.ts
|
|
3496
3482
|
/**
|
|
@@ -3713,7 +3699,6 @@ function generateFormDataAndUrlEncodedFunction({ body, formData, formUrlEncoded,
|
|
|
3713
3699
|
}
|
|
3714
3700
|
return "";
|
|
3715
3701
|
}
|
|
3716
|
-
|
|
3717
3702
|
//#endregion
|
|
3718
3703
|
//#region src/generators/parameter-definition.ts
|
|
3719
3704
|
function generateParameterDefinition(parameters = {}, context, suffix) {
|
|
@@ -3757,7 +3742,6 @@ function generateParameterDefinition(parameters = {}, context, suffix) {
|
|
|
3757
3742
|
}
|
|
3758
3743
|
return generatorSchemas;
|
|
3759
3744
|
}
|
|
3760
|
-
|
|
3761
3745
|
//#endregion
|
|
3762
3746
|
//#region src/generators/interface.ts
|
|
3763
3747
|
/**
|
|
@@ -3797,7 +3781,6 @@ function generateInterface({ name, schema, context }) {
|
|
|
3797
3781
|
schema
|
|
3798
3782
|
}];
|
|
3799
3783
|
}
|
|
3800
|
-
|
|
3801
3784
|
//#endregion
|
|
3802
3785
|
//#region src/generators/schema-definition.ts
|
|
3803
3786
|
/**
|
|
@@ -3926,7 +3909,6 @@ function generateSchemaDefinitions(schemaName, schema, context, suffix) {
|
|
|
3926
3909
|
schema
|
|
3927
3910
|
}];
|
|
3928
3911
|
}
|
|
3929
|
-
|
|
3930
3912
|
//#endregion
|
|
3931
3913
|
//#region src/generators/verbs-options.ts
|
|
3932
3914
|
async function buildVerbOption({ verb, output, operation, route, pathRoute, verbParameters = [], context, body, operationName, operationId, override, tags, deprecated, description, summary }) {
|
|
@@ -4129,7 +4111,6 @@ function _filteredVerbs(verbs, filters) {
|
|
|
4129
4111
|
return filterMode === "exclude" ? !isMatch : isMatch;
|
|
4130
4112
|
});
|
|
4131
4113
|
}
|
|
4132
|
-
|
|
4133
4114
|
//#endregion
|
|
4134
4115
|
//#region src/writers/file.ts
|
|
4135
4116
|
const TRAILING_WHITESPACE_RE = /[^\S\r\n]+$/gm;
|
|
@@ -4143,7 +4124,6 @@ const TRAILING_WHITESPACE_RE = /[^\S\r\n]+$/gm;
|
|
|
4143
4124
|
async function writeGeneratedFile(filePath, content) {
|
|
4144
4125
|
await fs$1.outputFile(filePath, content.replaceAll(TRAILING_WHITESPACE_RE, ""));
|
|
4145
4126
|
}
|
|
4146
|
-
|
|
4147
4127
|
//#endregion
|
|
4148
4128
|
//#region src/writers/schemas.ts
|
|
4149
4129
|
/**
|
|
@@ -4283,8 +4263,8 @@ function getSchema({ schema: { imports, model }, header, namingConvention = Nami
|
|
|
4283
4263
|
file += model;
|
|
4284
4264
|
return file;
|
|
4285
4265
|
}
|
|
4286
|
-
function getPath(path
|
|
4287
|
-
return
|
|
4266
|
+
function getPath(path, name, fileExtension) {
|
|
4267
|
+
return nodePath.join(path, `${name}${fileExtension}`);
|
|
4288
4268
|
}
|
|
4289
4269
|
function writeModelInline(acc, model) {
|
|
4290
4270
|
return acc + `${model}\n`;
|
|
@@ -4333,7 +4313,7 @@ async function writeSchemas({ schemaPath, schemas, target, namingConvention, fil
|
|
|
4333
4313
|
});
|
|
4334
4314
|
}
|
|
4335
4315
|
if (indexFiles) {
|
|
4336
|
-
const schemaFilePath =
|
|
4316
|
+
const schemaFilePath = nodePath.join(schemaPath, `index.ts`);
|
|
4337
4317
|
await fs$1.ensureFile(schemaFilePath);
|
|
4338
4318
|
const ext = fileExtension.endsWith(".ts") ? fileExtension.slice(0, -3) : fileExtension;
|
|
4339
4319
|
const conventionNamesSet = new Set(Object.values(schemaGroups).map((group) => conventionName(group[0].name, namingConvention)));
|
|
@@ -4344,7 +4324,6 @@ async function writeSchemas({ schemaPath, schemas, target, namingConvention, fil
|
|
|
4344
4324
|
}
|
|
4345
4325
|
}
|
|
4346
4326
|
}
|
|
4347
|
-
|
|
4348
4327
|
//#endregion
|
|
4349
4328
|
//#region src/writers/generate-imports-for-builder.ts
|
|
4350
4329
|
function generateImportsForBuilder(output, imports, relativeSchemasPath) {
|
|
@@ -4360,10 +4339,7 @@ function generateImportsForBuilder(output, imports, relativeSchemasPath) {
|
|
|
4360
4339
|
else {
|
|
4361
4340
|
const importsByDependency = /* @__PURE__ */ new Map();
|
|
4362
4341
|
for (const schemaImport of imports.filter((i) => !i.importPath)) {
|
|
4363
|
-
const
|
|
4364
|
-
const suffix = isZodSchemaOutput ? ".zod" : "";
|
|
4365
|
-
const importExtension = output.fileExtension.replace(/\.ts$/, "") || "";
|
|
4366
|
-
const dependency = joinSafe(relativeSchemasPath, `${normalizedName}${suffix}${importExtension}`);
|
|
4342
|
+
const dependency = joinSafe(relativeSchemasPath, `${conventionName(isZodSchemaOutput ? schemaImport.name : schemaImport.schemaName ?? schemaImport.name, output.namingConvention)}${isZodSchemaOutput ? ".zod" : ""}${output.fileExtension.replace(/\.ts$/, "") || ""}`);
|
|
4367
4343
|
if (!importsByDependency.has(dependency)) importsByDependency.set(dependency, []);
|
|
4368
4344
|
importsByDependency.get(dependency)?.push(schemaImport);
|
|
4369
4345
|
}
|
|
@@ -4380,7 +4356,6 @@ function generateImportsForBuilder(output, imports, relativeSchemasPath) {
|
|
|
4380
4356
|
});
|
|
4381
4357
|
return [...schemaImports, ...otherImports];
|
|
4382
4358
|
}
|
|
4383
|
-
|
|
4384
4359
|
//#endregion
|
|
4385
4360
|
//#region src/writers/target.ts
|
|
4386
4361
|
function generateTarget(builder, options) {
|
|
@@ -4457,7 +4432,6 @@ function generateTarget(builder, options) {
|
|
|
4457
4432
|
implementationMock: target.implementationMock.function + target.implementationMock.handler
|
|
4458
4433
|
};
|
|
4459
4434
|
}
|
|
4460
|
-
|
|
4461
4435
|
//#endregion
|
|
4462
4436
|
//#region src/writers/types.ts
|
|
4463
4437
|
function getOrvalGeneratedTypes() {
|
|
@@ -4496,7 +4470,6 @@ interface TypedResponse<T> extends Response {
|
|
|
4496
4470
|
}
|
|
4497
4471
|
`;
|
|
4498
4472
|
}
|
|
4499
|
-
|
|
4500
4473
|
//#endregion
|
|
4501
4474
|
//#region src/writers/single-mode.ts
|
|
4502
4475
|
async function writeSingleMode({ builder, output, projectName, header, needSchema, generateSchemasInline }) {
|
|
@@ -4519,7 +4492,7 @@ async function writeSingleMode({ builder, output, projectName, header, needSchem
|
|
|
4519
4492
|
if (!matchingImport) continue;
|
|
4520
4493
|
if (!!mockImport.values || !!mockImport.isConstant || !!mockImport.default || !!mockImport.namespaceImport || !!mockImport.syntheticDefaultImport) matchingImport.values = true;
|
|
4521
4494
|
}
|
|
4522
|
-
const importsForBuilder = schemasPath ? generateImportsForBuilder(output, normalizedImports, schemasPath) :
|
|
4495
|
+
const importsForBuilder = schemasPath ? generateImportsForBuilder(output, normalizedImports, schemasPath) : generateImportsForBuilder(output, normalizedImports.filter((imp) => !!imp.importPath), ".");
|
|
4523
4496
|
data += builder.imports({
|
|
4524
4497
|
client: output.client,
|
|
4525
4498
|
implementation,
|
|
@@ -4534,7 +4507,8 @@ async function writeSingleMode({ builder, output, projectName, header, needSchem
|
|
|
4534
4507
|
output
|
|
4535
4508
|
});
|
|
4536
4509
|
if (output.mock) {
|
|
4537
|
-
const
|
|
4510
|
+
const filteredMockImports = importsMock.filter((impMock) => !normalizedImports.some((imp) => imp.name === impMock.name && (imp.alias ?? "") === (impMock.alias ?? "")));
|
|
4511
|
+
const importsMockForBuilder = schemasPath ? generateImportsForBuilder(output, filteredMockImports, schemasPath) : generateImportsForBuilder(output, filteredMockImports.filter((imp) => !!imp.importPath), ".");
|
|
4538
4512
|
data += builder.importsMock({
|
|
4539
4513
|
implementation: implementationMock,
|
|
4540
4514
|
imports: importsMockForBuilder,
|
|
@@ -4574,7 +4548,6 @@ async function writeSingleMode({ builder, output, projectName, header, needSchem
|
|
|
4574
4548
|
throw new Error(`Oups... 🍻. An Error occurred while writing file => ${errorMsg}`, { cause: error });
|
|
4575
4549
|
}
|
|
4576
4550
|
}
|
|
4577
|
-
|
|
4578
4551
|
//#endregion
|
|
4579
4552
|
//#region src/writers/split-mode.ts
|
|
4580
4553
|
async function writeSplitMode({ builder, output, projectName, header, needSchema, generateSchemasInline }) {
|
|
@@ -4611,7 +4584,7 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
4611
4584
|
isAllowSyntheticDefaultImports,
|
|
4612
4585
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4613
4586
|
});
|
|
4614
|
-
const schemasPath = output.schemas ? void 0 :
|
|
4587
|
+
const schemasPath = output.schemas ? void 0 : nodePath.join(dirname, filename + ".schemas" + extension);
|
|
4615
4588
|
if (schemasPath && needSchema) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
4616
4589
|
if (mutators) implementationData += generateMutatorImports({
|
|
4617
4590
|
mutators,
|
|
@@ -4633,9 +4606,9 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
4633
4606
|
implementationData += `\n${implementation}`;
|
|
4634
4607
|
mockData += `\n${implementationMock}`;
|
|
4635
4608
|
const implementationFilename = filename + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
4636
|
-
const implementationPath =
|
|
4609
|
+
const implementationPath = nodePath.join(dirname, implementationFilename);
|
|
4637
4610
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
4638
|
-
const mockPath = output.mock ?
|
|
4611
|
+
const mockPath = output.mock ? nodePath.join(dirname, filename + "." + getMockFileExtensionByTypeName(output.mock) + extension) : void 0;
|
|
4639
4612
|
if (mockPath) await writeGeneratedFile(mockPath, mockData);
|
|
4640
4613
|
return [
|
|
4641
4614
|
implementationPath,
|
|
@@ -4646,7 +4619,6 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
4646
4619
|
throw new Error(`Oups... 🍻. An Error occurred while splitting => ${String(error)}`, { cause: error });
|
|
4647
4620
|
}
|
|
4648
4621
|
}
|
|
4649
|
-
|
|
4650
4622
|
//#endregion
|
|
4651
4623
|
//#region src/writers/target-tags.ts
|
|
4652
4624
|
function addDefaultTagIfEmpty(operation) {
|
|
@@ -4761,7 +4733,6 @@ function generateTargetForTags(builder, options) {
|
|
|
4761
4733
|
};
|
|
4762
4734
|
return result;
|
|
4763
4735
|
}
|
|
4764
|
-
|
|
4765
4736
|
//#endregion
|
|
4766
4737
|
//#region src/writers/split-tags-mode.ts
|
|
4767
4738
|
async function writeSplitTagsMode({ builder, output, projectName, header, needSchema, generateSchemasInline }) {
|
|
@@ -4772,7 +4743,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4772
4743
|
const target = generateTargetForTags(builder, output);
|
|
4773
4744
|
const isAllowSyntheticDefaultImports = isSyntheticDefaultImportsAllow(output.tsconfig);
|
|
4774
4745
|
const mockOption = output.mock && !isFunction(output.mock) ? output.mock : void 0;
|
|
4775
|
-
const indexFilePath = mockOption?.indexMockFiles ?
|
|
4746
|
+
const indexFilePath = mockOption?.indexMockFiles ? nodePath.join(dirname, "index." + getMockFileExtensionByTypeName(mockOption) + extension) : void 0;
|
|
4776
4747
|
if (indexFilePath) await fs$1.outputFile(indexFilePath, "");
|
|
4777
4748
|
const tagEntries = Object.entries(target);
|
|
4778
4749
|
const generatedFilePathsArray = await Promise.all(tagEntries.map(async ([tag, target]) => {
|
|
@@ -4780,19 +4751,19 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4780
4751
|
const { imports, implementation, implementationMock, importsMock, mutators, clientMutators, formData, fetchReviver, formUrlEncoded, paramsSerializer } = target;
|
|
4781
4752
|
let implementationData = header;
|
|
4782
4753
|
let mockData = header;
|
|
4783
|
-
const importerPath =
|
|
4754
|
+
const importerPath = nodePath.join(dirname, tag, tag + extension);
|
|
4784
4755
|
const relativeSchemasPath = output.schemas ? getRelativeImportPath(importerPath, getFileInfo(isString(output.schemas) ? output.schemas : output.schemas.path, { extension: output.fileExtension }).dirname) : "../" + filename + ".schemas" + extension.replace(/\.ts$/, "");
|
|
4785
4756
|
const tagNames = new Set(tagEntries.map(([t]) => t));
|
|
4786
4757
|
const serviceSuffix = OutputClient.ANGULAR === output.client ? ".service" : "";
|
|
4787
4758
|
const importsForBuilder = generateImportsForBuilder(output, imports.map((imp) => {
|
|
4788
4759
|
if (!imp.importPath) return imp;
|
|
4789
4760
|
if (!imp.importPath.startsWith(".")) return imp;
|
|
4790
|
-
const resolvedPath =
|
|
4791
|
-
const targetBasename =
|
|
4761
|
+
const resolvedPath = nodePath.resolve(dirname, imp.importPath);
|
|
4762
|
+
const targetBasename = nodePath.basename(resolvedPath);
|
|
4792
4763
|
let targetFile;
|
|
4793
4764
|
if (tagNames.has(targetBasename)) {
|
|
4794
4765
|
const tagFilename = targetBasename + serviceSuffix + extension;
|
|
4795
|
-
targetFile =
|
|
4766
|
+
targetFile = nodePath.join(resolvedPath, tagFilename);
|
|
4796
4767
|
} else targetFile = resolvedPath + extension;
|
|
4797
4768
|
const adjustedPath = getRelativeImportPath(importerPath, targetFile);
|
|
4798
4769
|
return {
|
|
@@ -4822,7 +4793,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4822
4793
|
isAllowSyntheticDefaultImports,
|
|
4823
4794
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4824
4795
|
});
|
|
4825
|
-
const schemasPath = output.schemas ? void 0 :
|
|
4796
|
+
const schemasPath = output.schemas ? void 0 : nodePath.join(dirname, filename + ".schemas" + extension);
|
|
4826
4797
|
if (schemasPath && needSchema) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
4827
4798
|
if (mutators) implementationData += generateMutatorImports({
|
|
4828
4799
|
mutators,
|
|
@@ -4860,9 +4831,9 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4860
4831
|
implementationData += `\n${implementation}`;
|
|
4861
4832
|
mockData += `\n${implementationMock}`;
|
|
4862
4833
|
const implementationFilename = tag + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
4863
|
-
const implementationPath =
|
|
4834
|
+
const implementationPath = nodePath.join(dirname, tag, implementationFilename);
|
|
4864
4835
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
4865
|
-
const mockPath = output.mock ?
|
|
4836
|
+
const mockPath = output.mock ? nodePath.join(dirname, tag, tag + "." + getMockFileExtensionByTypeName(output.mock) + extension) : void 0;
|
|
4866
4837
|
if (mockPath) await writeGeneratedFile(mockPath, mockData);
|
|
4867
4838
|
return [
|
|
4868
4839
|
implementationPath,
|
|
@@ -4882,7 +4853,6 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4882
4853
|
}
|
|
4883
4854
|
return [...new Set([...indexFilePath ? [indexFilePath] : [], ...generatedFilePathsArray.flat()])];
|
|
4884
4855
|
}
|
|
4885
|
-
|
|
4886
4856
|
//#endregion
|
|
4887
4857
|
//#region src/writers/tags-mode.ts
|
|
4888
4858
|
async function writeTagsMode({ builder, output, projectName, header, needSchema, generateSchemasInline }) {
|
|
@@ -4932,7 +4902,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema,
|
|
|
4932
4902
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4933
4903
|
});
|
|
4934
4904
|
}
|
|
4935
|
-
const schemasPath = output.schemas ? void 0 :
|
|
4905
|
+
const schemasPath = output.schemas ? void 0 : nodePath.join(dirname, filename + ".schemas" + extension);
|
|
4936
4906
|
if (schemasPath && needSchema) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
4937
4907
|
if (mutators) data += generateMutatorImports({
|
|
4938
4908
|
mutators,
|
|
@@ -4957,7 +4927,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema,
|
|
|
4957
4927
|
data += "\n\n";
|
|
4958
4928
|
data += implementationMock;
|
|
4959
4929
|
}
|
|
4960
|
-
const implementationPath =
|
|
4930
|
+
const implementationPath = nodePath.join(dirname, `${kebab(tag)}${extension}`);
|
|
4961
4931
|
await writeGeneratedFile(implementationPath, data);
|
|
4962
4932
|
return [implementationPath, ...schemasPath ? [schemasPath] : []];
|
|
4963
4933
|
} catch (error) {
|
|
@@ -4965,7 +4935,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema,
|
|
|
4965
4935
|
}
|
|
4966
4936
|
}))).flat();
|
|
4967
4937
|
}
|
|
4968
|
-
|
|
4969
4938
|
//#endregion
|
|
4970
4939
|
export { BODY_TYPE_NAME, EnumGeneration, ErrorWithTag, FormDataArrayHandling, GetterPropType, LogLevels, NamingConvention, OutputClient, OutputHttpClient, OutputMockType, OutputMode, PropertySortOrder, RefComponentSuffix, SchemaType, SupportedFormatter, TEMPLATE_TAG_REGEX, URL_REGEX, VERBS_WITH_BODY, Verbs, _filteredVerbs, addDependency, asyncReduce, camel, combineSchemas, compareVersions, conventionName, count, createDebugger, createLogger, createSuccessMessage, createTypeAliasIfNeeded, dedupeUnionType, dynamicImport, escape, escapeRegExp, filterByContentType, fixCrossDirectoryImports, fixRegularSchemaImports, generalJSTypes, generalJSTypesWithArray, generateAxiosOptions, generateBodyMutatorConfig, generateBodyOptions, generateComponentDefinition, generateDependencyImports, generateFormDataAndUrlEncodedFunction, generateImports, generateModelInline, generateModelsInline, generateMutator, generateMutatorConfig, generateMutatorImports, generateMutatorRequestOptions, generateOptions, generateParameterDefinition, generateQueryParamsAxiosConfig, generateSchemasDefinition, generateTarget, generateTargetForTags, generateVerbImports, generateVerbOptions, generateVerbsOptions, getAngularFilteredParamsCallExpression, getAngularFilteredParamsExpression, getAngularFilteredParamsHelperBody, getArray, getBaseUrlRuntimeImports, getBodiesByContentType, getBody, getCombinedEnumValue, getDefaultContentType, getEnum, getEnumDescriptions, getEnumImplementation, getEnumNames, getEnumUnionFromSchema, getExtension, getFileInfo, getFormDataFieldFileType, getFullRoute, getIsBodyVerb, getKey, getMockFileExtensionByTypeName, getNumberWord, getObject, getOperationId, getOrvalGeneratedTypes, getParameters, getParams, getParamsInPath, getPropertySafe, getProps, getQueryParams, getRefInfo, getResReqTypes, getResponse, getResponseTypeCategory, getRoute, getRouteAsArray, getScalar, getSuccessResponseType, getTypedResponse, getWarningCount, isBinaryContentType, isBoolean, isDirectory, isFunction, isModule, isNullish, isNumber, isNumeric, isObject, isReference, isSchema, isString, isStringLike, isSyntheticDefaultImportsAllow, isUrl, isVerb, isVerbose, jsDoc, jsStringEscape, kebab, keyValuePairsToJsDoc, log, logError, logVerbose, logWarning, mergeDeep, mismatchArgsMessage, pascal, removeFilesAndEmptyFolders, resetWarnings, resolveDiscriminators, resolveExampleRefs, resolveInstalledVersion, resolveInstalledVersions, resolveObject, resolveRef, resolveValue, sanitize, setVerbose, snake, sortByPriority, splitSchemasByType, startMessage, stringify, toObjectString, path_exports as upath, upper, writeModelInline, writeModelsInline, writeSchema, writeSchemas, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode };
|
|
4940
|
+
|
|
4971
4941
|
//# sourceMappingURL=index.mjs.map
|