@orval/core 8.12.1 → 8.12.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 +40 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ 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, isFunction as isFunction$1, 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";
|
|
@@ -144,7 +144,7 @@ function isReference(obj) {
|
|
|
144
144
|
return !isNullish$1(obj) && Object.hasOwn(obj, "$ref");
|
|
145
145
|
}
|
|
146
146
|
function isDirectory(pathValue) {
|
|
147
|
-
return !
|
|
147
|
+
return !nodePath.extname(pathValue);
|
|
148
148
|
}
|
|
149
149
|
function isObject(x) {
|
|
150
150
|
return Object.prototype.toString.call(x) === "[object Object]";
|
|
@@ -507,8 +507,8 @@ async function dynamicImport(toImport, from = process.cwd(), takeDefault = true)
|
|
|
507
507
|
if (!toImport) return toImport;
|
|
508
508
|
try {
|
|
509
509
|
if (isString(toImport)) {
|
|
510
|
-
const filePath =
|
|
511
|
-
const extension =
|
|
510
|
+
const filePath = nodePath.resolve(from, toImport);
|
|
511
|
+
const extension = nodePath.extname(filePath);
|
|
512
512
|
if (TS_MODULE_EXTENSIONS.has(extension)) {
|
|
513
513
|
const data = await createJiti(from, { interopDefault: true }).import(filePath);
|
|
514
514
|
if (takeDefault && (isObject(data) || isModule(data)) && data.default) return data.default;
|
|
@@ -533,14 +533,14 @@ function getExtension(path) {
|
|
|
533
533
|
//#region src/utils/file.ts
|
|
534
534
|
function getFileInfo(target = "", { backupFilename = "filename", extension = ".ts" } = {}) {
|
|
535
535
|
const isDir = isDirectory(target);
|
|
536
|
-
const filePath = isDir ?
|
|
536
|
+
const filePath = isDir ? nodePath.join(target, backupFilename + extension) : target;
|
|
537
537
|
return {
|
|
538
538
|
path: filePath,
|
|
539
539
|
pathWithoutExtension: filePath.replace(/\.[^/.]+$/, ""),
|
|
540
540
|
extension,
|
|
541
541
|
isDirectory: isDir,
|
|
542
|
-
dirname:
|
|
543
|
-
filename:
|
|
542
|
+
dirname: nodePath.dirname(filePath),
|
|
543
|
+
filename: nodePath.basename(filePath, extension.startsWith(".") ? extension : `.${extension}`)
|
|
544
544
|
};
|
|
545
545
|
}
|
|
546
546
|
async function removeFilesAndEmptyFolders(patterns, dir) {
|
|
@@ -754,13 +754,13 @@ function toUnix(value) {
|
|
|
754
754
|
return value;
|
|
755
755
|
}
|
|
756
756
|
function join(...args) {
|
|
757
|
-
return toUnix(
|
|
757
|
+
return toUnix(nodePath.join(...args.map((a) => toUnix(a))));
|
|
758
758
|
}
|
|
759
759
|
/**
|
|
760
760
|
* Behaves exactly like `path.relative(from, to)`, but keeps the first meaningful "./"
|
|
761
761
|
*/
|
|
762
762
|
function relativeSafe(from, to) {
|
|
763
|
-
return normalizeSafe(`./${toUnix(
|
|
763
|
+
return normalizeSafe(`./${toUnix(nodePath.relative(toUnix(from), toUnix(to)))}`);
|
|
764
764
|
}
|
|
765
765
|
function getSchemaFileName(path) {
|
|
766
766
|
return path.replace(`.${getExtension(path)}`, "").slice(path.lastIndexOf("/") + 1);
|
|
@@ -768,13 +768,13 @@ function getSchemaFileName(path) {
|
|
|
768
768
|
function normalizeSafe(value) {
|
|
769
769
|
let result;
|
|
770
770
|
value = toUnix(value);
|
|
771
|
-
result = toUnix(
|
|
771
|
+
result = toUnix(nodePath.normalize(value));
|
|
772
772
|
if (value.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
773
773
|
else if (value.startsWith("//") && !result.startsWith("//")) result = value.startsWith("//./") ? "//." + result : "/" + result;
|
|
774
774
|
return result;
|
|
775
775
|
}
|
|
776
776
|
function joinSafe(...values) {
|
|
777
|
-
let result = toUnix(
|
|
777
|
+
let result = toUnix(nodePath.join(...values.map((v) => toUnix(v))));
|
|
778
778
|
if (values.length > 0) {
|
|
779
779
|
const firstValue = toUnix(values[0]);
|
|
780
780
|
if (firstValue.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
@@ -805,14 +805,14 @@ function joinSafe(...values) {
|
|
|
805
805
|
* @returns The relative import path string.
|
|
806
806
|
*/
|
|
807
807
|
function getRelativeImportPath(importerFilePath, exporterFilePath, includeFileExtension = false) {
|
|
808
|
-
if (!
|
|
809
|
-
if (!
|
|
810
|
-
const importerDir =
|
|
811
|
-
const relativePath =
|
|
812
|
-
let posixPath =
|
|
808
|
+
if (!nodePath.isAbsolute(importerFilePath)) throw new Error(`'importerFilePath' is not an absolute path. "${importerFilePath}"`);
|
|
809
|
+
if (!nodePath.isAbsolute(exporterFilePath)) throw new Error(`'exporterFilePath' is not an absolute path. "${exporterFilePath}"`);
|
|
810
|
+
const importerDir = nodePath.dirname(importerFilePath);
|
|
811
|
+
const relativePath = nodePath.relative(importerDir, exporterFilePath);
|
|
812
|
+
let posixPath = nodePath.posix.join(...relativePath.split(nodePath.sep));
|
|
813
813
|
if (!posixPath.startsWith("./") && !posixPath.startsWith("../")) posixPath = `./${posixPath}`;
|
|
814
814
|
if (!includeFileExtension) {
|
|
815
|
-
const ext =
|
|
815
|
+
const ext = nodePath.extname(posixPath);
|
|
816
816
|
if (ext && posixPath.endsWith(ext)) posixPath = posixPath.slice(0, -ext.length);
|
|
817
817
|
}
|
|
818
818
|
return posixPath;
|
|
@@ -821,20 +821,20 @@ function getRelativeImportPath(importerFilePath, exporterFilePath, includeFileEx
|
|
|
821
821
|
//#region src/utils/resolve-version.ts
|
|
822
822
|
function resolveInstalledVersion(packageName, fromDir) {
|
|
823
823
|
try {
|
|
824
|
-
const require = createRequire(
|
|
824
|
+
const require = createRequire(nodePath.join(fromDir, "noop.js"));
|
|
825
825
|
try {
|
|
826
826
|
return require(`${packageName}/package.json`).version;
|
|
827
827
|
} catch (directError) {
|
|
828
828
|
if (directError instanceof Error && "code" in directError && directError.code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
829
829
|
const entryPath = require.resolve(packageName);
|
|
830
|
-
let dir =
|
|
831
|
-
while (dir !==
|
|
832
|
-
const pkgPath =
|
|
830
|
+
let dir = nodePath.dirname(entryPath);
|
|
831
|
+
while (dir !== nodePath.parse(dir).root) {
|
|
832
|
+
const pkgPath = nodePath.join(dir, "package.json");
|
|
833
833
|
if (existsSync(pkgPath)) {
|
|
834
834
|
const pkgData = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
835
835
|
if (pkgData.name === packageName) return pkgData.version;
|
|
836
836
|
}
|
|
837
|
-
dir =
|
|
837
|
+
dir = nodePath.dirname(dir);
|
|
838
838
|
}
|
|
839
839
|
return;
|
|
840
840
|
}
|
|
@@ -2076,7 +2076,7 @@ function resolveSchemaPropertiesToFormData({ schema, variableName, propName, con
|
|
|
2076
2076
|
if (isUrlEncoded && (fileType || property.format === "binary")) formDataValue = `${variableName}.append(\`${keyPrefix}${key}\`, ${nonOptionalValueKey});\n`;
|
|
2077
2077
|
else if (fileType === "binary" || property.format === "binary") formDataValue = `${variableName}.append(\`${keyPrefix}${key}\`, ${nonOptionalValueKey});\n`;
|
|
2078
2078
|
else if (fileType === "text") formDataValue = `${variableName}.append(\`${keyPrefix}${key}\`, ${nonOptionalValueKey} instanceof Blob ? ${nonOptionalValueKey} : new Blob([${nonOptionalValueKey}], { type: '${effectiveContentType}' }));\n`;
|
|
2079
|
-
else if (property.type === "object") formDataValue = context.output.override.formData.arrayHandling === FormDataArrayHandling.EXPLODE ? resolveSchemaPropertiesToFormData({
|
|
2079
|
+
else if (property.type === "object" || Array.isArray(property.type) && property.type.includes("object")) formDataValue = context.output.override.formData.arrayHandling === FormDataArrayHandling.EXPLODE ? resolveSchemaPropertiesToFormData({
|
|
2080
2080
|
schema: property,
|
|
2081
2081
|
variableName,
|
|
2082
2082
|
propName: nonOptionalValueKey,
|
|
@@ -2086,7 +2086,7 @@ function resolveSchemaPropertiesToFormData({ schema, variableName, propName, con
|
|
|
2086
2086
|
depth: depth + 1,
|
|
2087
2087
|
encoding
|
|
2088
2088
|
}) : `${variableName}.append(\`${keyPrefix}${key}\`, JSON.stringify(${nonOptionalValueKey}));\n`;
|
|
2089
|
-
else if (property.type === "array") {
|
|
2089
|
+
else if (property.type === "array" || Array.isArray(property.type) && property.type.includes("array")) {
|
|
2090
2090
|
let valueStr = "value";
|
|
2091
2091
|
let hasNonPrimitiveChild = false;
|
|
2092
2092
|
const propertyItems = getSchemaItems(property);
|
|
@@ -4636,8 +4636,8 @@ function getSchema({ schema: { imports, model }, header, namingConvention = Nami
|
|
|
4636
4636
|
file += model;
|
|
4637
4637
|
return file;
|
|
4638
4638
|
}
|
|
4639
|
-
function getPath(path
|
|
4640
|
-
return
|
|
4639
|
+
function getPath(path, name, fileExtension) {
|
|
4640
|
+
return nodePath.join(path, `${name}${fileExtension}`);
|
|
4641
4641
|
}
|
|
4642
4642
|
function writeModelInline(acc, model) {
|
|
4643
4643
|
return acc + `${model}\n`;
|
|
@@ -4689,7 +4689,7 @@ async function writeSchemas({ schemaPath, schemas, target, namingConvention, fil
|
|
|
4689
4689
|
});
|
|
4690
4690
|
}
|
|
4691
4691
|
if (indexFiles) {
|
|
4692
|
-
const schemaFilePath =
|
|
4692
|
+
const schemaFilePath = nodePath.join(schemaPath, `index.ts`);
|
|
4693
4693
|
await fs$1.ensureFile(schemaFilePath);
|
|
4694
4694
|
const ext = getImportExtension(fileExtension, tsconfig);
|
|
4695
4695
|
const conventionNamesSet = new Set(Object.values(schemaGroups).map((group) => conventionName(group[0].name, namingConvention)));
|
|
@@ -5000,7 +5000,7 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
5000
5000
|
packageJson: output.packageJson,
|
|
5001
5001
|
output
|
|
5002
5002
|
});
|
|
5003
|
-
const schemasPath = !output.schemas && needSchema ?
|
|
5003
|
+
const schemasPath = !output.schemas && needSchema ? nodePath.join(dirname, filename + ".schemas" + extension) : void 0;
|
|
5004
5004
|
if (schemasPath) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
5005
5005
|
if (mutators) implementationData += generateMutatorImports({
|
|
5006
5006
|
mutators,
|
|
@@ -5022,7 +5022,7 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
5022
5022
|
}
|
|
5023
5023
|
implementationData += `\n${implementation}`;
|
|
5024
5024
|
const implementationFilename = filename + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
5025
|
-
const implementationPath =
|
|
5025
|
+
const implementationPath = nodePath.join(dirname, implementationFilename);
|
|
5026
5026
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
5027
5027
|
const mockPaths = [];
|
|
5028
5028
|
for (const mockOutput of mockOutputs) {
|
|
@@ -5039,7 +5039,7 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
5039
5039
|
options: entry
|
|
5040
5040
|
});
|
|
5041
5041
|
mockData += `\n${mockOutput.implementation}`;
|
|
5042
|
-
const mockPath =
|
|
5042
|
+
const mockPath = nodePath.join(dirname, filename + "." + getMockFileExtensionByTypeName(entry) + extension);
|
|
5043
5043
|
await writeGeneratedFile(mockPath, mockData);
|
|
5044
5044
|
mockPaths.push(mockPath);
|
|
5045
5045
|
}
|
|
@@ -5235,7 +5235,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
5235
5235
|
const indexFilePathsByType = /* @__PURE__ */ new Map();
|
|
5236
5236
|
if (output.mock.indexMockFiles) for (const entry of generatorEntries) {
|
|
5237
5237
|
const ext = getMockFileExtensionByTypeName(entry);
|
|
5238
|
-
const indexPath =
|
|
5238
|
+
const indexPath = nodePath.join(dirname, `index.${ext}${extension}`);
|
|
5239
5239
|
indexFilePathsByType.set(ext, indexPath);
|
|
5240
5240
|
await fs$1.outputFile(indexPath, "");
|
|
5241
5241
|
}
|
|
@@ -5244,19 +5244,19 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
5244
5244
|
try {
|
|
5245
5245
|
const { imports, implementation, mockOutputs, mutators, clientMutators, formData, fetchReviver, formUrlEncoded, paramsSerializer, paramsFilter } = target;
|
|
5246
5246
|
let implementationData = header;
|
|
5247
|
-
const importerPath =
|
|
5247
|
+
const importerPath = nodePath.join(dirname, tag, tag + extension);
|
|
5248
5248
|
const relativeSchemasPath = output.schemas ? getRelativeImportPath(importerPath, getFileInfo(isString(output.schemas) ? output.schemas : output.schemas.path, { extension: output.fileExtension }).dirname) : "../" + filename + ".schemas" + extension.replace(/\.ts$/, "");
|
|
5249
5249
|
const tagNames = new Set(tagEntries.map(([t]) => t));
|
|
5250
5250
|
const serviceSuffix = OutputClient.ANGULAR === output.client ? ".service" : "";
|
|
5251
5251
|
const importsForBuilder = generateImportsForBuilder(output, imports.map((imp) => {
|
|
5252
5252
|
if (!imp.importPath) return imp;
|
|
5253
5253
|
if (!imp.importPath.startsWith(".")) return imp;
|
|
5254
|
-
const resolvedPath =
|
|
5255
|
-
const targetBasename =
|
|
5254
|
+
const resolvedPath = nodePath.resolve(dirname, imp.importPath);
|
|
5255
|
+
const targetBasename = nodePath.basename(resolvedPath);
|
|
5256
5256
|
let targetFile;
|
|
5257
5257
|
if (tagNames.has(targetBasename)) {
|
|
5258
5258
|
const tagFilename = targetBasename + serviceSuffix + extension;
|
|
5259
|
-
targetFile =
|
|
5259
|
+
targetFile = nodePath.join(resolvedPath, tagFilename);
|
|
5260
5260
|
} else targetFile = resolvedPath + extension;
|
|
5261
5261
|
const adjustedPath = getRelativeImportPath(importerPath, targetFile);
|
|
5262
5262
|
return {
|
|
@@ -5277,7 +5277,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
5277
5277
|
packageJson: output.packageJson,
|
|
5278
5278
|
output
|
|
5279
5279
|
});
|
|
5280
|
-
const schemasPath = !output.schemas && needSchema ?
|
|
5280
|
+
const schemasPath = !output.schemas && needSchema ? nodePath.join(dirname, filename + ".schemas" + extension) : void 0;
|
|
5281
5281
|
if (schemasPath) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
5282
5282
|
if (mutators) implementationData += generateMutatorImports({
|
|
5283
5283
|
mutators,
|
|
@@ -5318,7 +5318,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
5318
5318
|
}
|
|
5319
5319
|
implementationData += `\n${implementation}`;
|
|
5320
5320
|
const implementationFilename = tag + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
5321
|
-
const implementationPath =
|
|
5321
|
+
const implementationPath = nodePath.join(dirname, tag, implementationFilename);
|
|
5322
5322
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
5323
5323
|
const mockPaths = [];
|
|
5324
5324
|
for (const mockOutput of mockOutputs) {
|
|
@@ -5335,7 +5335,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
5335
5335
|
options: entry
|
|
5336
5336
|
});
|
|
5337
5337
|
mockData += `\n${mockOutput.implementation}`;
|
|
5338
|
-
const mockPath =
|
|
5338
|
+
const mockPath = nodePath.join(dirname, tag, tag + "." + getMockFileExtensionByTypeName(entry) + extension);
|
|
5339
5339
|
await writeGeneratedFile(mockPath, mockData);
|
|
5340
5340
|
mockPaths.push(mockPath);
|
|
5341
5341
|
}
|
|
@@ -5413,7 +5413,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema,
|
|
|
5413
5413
|
options: entry && !isFunction(entry) ? entry : void 0
|
|
5414
5414
|
});
|
|
5415
5415
|
}
|
|
5416
|
-
const schemasPath = !output.schemas && needSchema ?
|
|
5416
|
+
const schemasPath = !output.schemas && needSchema ? nodePath.join(dirname, filename + ".schemas" + extension) : void 0;
|
|
5417
5417
|
if (schemasPath) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
5418
5418
|
if (mutators) data += generateMutatorImports({
|
|
5419
5419
|
mutators,
|
|
@@ -5439,7 +5439,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema,
|
|
|
5439
5439
|
data += "\n\n";
|
|
5440
5440
|
data += implementationMock;
|
|
5441
5441
|
}
|
|
5442
|
-
const implementationPath =
|
|
5442
|
+
const implementationPath = nodePath.join(dirname, `${kebab(tag)}${extension}`);
|
|
5443
5443
|
await writeGeneratedFile(implementationPath, data);
|
|
5444
5444
|
return [implementationPath, ...schemasPath ? [schemasPath] : []];
|
|
5445
5445
|
} catch (error) {
|