@orval/core 8.6.0 → 8.6.2
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 +35 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { t as __exportAll } from "./chunk-C7Uep-_p.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 path from "node:path";
|
|
6
6
|
import { compare } from "compare-versions";
|
|
7
7
|
import debug from "debug";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
@@ -135,7 +135,7 @@ function isReference(obj) {
|
|
|
135
135
|
return !isNullish$1(obj) && Object.hasOwn(obj, "$ref");
|
|
136
136
|
}
|
|
137
137
|
function isDirectory(pathValue) {
|
|
138
|
-
return !
|
|
138
|
+
return !path.extname(pathValue);
|
|
139
139
|
}
|
|
140
140
|
function isObject(x) {
|
|
141
141
|
return Object.prototype.toString.call(x) === "[object Object]";
|
|
@@ -469,8 +469,8 @@ async function dynamicImport(toImport, from = process.cwd(), takeDefault = true)
|
|
|
469
469
|
if (!toImport) return toImport;
|
|
470
470
|
try {
|
|
471
471
|
if (isString(toImport)) {
|
|
472
|
-
const filePath =
|
|
473
|
-
const extension =
|
|
472
|
+
const filePath = path.resolve(from, toImport);
|
|
473
|
+
const extension = path.extname(filePath);
|
|
474
474
|
if (TS_MODULE_EXTENSIONS.has(extension)) {
|
|
475
475
|
const data = await createJiti(from, { interopDefault: true }).import(filePath);
|
|
476
476
|
if (takeDefault && (isObject(data) || isModule(data)) && data.default) return data.default;
|
|
@@ -497,14 +497,14 @@ function getExtension(path) {
|
|
|
497
497
|
//#region src/utils/file.ts
|
|
498
498
|
function getFileInfo(target = "", { backupFilename = "filename", extension = ".ts" } = {}) {
|
|
499
499
|
const isDir = isDirectory(target);
|
|
500
|
-
const filePath = isDir ?
|
|
500
|
+
const filePath = isDir ? path.join(target, backupFilename + extension) : target;
|
|
501
501
|
return {
|
|
502
502
|
path: filePath,
|
|
503
503
|
pathWithoutExtension: filePath.replace(/\.[^/.]+$/, ""),
|
|
504
504
|
extension,
|
|
505
505
|
isDirectory: isDir,
|
|
506
|
-
dirname:
|
|
507
|
-
filename:
|
|
506
|
+
dirname: path.dirname(filePath),
|
|
507
|
+
filename: path.basename(filePath, extension.startsWith(".") ? extension : `.${extension}`)
|
|
508
508
|
};
|
|
509
509
|
}
|
|
510
510
|
async function removeFilesAndEmptyFolders(patterns, dir) {
|
|
@@ -708,13 +708,13 @@ function toUnix(value) {
|
|
|
708
708
|
return value;
|
|
709
709
|
}
|
|
710
710
|
function join(...args) {
|
|
711
|
-
return toUnix(
|
|
711
|
+
return toUnix(path.join(...args.map((a) => toUnix(a))));
|
|
712
712
|
}
|
|
713
713
|
/**
|
|
714
714
|
* Behaves exactly like `path.relative(from, to)`, but keeps the first meaningful "./"
|
|
715
715
|
*/
|
|
716
716
|
function relativeSafe(from, to) {
|
|
717
|
-
return normalizeSafe(`.${separator}${toUnix(
|
|
717
|
+
return normalizeSafe(`.${separator}${toUnix(path.relative(toUnix(from), toUnix(to)))}`);
|
|
718
718
|
}
|
|
719
719
|
function getSchemaFileName(path) {
|
|
720
720
|
return path.replace(`.${getExtension(path)}`, "").slice(path.lastIndexOf("/") + 1);
|
|
@@ -723,13 +723,13 @@ const separator = "/";
|
|
|
723
723
|
function normalizeSafe(value) {
|
|
724
724
|
let result;
|
|
725
725
|
value = toUnix(value);
|
|
726
|
-
result = toUnix(
|
|
726
|
+
result = toUnix(path.normalize(value));
|
|
727
727
|
if (value.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
728
728
|
else if (value.startsWith("//") && !result.startsWith("//")) result = value.startsWith("//./") ? "//." + result : "/" + result;
|
|
729
729
|
return result;
|
|
730
730
|
}
|
|
731
731
|
function joinSafe(...values) {
|
|
732
|
-
let result = toUnix(
|
|
732
|
+
let result = toUnix(path.join(...values.map((v) => toUnix(v))));
|
|
733
733
|
if (values.length > 0) {
|
|
734
734
|
const firstValue = toUnix(values[0]);
|
|
735
735
|
if (firstValue.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
@@ -760,14 +760,14 @@ function joinSafe(...values) {
|
|
|
760
760
|
* @returns The relative import path string.
|
|
761
761
|
*/
|
|
762
762
|
function getRelativeImportPath(importerFilePath, exporterFilePath, includeFileExtension = false) {
|
|
763
|
-
if (!
|
|
764
|
-
if (!
|
|
765
|
-
const importerDir =
|
|
766
|
-
const relativePath =
|
|
767
|
-
let posixPath =
|
|
763
|
+
if (!path.isAbsolute(importerFilePath)) throw new Error(`'importerFilePath' is not an absolute path. "${importerFilePath}"`);
|
|
764
|
+
if (!path.isAbsolute(exporterFilePath)) throw new Error(`'exporterFilePath' is not an absolute path. "${exporterFilePath}"`);
|
|
765
|
+
const importerDir = path.dirname(importerFilePath);
|
|
766
|
+
const relativePath = path.relative(importerDir, exporterFilePath);
|
|
767
|
+
let posixPath = path.posix.join(...relativePath.split(path.sep));
|
|
768
768
|
if (!posixPath.startsWith("./") && !posixPath.startsWith("../")) posixPath = `./${posixPath}`;
|
|
769
769
|
if (!includeFileExtension) {
|
|
770
|
-
const ext =
|
|
770
|
+
const ext = path.extname(posixPath);
|
|
771
771
|
if (ext && posixPath.endsWith(ext)) posixPath = posixPath.slice(0, -ext.length);
|
|
772
772
|
}
|
|
773
773
|
return posixPath;
|
|
@@ -777,20 +777,20 @@ function getRelativeImportPath(importerFilePath, exporterFilePath, includeFileEx
|
|
|
777
777
|
//#region src/utils/resolve-version.ts
|
|
778
778
|
function resolveInstalledVersion(packageName, fromDir) {
|
|
779
779
|
try {
|
|
780
|
-
const require = createRequire(
|
|
780
|
+
const require = createRequire(path.join(fromDir, "noop.js"));
|
|
781
781
|
try {
|
|
782
782
|
return require(`${packageName}/package.json`).version;
|
|
783
783
|
} catch (directError) {
|
|
784
784
|
if (directError instanceof Error && "code" in directError && directError.code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
785
785
|
const entryPath = require.resolve(packageName);
|
|
786
|
-
let dir =
|
|
787
|
-
while (dir !==
|
|
788
|
-
const pkgPath =
|
|
786
|
+
let dir = path.dirname(entryPath);
|
|
787
|
+
while (dir !== path.parse(dir).root) {
|
|
788
|
+
const pkgPath = path.join(dir, "package.json");
|
|
789
789
|
if (existsSync(pkgPath)) {
|
|
790
790
|
const pkgData = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
791
791
|
if (pkgData.name === packageName) return pkgData.version;
|
|
792
792
|
}
|
|
793
|
-
dir =
|
|
793
|
+
dir = path.dirname(dir);
|
|
794
794
|
}
|
|
795
795
|
return;
|
|
796
796
|
}
|
|
@@ -4160,8 +4160,8 @@ function getSchema({ schema: { imports, model }, header, namingConvention = Nami
|
|
|
4160
4160
|
file += model;
|
|
4161
4161
|
return file;
|
|
4162
4162
|
}
|
|
4163
|
-
function getPath(path, name, fileExtension) {
|
|
4164
|
-
return
|
|
4163
|
+
function getPath(path$1, name, fileExtension) {
|
|
4164
|
+
return path.join(path$1, `${name}${fileExtension}`);
|
|
4165
4165
|
}
|
|
4166
4166
|
function writeModelInline(acc, model) {
|
|
4167
4167
|
return acc + `${model}\n`;
|
|
@@ -4210,7 +4210,7 @@ async function writeSchemas({ schemaPath, schemas, target, namingConvention, fil
|
|
|
4210
4210
|
});
|
|
4211
4211
|
}
|
|
4212
4212
|
if (indexFiles) {
|
|
4213
|
-
const schemaFilePath =
|
|
4213
|
+
const schemaFilePath = path.join(schemaPath, `index${fileExtension}`);
|
|
4214
4214
|
await fs$1.ensureFile(schemaFilePath);
|
|
4215
4215
|
const ext = fileExtension.endsWith(".ts") ? fileExtension.slice(0, -3) : fileExtension;
|
|
4216
4216
|
const conventionNamesSet = new Set(Object.values(schemaGroups).map((group) => conventionName(group[0].name, namingConvention)));
|
|
@@ -4488,7 +4488,7 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
4488
4488
|
isAllowSyntheticDefaultImports,
|
|
4489
4489
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4490
4490
|
});
|
|
4491
|
-
const schemasPath = output.schemas ? void 0 :
|
|
4491
|
+
const schemasPath = output.schemas ? void 0 : path.join(dirname, filename + ".schemas" + extension);
|
|
4492
4492
|
if (schemasPath && needSchema) await writeGeneratedFile(schemasPath, header + generateModelsInline(builder.schemas));
|
|
4493
4493
|
if (mutators) implementationData += generateMutatorImports({
|
|
4494
4494
|
mutators,
|
|
@@ -4510,9 +4510,9 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
4510
4510
|
implementationData += `\n${implementation}`;
|
|
4511
4511
|
mockData += `\n${implementationMock}`;
|
|
4512
4512
|
const implementationFilename = filename + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
4513
|
-
const implementationPath =
|
|
4513
|
+
const implementationPath = path.join(dirname, implementationFilename);
|
|
4514
4514
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
4515
|
-
const mockPath = output.mock ?
|
|
4515
|
+
const mockPath = output.mock ? path.join(dirname, filename + "." + getMockFileExtensionByTypeName(output.mock) + extension) : void 0;
|
|
4516
4516
|
if (mockPath) await writeGeneratedFile(mockPath, mockData);
|
|
4517
4517
|
return [
|
|
4518
4518
|
implementationPath,
|
|
@@ -4649,7 +4649,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4649
4649
|
const target = generateTargetForTags(builder, output);
|
|
4650
4650
|
const isAllowSyntheticDefaultImports = isSyntheticDefaultImportsAllow(output.tsconfig);
|
|
4651
4651
|
const mockOption = output.mock && !isFunction(output.mock) ? output.mock : void 0;
|
|
4652
|
-
const indexFilePath = mockOption?.indexMockFiles ?
|
|
4652
|
+
const indexFilePath = mockOption?.indexMockFiles ? path.join(dirname, "index." + getMockFileExtensionByTypeName(mockOption) + extension) : void 0;
|
|
4653
4653
|
if (indexFilePath) await fs$1.outputFile(indexFilePath, "");
|
|
4654
4654
|
const tagEntries = Object.entries(target);
|
|
4655
4655
|
const generatedFilePathsArray = await Promise.all(tagEntries.map(async ([tag, target]) => {
|
|
@@ -4657,7 +4657,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4657
4657
|
const { imports, implementation, implementationMock, importsMock, mutators, clientMutators, formData, fetchReviver, formUrlEncoded, paramsSerializer } = target;
|
|
4658
4658
|
let implementationData = header;
|
|
4659
4659
|
let mockData = header;
|
|
4660
|
-
const importerPath =
|
|
4660
|
+
const importerPath = path.join(dirname, tag, tag + extension);
|
|
4661
4661
|
const relativeSchemasPath = output.schemas ? getRelativeImportPath(importerPath, getFileInfo(isString(output.schemas) ? output.schemas : output.schemas.path, { extension: output.fileExtension }).dirname) : "../" + filename + ".schemas";
|
|
4662
4662
|
const importsForBuilder = generateImportsForBuilder(output, imports, relativeSchemasPath);
|
|
4663
4663
|
implementationData += builder.imports({
|
|
@@ -4682,7 +4682,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4682
4682
|
isAllowSyntheticDefaultImports,
|
|
4683
4683
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4684
4684
|
});
|
|
4685
|
-
const schemasPath = output.schemas ? void 0 :
|
|
4685
|
+
const schemasPath = output.schemas ? void 0 : path.join(dirname, filename + ".schemas" + extension);
|
|
4686
4686
|
if (schemasPath && needSchema) await writeGeneratedFile(schemasPath, header + generateModelsInline(builder.schemas));
|
|
4687
4687
|
if (mutators) implementationData += generateMutatorImports({
|
|
4688
4688
|
mutators,
|
|
@@ -4720,9 +4720,9 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4720
4720
|
implementationData += `\n${implementation}`;
|
|
4721
4721
|
mockData += `\n${implementationMock}`;
|
|
4722
4722
|
const implementationFilename = tag + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
4723
|
-
const implementationPath =
|
|
4723
|
+
const implementationPath = path.join(dirname, tag, implementationFilename);
|
|
4724
4724
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
4725
|
-
const mockPath = output.mock ?
|
|
4725
|
+
const mockPath = output.mock ? path.join(dirname, tag, tag + "." + getMockFileExtensionByTypeName(output.mock) + extension) : void 0;
|
|
4726
4726
|
if (mockPath) await writeGeneratedFile(mockPath, mockData);
|
|
4727
4727
|
return [
|
|
4728
4728
|
implementationPath,
|
|
@@ -4792,7 +4792,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema
|
|
|
4792
4792
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4793
4793
|
});
|
|
4794
4794
|
}
|
|
4795
|
-
const schemasPath = output.schemas ? void 0 :
|
|
4795
|
+
const schemasPath = output.schemas ? void 0 : path.join(dirname, filename + ".schemas" + extension);
|
|
4796
4796
|
if (schemasPath && needSchema) await writeGeneratedFile(schemasPath, header + generateModelsInline(builder.schemas));
|
|
4797
4797
|
if (mutators) data += generateMutatorImports({
|
|
4798
4798
|
mutators,
|
|
@@ -4817,7 +4817,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema
|
|
|
4817
4817
|
data += "\n\n";
|
|
4818
4818
|
data += implementationMock;
|
|
4819
4819
|
}
|
|
4820
|
-
const implementationPath =
|
|
4820
|
+
const implementationPath = path.join(dirname, `${kebab(tag)}${extension}`);
|
|
4821
4821
|
await writeGeneratedFile(implementationPath, data);
|
|
4822
4822
|
return [implementationPath, ...schemasPath ? [schemasPath] : []];
|
|
4823
4823
|
} catch (error) {
|