@orval/core 8.9.1 → 8.10.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.d.mts +2 -2
- package/dist/index.mjs +113 -81
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -836,7 +836,7 @@ interface Tsconfig {
|
|
|
836
836
|
target?: TsConfigTarget;
|
|
837
837
|
};
|
|
838
838
|
}
|
|
839
|
-
type TsConfigTarget = 'es3' | 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext';
|
|
839
|
+
type TsConfigTarget = 'es3' | 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023' | 'es2024' | 'es2025' | 'esnext';
|
|
840
840
|
interface PackageJson {
|
|
841
841
|
dependencies?: Record<string, string>;
|
|
842
842
|
devDependencies?: Record<string, string>;
|
|
@@ -1369,7 +1369,7 @@ interface GenerateFormDataAndUrlEncodedFunctionOptions {
|
|
|
1369
1369
|
isFormData: boolean;
|
|
1370
1370
|
isFormUrlEncoded: boolean;
|
|
1371
1371
|
}
|
|
1372
|
-
declare function generateBodyOptions(body: GetterBody, isFormData: boolean, isFormUrlEncoded: boolean): string;
|
|
1372
|
+
declare function generateBodyOptions(body: GetterBody, isFormData: boolean, isFormUrlEncoded: boolean): string | undefined;
|
|
1373
1373
|
interface GenerateAxiosOptions {
|
|
1374
1374
|
response: GetterResponse;
|
|
1375
1375
|
isExactOptionalPropertyTypes: boolean;
|
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, 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";
|
|
@@ -137,7 +137,7 @@ function isReference(obj) {
|
|
|
137
137
|
return !isNullish$1(obj) && Object.hasOwn(obj, "$ref");
|
|
138
138
|
}
|
|
139
139
|
function isDirectory(pathValue) {
|
|
140
|
-
return !
|
|
140
|
+
return !path.extname(pathValue);
|
|
141
141
|
}
|
|
142
142
|
function isObject(x) {
|
|
143
143
|
return Object.prototype.toString.call(x) === "[object Object]";
|
|
@@ -450,8 +450,8 @@ async function dynamicImport(toImport, from = process.cwd(), takeDefault = true)
|
|
|
450
450
|
if (!toImport) return toImport;
|
|
451
451
|
try {
|
|
452
452
|
if (isString(toImport)) {
|
|
453
|
-
const filePath =
|
|
454
|
-
const extension =
|
|
453
|
+
const filePath = path.resolve(from, toImport);
|
|
454
|
+
const extension = path.extname(filePath);
|
|
455
455
|
if (TS_MODULE_EXTENSIONS.has(extension)) {
|
|
456
456
|
const data = await createJiti(from, { interopDefault: true }).import(filePath);
|
|
457
457
|
if (takeDefault && (isObject(data) || isModule(data)) && data.default) return data.default;
|
|
@@ -476,14 +476,14 @@ function getExtension(path) {
|
|
|
476
476
|
//#region src/utils/file.ts
|
|
477
477
|
function getFileInfo(target = "", { backupFilename = "filename", extension = ".ts" } = {}) {
|
|
478
478
|
const isDir = isDirectory(target);
|
|
479
|
-
const filePath = isDir ?
|
|
479
|
+
const filePath = isDir ? path.join(target, backupFilename + extension) : target;
|
|
480
480
|
return {
|
|
481
481
|
path: filePath,
|
|
482
482
|
pathWithoutExtension: filePath.replace(/\.[^/.]+$/, ""),
|
|
483
483
|
extension,
|
|
484
484
|
isDirectory: isDir,
|
|
485
|
-
dirname:
|
|
486
|
-
filename:
|
|
485
|
+
dirname: path.dirname(filePath),
|
|
486
|
+
filename: path.basename(filePath, extension.startsWith(".") ? extension : `.${extension}`)
|
|
487
487
|
};
|
|
488
488
|
}
|
|
489
489
|
async function removeFilesAndEmptyFolders(patterns, dir) {
|
|
@@ -691,13 +691,13 @@ function toUnix(value) {
|
|
|
691
691
|
return value;
|
|
692
692
|
}
|
|
693
693
|
function join(...args) {
|
|
694
|
-
return toUnix(
|
|
694
|
+
return toUnix(path.join(...args.map((a) => toUnix(a))));
|
|
695
695
|
}
|
|
696
696
|
/**
|
|
697
697
|
* Behaves exactly like `path.relative(from, to)`, but keeps the first meaningful "./"
|
|
698
698
|
*/
|
|
699
699
|
function relativeSafe(from, to) {
|
|
700
|
-
return normalizeSafe(`./${toUnix(
|
|
700
|
+
return normalizeSafe(`./${toUnix(path.relative(toUnix(from), toUnix(to)))}`);
|
|
701
701
|
}
|
|
702
702
|
function getSchemaFileName(path) {
|
|
703
703
|
return path.replace(`.${getExtension(path)}`, "").slice(path.lastIndexOf("/") + 1);
|
|
@@ -705,13 +705,13 @@ function getSchemaFileName(path) {
|
|
|
705
705
|
function normalizeSafe(value) {
|
|
706
706
|
let result;
|
|
707
707
|
value = toUnix(value);
|
|
708
|
-
result = toUnix(
|
|
708
|
+
result = toUnix(path.normalize(value));
|
|
709
709
|
if (value.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
710
710
|
else if (value.startsWith("//") && !result.startsWith("//")) result = value.startsWith("//./") ? "//." + result : "/" + result;
|
|
711
711
|
return result;
|
|
712
712
|
}
|
|
713
713
|
function joinSafe(...values) {
|
|
714
|
-
let result = toUnix(
|
|
714
|
+
let result = toUnix(path.join(...values.map((v) => toUnix(v))));
|
|
715
715
|
if (values.length > 0) {
|
|
716
716
|
const firstValue = toUnix(values[0]);
|
|
717
717
|
if (firstValue.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) result = "./" + result;
|
|
@@ -742,14 +742,14 @@ function joinSafe(...values) {
|
|
|
742
742
|
* @returns The relative import path string.
|
|
743
743
|
*/
|
|
744
744
|
function getRelativeImportPath(importerFilePath, exporterFilePath, includeFileExtension = false) {
|
|
745
|
-
if (!
|
|
746
|
-
if (!
|
|
747
|
-
const importerDir =
|
|
748
|
-
const relativePath =
|
|
749
|
-
let posixPath =
|
|
745
|
+
if (!path.isAbsolute(importerFilePath)) throw new Error(`'importerFilePath' is not an absolute path. "${importerFilePath}"`);
|
|
746
|
+
if (!path.isAbsolute(exporterFilePath)) throw new Error(`'exporterFilePath' is not an absolute path. "${exporterFilePath}"`);
|
|
747
|
+
const importerDir = path.dirname(importerFilePath);
|
|
748
|
+
const relativePath = path.relative(importerDir, exporterFilePath);
|
|
749
|
+
let posixPath = path.posix.join(...relativePath.split(path.sep));
|
|
750
750
|
if (!posixPath.startsWith("./") && !posixPath.startsWith("../")) posixPath = `./${posixPath}`;
|
|
751
751
|
if (!includeFileExtension) {
|
|
752
|
-
const ext =
|
|
752
|
+
const ext = path.extname(posixPath);
|
|
753
753
|
if (ext && posixPath.endsWith(ext)) posixPath = posixPath.slice(0, -ext.length);
|
|
754
754
|
}
|
|
755
755
|
return posixPath;
|
|
@@ -758,20 +758,20 @@ function getRelativeImportPath(importerFilePath, exporterFilePath, includeFileEx
|
|
|
758
758
|
//#region src/utils/resolve-version.ts
|
|
759
759
|
function resolveInstalledVersion(packageName, fromDir) {
|
|
760
760
|
try {
|
|
761
|
-
const require = createRequire(
|
|
761
|
+
const require = createRequire(path.join(fromDir, "noop.js"));
|
|
762
762
|
try {
|
|
763
763
|
return require(`${packageName}/package.json`).version;
|
|
764
764
|
} catch (directError) {
|
|
765
765
|
if (directError instanceof Error && "code" in directError && directError.code === "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
766
766
|
const entryPath = require.resolve(packageName);
|
|
767
|
-
let dir =
|
|
768
|
-
while (dir !==
|
|
769
|
-
const pkgPath =
|
|
767
|
+
let dir = path.dirname(entryPath);
|
|
768
|
+
while (dir !== path.parse(dir).root) {
|
|
769
|
+
const pkgPath = path.join(dir, "package.json");
|
|
770
770
|
if (existsSync(pkgPath)) {
|
|
771
771
|
const pkgData = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
772
772
|
if (pkgData.name === packageName) return pkgData.version;
|
|
773
773
|
}
|
|
774
|
-
dir =
|
|
774
|
+
dir = path.dirname(dir);
|
|
775
775
|
}
|
|
776
776
|
return;
|
|
777
777
|
}
|
|
@@ -1543,7 +1543,7 @@ function getArray({ schema, name, context, formDataContext }) {
|
|
|
1543
1543
|
formDataContext
|
|
1544
1544
|
});
|
|
1545
1545
|
return {
|
|
1546
|
-
value: `${schema.readOnly === true && !context.output.override.suppressReadonlyModifier ? "readonly " : ""}${resolvedObject.value.includes("|") ? `(${resolvedObject.value})[]` : `${resolvedObject.value}[]`}`,
|
|
1546
|
+
value: `${schema.readOnly === true && !context.output.override.suppressReadonlyModifier ? "readonly " : ""}${resolvedObject.value.includes("|") || resolvedObject.value.includes("&") ? `(${resolvedObject.value})[]` : `${resolvedObject.value}[]`}`,
|
|
1547
1547
|
imports: resolvedObject.imports,
|
|
1548
1548
|
schemas: resolvedObject.schemas,
|
|
1549
1549
|
dependencies: resolvedObject.dependencies,
|
|
@@ -2108,30 +2108,59 @@ function getKey(key) {
|
|
|
2108
2108
|
}
|
|
2109
2109
|
//#endregion
|
|
2110
2110
|
//#region src/getters/object.ts
|
|
2111
|
+
function getPropertyNamesEnumKeyType(item) {
|
|
2112
|
+
if (!("propertyNames" in item) || !item.propertyNames) return;
|
|
2113
|
+
const propertyNames = item.propertyNames;
|
|
2114
|
+
if (Array.isArray(propertyNames.enum)) {
|
|
2115
|
+
const enumValues = propertyNames.enum.filter((val) => isString(val));
|
|
2116
|
+
if (enumValues.length > 0) return {
|
|
2117
|
+
value: enumValues.map((val) => `'${escape(val)}'`).join(" | "),
|
|
2118
|
+
imports: [],
|
|
2119
|
+
dependencies: []
|
|
2120
|
+
};
|
|
2121
|
+
}
|
|
2122
|
+
if (isString(propertyNames.const)) return {
|
|
2123
|
+
value: `'${escape(propertyNames.const)}'`,
|
|
2124
|
+
imports: [],
|
|
2125
|
+
dependencies: []
|
|
2126
|
+
};
|
|
2127
|
+
}
|
|
2111
2128
|
/**
|
|
2112
|
-
*
|
|
2113
|
-
*
|
|
2114
|
-
* Returns undefined if propertyNames has neither
|
|
2129
|
+
* Resolve a narrowed key type from OpenAPI 3.1 propertyNames.
|
|
2130
|
+
* Supports inline enum/const and $ref string enums.
|
|
2115
2131
|
*/
|
|
2116
|
-
function
|
|
2117
|
-
|
|
2132
|
+
function getPropertyNamesKeyType(item, context) {
|
|
2133
|
+
const inlineKeyType = getPropertyNamesEnumKeyType(item);
|
|
2134
|
+
if (inlineKeyType) return inlineKeyType;
|
|
2118
2135
|
const propertyNames = item.propertyNames;
|
|
2119
|
-
if (
|
|
2120
|
-
|
|
2136
|
+
if (!propertyNames || !isReference(propertyNames)) return;
|
|
2137
|
+
const resolvedValue = resolveValue({
|
|
2138
|
+
schema: propertyNames,
|
|
2139
|
+
context
|
|
2140
|
+
});
|
|
2141
|
+
const resolvedConst = resolvedValue.originalSchema.const;
|
|
2142
|
+
const isStringConst = resolvedValue.type === "string" && isString(resolvedConst);
|
|
2143
|
+
if (!resolvedValue.isEnum && !isStringConst) return;
|
|
2144
|
+
return {
|
|
2145
|
+
value: resolvedValue.value,
|
|
2146
|
+
imports: resolvedValue.imports,
|
|
2147
|
+
dependencies: resolvedValue.dependencies
|
|
2148
|
+
};
|
|
2121
2149
|
}
|
|
2122
2150
|
/**
|
|
2123
2151
|
* Generate index signature key type based on propertyNames enum or const
|
|
2124
2152
|
* Returns union type string like "'foo' | 'bar'", "'x'", or 'string' if neither
|
|
2125
2153
|
*/
|
|
2126
2154
|
function getIndexSignatureKey(item) {
|
|
2127
|
-
|
|
2128
|
-
if (enumValues && enumValues.length > 0) return enumValues.map((val) => `'${val}'`).join(" | ");
|
|
2129
|
-
return "string";
|
|
2155
|
+
return getPropertyNamesEnumKeyType(item)?.value ?? "string";
|
|
2130
2156
|
}
|
|
2131
|
-
function getPropertyNamesRecordType(item, valueType) {
|
|
2132
|
-
const
|
|
2133
|
-
if (!
|
|
2134
|
-
return
|
|
2157
|
+
function getPropertyNamesRecordType(item, valueType, context) {
|
|
2158
|
+
const keyType = getPropertyNamesKeyType(item, context);
|
|
2159
|
+
if (!keyType) return;
|
|
2160
|
+
return {
|
|
2161
|
+
...keyType,
|
|
2162
|
+
value: `Partial<Record<${keyType.value}, ${valueType}>>`
|
|
2163
|
+
};
|
|
2135
2164
|
}
|
|
2136
2165
|
/**
|
|
2137
2166
|
* Return the output type from an object
|
|
@@ -2185,7 +2214,7 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
2185
2214
|
if (itemProperties && Object.entries(itemProperties).length > 0) {
|
|
2186
2215
|
const entries = Object.entries(itemProperties);
|
|
2187
2216
|
if (context.output.propertySortOrder === PropertySortOrder.ALPHABETICAL) entries.sort((a, b) => {
|
|
2188
|
-
return a[0].localeCompare(b[0]);
|
|
2217
|
+
return a[0].localeCompare(b[0], "en", { numeric: true });
|
|
2189
2218
|
});
|
|
2190
2219
|
const acc = {
|
|
2191
2220
|
imports: [],
|
|
@@ -2257,11 +2286,13 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
2257
2286
|
if (entries.length - 1 === index) {
|
|
2258
2287
|
const additionalProps = schemaItem.additionalProperties;
|
|
2259
2288
|
if (additionalProps) if (additionalProps === true) {
|
|
2260
|
-
const recordType = getPropertyNamesRecordType(schemaItem, "unknown");
|
|
2289
|
+
const recordType = getPropertyNamesRecordType(schemaItem, "unknown", context);
|
|
2261
2290
|
if (recordType) {
|
|
2262
2291
|
acc.value += "\n}";
|
|
2263
|
-
acc.value += ` & ${recordType}`;
|
|
2292
|
+
acc.value += ` & ${recordType.value}`;
|
|
2264
2293
|
acc.useTypeAlias = true;
|
|
2294
|
+
acc.imports.push(...recordType.imports);
|
|
2295
|
+
acc.dependencies.push(...recordType.dependencies);
|
|
2265
2296
|
} else {
|
|
2266
2297
|
const keyType = getIndexSignatureKey(schemaItem);
|
|
2267
2298
|
acc.value += `\n [key: ${keyType}]: unknown;\n }`;
|
|
@@ -2272,11 +2303,13 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
2272
2303
|
name,
|
|
2273
2304
|
context
|
|
2274
2305
|
});
|
|
2275
|
-
const recordType = getPropertyNamesRecordType(schemaItem, resolvedValue.value);
|
|
2306
|
+
const recordType = getPropertyNamesRecordType(schemaItem, resolvedValue.value, context);
|
|
2276
2307
|
if (recordType) {
|
|
2277
2308
|
acc.value += "\n}";
|
|
2278
|
-
acc.value += ` & ${recordType}`;
|
|
2309
|
+
acc.value += ` & ${recordType.value}`;
|
|
2279
2310
|
acc.useTypeAlias = true;
|
|
2311
|
+
acc.imports.push(...recordType.imports);
|
|
2312
|
+
acc.dependencies.push(...recordType.dependencies);
|
|
2280
2313
|
} else {
|
|
2281
2314
|
const keyType = getIndexSignatureKey(schemaItem);
|
|
2282
2315
|
acc.value += `\n [key: ${keyType}]: ${resolvedValue.value};\n}`;
|
|
@@ -2295,17 +2328,17 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
2295
2328
|
const readOnlyFlag = schemaItem.readOnly;
|
|
2296
2329
|
if (outerAdditionalProps) {
|
|
2297
2330
|
if (outerAdditionalProps === true) {
|
|
2298
|
-
const recordType = getPropertyNamesRecordType(schemaItem, "unknown");
|
|
2331
|
+
const recordType = getPropertyNamesRecordType(schemaItem, "unknown", context);
|
|
2299
2332
|
if (recordType) return {
|
|
2300
|
-
value: recordType + nullable,
|
|
2301
|
-
imports:
|
|
2333
|
+
value: recordType.value + nullable,
|
|
2334
|
+
imports: recordType.imports,
|
|
2302
2335
|
schemas: [],
|
|
2303
2336
|
isEnum: false,
|
|
2304
2337
|
type: "object",
|
|
2305
2338
|
isRef: false,
|
|
2306
2339
|
hasReadonlyProps: readOnlyFlag ?? false,
|
|
2307
2340
|
useTypeAlias: true,
|
|
2308
|
-
dependencies:
|
|
2341
|
+
dependencies: recordType.dependencies
|
|
2309
2342
|
};
|
|
2310
2343
|
return {
|
|
2311
2344
|
value: `{ [key: ${getIndexSignatureKey(schemaItem)}]: unknown }` + nullable,
|
|
@@ -2324,17 +2357,17 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
2324
2357
|
name,
|
|
2325
2358
|
context
|
|
2326
2359
|
});
|
|
2327
|
-
const recordType = getPropertyNamesRecordType(schemaItem, resolvedValue.value);
|
|
2360
|
+
const recordType = getPropertyNamesRecordType(schemaItem, resolvedValue.value, context);
|
|
2328
2361
|
if (recordType) return {
|
|
2329
|
-
value: recordType + nullable,
|
|
2330
|
-
imports: resolvedValue.imports,
|
|
2362
|
+
value: recordType.value + nullable,
|
|
2363
|
+
imports: [...recordType.imports, ...resolvedValue.imports],
|
|
2331
2364
|
schemas: resolvedValue.schemas,
|
|
2332
2365
|
isEnum: false,
|
|
2333
2366
|
type: "object",
|
|
2334
2367
|
isRef: false,
|
|
2335
2368
|
hasReadonlyProps: resolvedValue.hasReadonlyProps,
|
|
2336
2369
|
useTypeAlias: true,
|
|
2337
|
-
dependencies: resolvedValue.dependencies
|
|
2370
|
+
dependencies: [...recordType.dependencies, ...resolvedValue.dependencies]
|
|
2338
2371
|
};
|
|
2339
2372
|
return {
|
|
2340
2373
|
value: `{[key: ${getIndexSignatureKey(schemaItem)}]: ${resolvedValue.value}}` + nullable,
|
|
@@ -2369,17 +2402,17 @@ function getObject({ item, name, context, nullable, formDataContext }) {
|
|
|
2369
2402
|
};
|
|
2370
2403
|
}
|
|
2371
2404
|
const keyType = itemType === "object" ? getIndexSignatureKey(schemaItem) : "string";
|
|
2372
|
-
const recordType = getPropertyNamesRecordType(schemaItem, "unknown");
|
|
2405
|
+
const recordType = getPropertyNamesRecordType(schemaItem, "unknown", context);
|
|
2373
2406
|
if (itemType === "object" && recordType) return {
|
|
2374
|
-
value: recordType + nullable,
|
|
2375
|
-
imports:
|
|
2407
|
+
value: recordType.value + nullable,
|
|
2408
|
+
imports: recordType.imports,
|
|
2376
2409
|
schemas: [],
|
|
2377
2410
|
isEnum: false,
|
|
2378
2411
|
type: "object",
|
|
2379
2412
|
isRef: false,
|
|
2380
2413
|
hasReadonlyProps: readOnlyFlag ?? false,
|
|
2381
2414
|
useTypeAlias: true,
|
|
2382
|
-
dependencies:
|
|
2415
|
+
dependencies: recordType.dependencies
|
|
2383
2416
|
};
|
|
2384
2417
|
return {
|
|
2385
2418
|
value: (itemType === "object" ? `{ [key: ${keyType}]: unknown }` : "unknown") + nullable,
|
|
@@ -3076,7 +3109,7 @@ function getResponse({ responses, operationName, context, contentType }) {
|
|
|
3076
3109
|
success: success || (defaultType ?? "unknown"),
|
|
3077
3110
|
errors: errors || (defaultType ?? "unknown")
|
|
3078
3111
|
},
|
|
3079
|
-
isBlob: groupedByStatus.success.some((t) => !!t.contentType && isBinaryContentType(t.contentType)),
|
|
3112
|
+
isBlob: groupedByStatus.success.some((t) => !!t.contentType && isBinaryContentType(t.contentType) || t.value === "Blob" && !t.isRef),
|
|
3080
3113
|
types: groupedByStatus,
|
|
3081
3114
|
contentTypes,
|
|
3082
3115
|
schemas,
|
|
@@ -3213,7 +3246,7 @@ function generateImports({ imports, namingConvention = NamingConvention.CAMEL_CA
|
|
|
3213
3246
|
...imp,
|
|
3214
3247
|
importPath: imp.importPath ?? `./${conventionName(imp.name, namingConvention)}`
|
|
3215
3248
|
})), (imp) => !imp.default && !imp.namespaceImport && !imp.syntheticDefaultImport && !imp.values && !imp.isConstant ? `aggregate|${imp.importPath}` : `single|${imp.importPath}|${imp.name}|${imp.alias ?? ""}|${String(imp.default)}|${String(imp.namespaceImport)}|${String(imp.syntheticDefaultImport)}|${String(imp.values)}|${String(imp.isConstant)}`);
|
|
3216
|
-
return Object.entries(grouped).toSorted(([a], [b]) => a.localeCompare(b)).map(([, group]) => {
|
|
3249
|
+
return Object.entries(grouped).toSorted(([a], [b]) => a.localeCompare(b, "en", { numeric: true })).map(([, group]) => {
|
|
3217
3250
|
const sample = group[0];
|
|
3218
3251
|
if (!sample.default && !sample.namespaceImport && !sample.syntheticDefaultImport && !sample.values && !sample.isConstant) return `import type { ${[...new Set(group.map(({ name, alias }) => `${name}${alias ? ` as ${alias}` : ""}`))].toSorted().join(", ")} } from '${sample.importPath}';`;
|
|
3219
3252
|
const { name, values, alias, isConstant, importPath } = sample;
|
|
@@ -3660,10 +3693,9 @@ function filterParams(
|
|
|
3660
3693
|
*/
|
|
3661
3694
|
const getAngularFilteredParamsCallExpression = (paramsExpression, requiredNullableParamKeys = [], preserveRequiredNullables = false) => `filterParams(${paramsExpression}, new Set<string>(${JSON.stringify(requiredNullableParamKeys)})${preserveRequiredNullables ? ", true" : ""})`;
|
|
3662
3695
|
function generateBodyOptions(body, isFormData, isFormUrlEncoded) {
|
|
3663
|
-
if (isFormData && body.formData) return "
|
|
3664
|
-
if (isFormUrlEncoded && body.formUrlEncoded) return "
|
|
3665
|
-
if (body.implementation) return
|
|
3666
|
-
return "";
|
|
3696
|
+
if (isFormData && body.formData) return "formData";
|
|
3697
|
+
if (isFormUrlEncoded && body.formUrlEncoded) return "formUrlEncoded";
|
|
3698
|
+
if (body.implementation) return body.implementation;
|
|
3667
3699
|
}
|
|
3668
3700
|
function generateAxiosOptions({ response, isExactOptionalPropertyTypes, angularObserve, angularParamsRef, requiredNullableQueryParamKeys, queryParams, headers, requestOptions, hasSignal, hasSignalParam = false, isVue, isAngular, paramsSerializer, paramsSerializerOptions }) {
|
|
3669
3701
|
const isRequestOptions = requestOptions !== false;
|
|
@@ -3710,7 +3742,7 @@ function generateAxiosOptions({ response, isExactOptionalPropertyTypes, angularO
|
|
|
3710
3742
|
return value;
|
|
3711
3743
|
}
|
|
3712
3744
|
function generateOptions({ route, body, angularObserve, angularParamsRef, headers, queryParams, response, verb, requestOptions, isFormData, isFormUrlEncoded, isAngular, isExactOptionalPropertyTypes, hasSignal, hasSignalParam, isVue, paramsSerializer, paramsSerializerOptions }) {
|
|
3713
|
-
const
|
|
3745
|
+
const bodyIdentifier = getIsBodyVerb(verb) ? generateBodyOptions(body, isFormData, isFormUrlEncoded) : void 0;
|
|
3714
3746
|
const axiosOptions = generateAxiosOptions({
|
|
3715
3747
|
response,
|
|
3716
3748
|
angularObserve,
|
|
@@ -3731,11 +3763,11 @@ function generateOptions({ route, body, angularObserve, angularParamsRef, header
|
|
|
3731
3763
|
const isRawOptionsArgument = trimmedAxiosOptions === "options" || trimmedAxiosOptions.startsWith("(") && trimmedAxiosOptions.endsWith(")") || trimmedAxiosOptions.startsWith("{") && trimmedAxiosOptions.endsWith("}");
|
|
3732
3764
|
const optionsArgument = axiosOptions ? isRawOptionsArgument ? axiosOptions : `{${axiosOptions}}` : "";
|
|
3733
3765
|
if (verb === Verbs.DELETE) {
|
|
3734
|
-
if (!
|
|
3766
|
+
if (!bodyIdentifier) return `\n \`${route}\`${optionsArgument ? `,${optionsArgument}` : ""}\n `;
|
|
3735
3767
|
const deleteBodyOptions = isRawOptionsArgument ? `...${optionsArgument}` : axiosOptions;
|
|
3736
|
-
return `\n \`${route}\`,{${isAngular ? "body" : "data"}
|
|
3768
|
+
return `\n \`${route}\`,{${`${isAngular ? "body" : "data"}: ${bodyIdentifier}`}${axiosOptions ? `,${deleteBodyOptions}` : ""}}\n `;
|
|
3737
3769
|
}
|
|
3738
|
-
const bodyOrOptions = getIsBodyVerb(verb) ?
|
|
3770
|
+
const bodyOrOptions = getIsBodyVerb(verb) ? `\n ${bodyIdentifier ?? "undefined"},` : "";
|
|
3739
3771
|
return `\n \`${route}\`${bodyOrOptions || optionsArgument ? "," : ""}${bodyOrOptions}${optionsArgument}\n `;
|
|
3740
3772
|
}
|
|
3741
3773
|
function generateBodyMutatorConfig(body, isFormData, isFormUrlEncoded) {
|
|
@@ -4333,8 +4365,8 @@ function getSchema({ schema: { imports, model }, header, namingConvention = Nami
|
|
|
4333
4365
|
file += model;
|
|
4334
4366
|
return file;
|
|
4335
4367
|
}
|
|
4336
|
-
function getPath(path, name, fileExtension) {
|
|
4337
|
-
return
|
|
4368
|
+
function getPath(path$1, name, fileExtension) {
|
|
4369
|
+
return path.join(path$1, `${name}${fileExtension}`);
|
|
4338
4370
|
}
|
|
4339
4371
|
function writeModelInline(acc, model) {
|
|
4340
4372
|
return acc + `${model}\n`;
|
|
@@ -4383,12 +4415,12 @@ async function writeSchemas({ schemaPath, schemas, target, namingConvention, fil
|
|
|
4383
4415
|
});
|
|
4384
4416
|
}
|
|
4385
4417
|
if (indexFiles) {
|
|
4386
|
-
const schemaFilePath =
|
|
4418
|
+
const schemaFilePath = path.join(schemaPath, `index.ts`);
|
|
4387
4419
|
await fs$1.ensureFile(schemaFilePath);
|
|
4388
4420
|
const ext = fileExtension.endsWith(".ts") ? fileExtension.slice(0, -3) : fileExtension;
|
|
4389
4421
|
const conventionNamesSet = new Set(Object.values(schemaGroups).map((group) => conventionName(group[0].name, namingConvention)));
|
|
4390
4422
|
try {
|
|
4391
|
-
await writeGeneratedFile(schemaFilePath, `${header}\n${[...conventionNamesSet].map((schemaName) => `export * from './${schemaName}${ext}';`).toSorted((a, b) => a.localeCompare(b)).join("\n")}\n`);
|
|
4423
|
+
await writeGeneratedFile(schemaFilePath, `${header}\n${[...conventionNamesSet].map((schemaName) => `export * from './${schemaName}${ext}';`).toSorted((a, b) => a.localeCompare(b, "en", { numeric: true })).join("\n")}\n`);
|
|
4392
4424
|
} catch (error) {
|
|
4393
4425
|
throw new Error(`Oups... 🍻. An Error occurred while writing schema index file ${schemaFilePath} => ${String(error)}`, { cause: error });
|
|
4394
4426
|
}
|
|
@@ -4654,7 +4686,7 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
4654
4686
|
isAllowSyntheticDefaultImports,
|
|
4655
4687
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4656
4688
|
});
|
|
4657
|
-
const schemasPath = !output.schemas && needSchema ?
|
|
4689
|
+
const schemasPath = !output.schemas && needSchema ? path.join(dirname, filename + ".schemas" + extension) : void 0;
|
|
4658
4690
|
if (schemasPath) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
4659
4691
|
if (mutators) implementationData += generateMutatorImports({
|
|
4660
4692
|
mutators,
|
|
@@ -4676,9 +4708,9 @@ async function writeSplitMode({ builder, output, projectName, header, needSchema
|
|
|
4676
4708
|
implementationData += `\n${implementation}`;
|
|
4677
4709
|
mockData += `\n${implementationMock}`;
|
|
4678
4710
|
const implementationFilename = filename + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
4679
|
-
const implementationPath =
|
|
4711
|
+
const implementationPath = path.join(dirname, implementationFilename);
|
|
4680
4712
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
4681
|
-
const mockPath = output.mock ?
|
|
4713
|
+
const mockPath = output.mock ? path.join(dirname, filename + "." + getMockFileExtensionByTypeName(output.mock) + extension) : void 0;
|
|
4682
4714
|
if (mockPath) await writeGeneratedFile(mockPath, mockData);
|
|
4683
4715
|
return [
|
|
4684
4716
|
implementationPath,
|
|
@@ -4813,7 +4845,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4813
4845
|
const target = generateTargetForTags(builder, output);
|
|
4814
4846
|
const isAllowSyntheticDefaultImports = isSyntheticDefaultImportsAllow(output.tsconfig);
|
|
4815
4847
|
const mockOption = output.mock && !isFunction(output.mock) ? output.mock : void 0;
|
|
4816
|
-
const indexFilePath = mockOption?.indexMockFiles ?
|
|
4848
|
+
const indexFilePath = mockOption?.indexMockFiles ? path.join(dirname, "index." + getMockFileExtensionByTypeName(mockOption) + extension) : void 0;
|
|
4817
4849
|
if (indexFilePath) await fs$1.outputFile(indexFilePath, "");
|
|
4818
4850
|
const tagEntries = Object.entries(target);
|
|
4819
4851
|
const generatedFilePathsArray = await Promise.all(tagEntries.map(async ([tag, target]) => {
|
|
@@ -4821,19 +4853,19 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4821
4853
|
const { imports, implementation, implementationMock, importsMock, mutators, clientMutators, formData, fetchReviver, formUrlEncoded, paramsSerializer } = target;
|
|
4822
4854
|
let implementationData = header;
|
|
4823
4855
|
let mockData = header;
|
|
4824
|
-
const importerPath =
|
|
4856
|
+
const importerPath = path.join(dirname, tag, tag + extension);
|
|
4825
4857
|
const relativeSchemasPath = output.schemas ? getRelativeImportPath(importerPath, getFileInfo(isString(output.schemas) ? output.schemas : output.schemas.path, { extension: output.fileExtension }).dirname) : "../" + filename + ".schemas" + extension.replace(/\.ts$/, "");
|
|
4826
4858
|
const tagNames = new Set(tagEntries.map(([t]) => t));
|
|
4827
4859
|
const serviceSuffix = OutputClient.ANGULAR === output.client ? ".service" : "";
|
|
4828
4860
|
const importsForBuilder = generateImportsForBuilder(output, imports.map((imp) => {
|
|
4829
4861
|
if (!imp.importPath) return imp;
|
|
4830
4862
|
if (!imp.importPath.startsWith(".")) return imp;
|
|
4831
|
-
const resolvedPath =
|
|
4832
|
-
const targetBasename =
|
|
4863
|
+
const resolvedPath = path.resolve(dirname, imp.importPath);
|
|
4864
|
+
const targetBasename = path.basename(resolvedPath);
|
|
4833
4865
|
let targetFile;
|
|
4834
4866
|
if (tagNames.has(targetBasename)) {
|
|
4835
4867
|
const tagFilename = targetBasename + serviceSuffix + extension;
|
|
4836
|
-
targetFile =
|
|
4868
|
+
targetFile = path.join(resolvedPath, tagFilename);
|
|
4837
4869
|
} else targetFile = resolvedPath + extension;
|
|
4838
4870
|
const adjustedPath = getRelativeImportPath(importerPath, targetFile);
|
|
4839
4871
|
return {
|
|
@@ -4863,7 +4895,7 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4863
4895
|
isAllowSyntheticDefaultImports,
|
|
4864
4896
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4865
4897
|
});
|
|
4866
|
-
const schemasPath = !output.schemas && needSchema ?
|
|
4898
|
+
const schemasPath = !output.schemas && needSchema ? path.join(dirname, filename + ".schemas" + extension) : void 0;
|
|
4867
4899
|
if (schemasPath) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
4868
4900
|
if (mutators) implementationData += generateMutatorImports({
|
|
4869
4901
|
mutators,
|
|
@@ -4901,9 +4933,9 @@ async function writeSplitTagsMode({ builder, output, projectName, header, needSc
|
|
|
4901
4933
|
implementationData += `\n${implementation}`;
|
|
4902
4934
|
mockData += `\n${implementationMock}`;
|
|
4903
4935
|
const implementationFilename = tag + (OutputClient.ANGULAR === output.client ? ".service" : "") + extension;
|
|
4904
|
-
const implementationPath =
|
|
4936
|
+
const implementationPath = path.join(dirname, tag, implementationFilename);
|
|
4905
4937
|
await writeGeneratedFile(implementationPath, implementationData);
|
|
4906
|
-
const mockPath = output.mock ?
|
|
4938
|
+
const mockPath = output.mock ? path.join(dirname, tag, tag + "." + getMockFileExtensionByTypeName(output.mock) + extension) : void 0;
|
|
4907
4939
|
if (mockPath) await writeGeneratedFile(mockPath, mockData);
|
|
4908
4940
|
return [
|
|
4909
4941
|
implementationPath,
|
|
@@ -4972,7 +5004,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema,
|
|
|
4972
5004
|
options: isFunction(output.mock) ? void 0 : output.mock
|
|
4973
5005
|
});
|
|
4974
5006
|
}
|
|
4975
|
-
const schemasPath = !output.schemas && needSchema ?
|
|
5007
|
+
const schemasPath = !output.schemas && needSchema ? path.join(dirname, filename + ".schemas" + extension) : void 0;
|
|
4976
5008
|
if (schemasPath) await writeGeneratedFile(schemasPath, generateSchemasInline ? header + generateSchemasInline() : header + generateModelsInline(builder.schemas));
|
|
4977
5009
|
if (mutators) data += generateMutatorImports({
|
|
4978
5010
|
mutators,
|
|
@@ -4997,7 +5029,7 @@ async function writeTagsMode({ builder, output, projectName, header, needSchema,
|
|
|
4997
5029
|
data += "\n\n";
|
|
4998
5030
|
data += implementationMock;
|
|
4999
5031
|
}
|
|
5000
|
-
const implementationPath =
|
|
5032
|
+
const implementationPath = path.join(dirname, `${kebab(tag)}${extension}`);
|
|
5001
5033
|
await writeGeneratedFile(implementationPath, data);
|
|
5002
5034
|
return [implementationPath, ...schemasPath ? [schemasPath] : []];
|
|
5003
5035
|
} catch (error) {
|