@orval/core 8.0.2 → 8.0.3
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 +6 -0
- package/dist/index.mjs +39 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1160,6 +1160,7 @@ interface GenerateAxiosOptions {
|
|
|
1160
1160
|
headers?: GeneratorSchema;
|
|
1161
1161
|
requestOptions?: object | boolean;
|
|
1162
1162
|
hasSignal: boolean;
|
|
1163
|
+
hasSignalParam?: boolean;
|
|
1163
1164
|
isVue: boolean;
|
|
1164
1165
|
isAngular: boolean;
|
|
1165
1166
|
paramsSerializer?: GeneratorMutator;
|
|
@@ -1172,6 +1173,7 @@ declare function generateAxiosOptions({
|
|
|
1172
1173
|
headers,
|
|
1173
1174
|
requestOptions,
|
|
1174
1175
|
hasSignal,
|
|
1176
|
+
hasSignalParam,
|
|
1175
1177
|
isVue,
|
|
1176
1178
|
isAngular,
|
|
1177
1179
|
paramsSerializer,
|
|
@@ -1190,6 +1192,7 @@ interface GenerateOptionsOptions {
|
|
|
1190
1192
|
isAngular?: boolean;
|
|
1191
1193
|
isExactOptionalPropertyTypes: boolean;
|
|
1192
1194
|
hasSignal: boolean;
|
|
1195
|
+
hasSignalParam?: boolean;
|
|
1193
1196
|
isVue?: boolean;
|
|
1194
1197
|
paramsSerializer?: GeneratorMutator;
|
|
1195
1198
|
paramsSerializerOptions?: ParamsSerializerOptions;
|
|
@@ -1207,6 +1210,7 @@ declare function generateOptions({
|
|
|
1207
1210
|
isAngular,
|
|
1208
1211
|
isExactOptionalPropertyTypes,
|
|
1209
1212
|
hasSignal,
|
|
1213
|
+
hasSignalParam,
|
|
1210
1214
|
isVue,
|
|
1211
1215
|
paramsSerializer,
|
|
1212
1216
|
paramsSerializerOptions
|
|
@@ -1223,6 +1227,7 @@ interface GenerateMutatorConfigOptions {
|
|
|
1223
1227
|
isFormData: boolean;
|
|
1224
1228
|
isFormUrlEncoded: boolean;
|
|
1225
1229
|
hasSignal: boolean;
|
|
1230
|
+
hasSignalParam?: boolean;
|
|
1226
1231
|
isExactOptionalPropertyTypes: boolean;
|
|
1227
1232
|
isVue?: boolean;
|
|
1228
1233
|
}
|
|
@@ -1236,6 +1241,7 @@ declare function generateMutatorConfig({
|
|
|
1236
1241
|
isFormData,
|
|
1237
1242
|
isFormUrlEncoded,
|
|
1238
1243
|
hasSignal,
|
|
1244
|
+
hasSignalParam,
|
|
1239
1245
|
isExactOptionalPropertyTypes,
|
|
1240
1246
|
isVue
|
|
1241
1247
|
}: GenerateMutatorConfigOptions): string;
|
package/dist/index.mjs
CHANGED
|
@@ -234,7 +234,7 @@ function joinSafe(...values) {
|
|
|
234
234
|
* @param property
|
|
235
235
|
*/
|
|
236
236
|
function isReference(obj) {
|
|
237
|
-
return Object.hasOwn(obj, "$ref");
|
|
237
|
+
return !isNull(obj) && Object.hasOwn(obj, "$ref");
|
|
238
238
|
}
|
|
239
239
|
function isDirectory(path$2) {
|
|
240
240
|
return !extname(path$2);
|
|
@@ -1383,12 +1383,13 @@ function getScalar({ item, name, context }) {
|
|
|
1383
1383
|
function combineValues({ resolvedData, resolvedValue, separator: separator$1, context }) {
|
|
1384
1384
|
if (resolvedData.isEnum.every(Boolean)) return `${resolvedData.values.join(` | `)}${resolvedValue ? ` | ${resolvedValue.value}` : ""}`;
|
|
1385
1385
|
if (separator$1 === "allOf") {
|
|
1386
|
-
let resolvedDataValue = resolvedData.values.join(` & `);
|
|
1386
|
+
let resolvedDataValue = resolvedData.values.map((v) => v.includes(" | ") ? `(${v})` : v).join(` & `);
|
|
1387
1387
|
if (resolvedData.originalSchema.length > 0 && resolvedValue) {
|
|
1388
1388
|
const discriminatedPropertySchemas = resolvedData.originalSchema.filter((s) => s?.discriminator && resolvedValue.value.includes(` ${s.discriminator.propertyName}:`));
|
|
1389
1389
|
if (discriminatedPropertySchemas.length > 0) resolvedDataValue = `Omit<${resolvedDataValue}, '${discriminatedPropertySchemas.map((s) => s.discriminator?.propertyName).join("' | '")}'>`;
|
|
1390
1390
|
}
|
|
1391
|
-
const
|
|
1391
|
+
const resolvedValueStr = resolvedValue?.value.includes(" | ") ? `(${resolvedValue.value})` : resolvedValue?.value;
|
|
1392
|
+
const joined = `${resolvedDataValue}${resolvedValue ? ` & ${resolvedValueStr}` : ""}`;
|
|
1392
1393
|
const overrideRequiredProperties = resolvedData.requiredProperties.filter((prop$1) => !resolvedData.originalSchema.some((schema) => schema?.properties?.[prop$1] && schema.required?.includes(prop$1)));
|
|
1393
1394
|
if (overrideRequiredProperties.length > 0) return `${joined} & Required<Pick<${joined}, '${overrideRequiredProperties.join("' | '")}'>>`;
|
|
1394
1395
|
return joined;
|
|
@@ -1488,6 +1489,16 @@ function combineSchemas({ name, schema, separator: separator$1, context, nullabl
|
|
|
1488
1489
|
name,
|
|
1489
1490
|
context
|
|
1490
1491
|
});
|
|
1492
|
+
else if (separator$1 === "allOf" && (schema.oneOf || schema.anyOf)) {
|
|
1493
|
+
const siblingCombiner = schema.oneOf ? "oneOf" : "anyOf";
|
|
1494
|
+
resolvedValue = combineSchemas({
|
|
1495
|
+
schema: { [siblingCombiner]: schema[siblingCombiner] },
|
|
1496
|
+
name,
|
|
1497
|
+
separator: siblingCombiner,
|
|
1498
|
+
context,
|
|
1499
|
+
nullable: ""
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1491
1502
|
return {
|
|
1492
1503
|
value: combineValues({
|
|
1493
1504
|
resolvedData,
|
|
@@ -1804,10 +1815,15 @@ function getResReqTypes(responsesOrRequests, name, context, defaultType = "unkno
|
|
|
1804
1815
|
if (res.content) return Object.entries(res.content).map(([contentType, mediaType], index, arr) => {
|
|
1805
1816
|
let propName = key ? pascal(name) + pascal(key) : void 0;
|
|
1806
1817
|
if (propName && arr.length > 1) propName = propName + pascal(getNumberWord(index + 1));
|
|
1818
|
+
let effectivePropName = propName;
|
|
1819
|
+
if (mediaType.schema && isReference(mediaType.schema)) {
|
|
1820
|
+
const { imports } = resolveRef(mediaType.schema, context);
|
|
1821
|
+
if (imports[0]?.name) effectivePropName = imports[0].name;
|
|
1822
|
+
}
|
|
1807
1823
|
const isFormData = formDataContentTypes.has(contentType);
|
|
1808
1824
|
const resolvedValue = getResReqContentTypes({
|
|
1809
1825
|
mediaType,
|
|
1810
|
-
propName,
|
|
1826
|
+
propName: effectivePropName,
|
|
1811
1827
|
context,
|
|
1812
1828
|
isFormData,
|
|
1813
1829
|
contentType
|
|
@@ -1827,7 +1843,7 @@ function getResReqTypes(responsesOrRequests, name, context, defaultType = "unkno
|
|
|
1827
1843
|
return;
|
|
1828
1844
|
}
|
|
1829
1845
|
const isFormUrlEncoded = formUrlEncodedContentTypes.has(contentType);
|
|
1830
|
-
if (!isFormData && !isFormUrlEncoded || !
|
|
1846
|
+
if (!isFormData && !isFormUrlEncoded || !effectivePropName) return {
|
|
1831
1847
|
...resolvedValue,
|
|
1832
1848
|
imports: resolvedValue.imports,
|
|
1833
1849
|
contentType,
|
|
@@ -1835,18 +1851,20 @@ function getResReqTypes(responsesOrRequests, name, context, defaultType = "unkno
|
|
|
1835
1851
|
examples: resolveExampleRefs(mediaType.examples, context)
|
|
1836
1852
|
};
|
|
1837
1853
|
const formData = isFormData ? getSchemaFormDataAndUrlEncoded({
|
|
1838
|
-
name:
|
|
1854
|
+
name: effectivePropName,
|
|
1839
1855
|
schemaObject: mediaType.schema,
|
|
1840
1856
|
context,
|
|
1841
1857
|
isRequestBodyOptional: "required" in res && res.required === false,
|
|
1858
|
+
isRef: true,
|
|
1842
1859
|
encoding: mediaType.encoding
|
|
1843
1860
|
}) : void 0;
|
|
1844
1861
|
const formUrlEncoded = isFormUrlEncoded ? getSchemaFormDataAndUrlEncoded({
|
|
1845
|
-
name:
|
|
1862
|
+
name: effectivePropName,
|
|
1846
1863
|
schemaObject: mediaType.schema,
|
|
1847
1864
|
context,
|
|
1848
1865
|
isUrlEncoded: true,
|
|
1849
1866
|
isRequestBodyOptional: "required" in res && res.required === false,
|
|
1867
|
+
isRef: true,
|
|
1850
1868
|
encoding: mediaType.encoding
|
|
1851
1869
|
}) : void 0;
|
|
1852
1870
|
const additionalImports = getFormDataAdditionalImports({
|
|
@@ -2875,18 +2893,20 @@ function generateBodyOptions(body, isFormData, isFormUrlEncoded) {
|
|
|
2875
2893
|
if (body.implementation) return `\n ${body.implementation},`;
|
|
2876
2894
|
return "";
|
|
2877
2895
|
}
|
|
2878
|
-
function generateAxiosOptions({ response, isExactOptionalPropertyTypes, queryParams, headers, requestOptions, hasSignal, isVue, isAngular, paramsSerializer, paramsSerializerOptions }) {
|
|
2896
|
+
function generateAxiosOptions({ response, isExactOptionalPropertyTypes, queryParams, headers, requestOptions, hasSignal, hasSignalParam = false, isVue, isAngular, paramsSerializer, paramsSerializerOptions }) {
|
|
2879
2897
|
const isRequestOptions = requestOptions !== false;
|
|
2898
|
+
const signalVar = hasSignalParam ? "querySignal" : "signal";
|
|
2899
|
+
const signalProp = hasSignalParam ? `signal: ${signalVar}` : "signal";
|
|
2880
2900
|
if (!queryParams && !headers && !response.isBlob && response.definition.success !== "string") {
|
|
2881
2901
|
if (isRequestOptions) return "options";
|
|
2882
|
-
if (hasSignal) return isExactOptionalPropertyTypes ?
|
|
2902
|
+
if (hasSignal) return isExactOptionalPropertyTypes ? `...(${signalVar} ? { ${signalProp} } : {})` : signalProp;
|
|
2883
2903
|
return "";
|
|
2884
2904
|
}
|
|
2885
2905
|
let value = "";
|
|
2886
2906
|
if (!isRequestOptions) {
|
|
2887
2907
|
if (queryParams) value += "\n params,";
|
|
2888
2908
|
if (headers) value += "\n headers,";
|
|
2889
|
-
if (hasSignal) value += isExactOptionalPropertyTypes ?
|
|
2909
|
+
if (hasSignal) value += isExactOptionalPropertyTypes ? `\n ...(${signalVar} ? { ${signalProp} } : {}),` : `\n ${signalProp},`;
|
|
2890
2910
|
}
|
|
2891
2911
|
if (!isObject(requestOptions) || !requestOptions.hasOwnProperty("responseType")) {
|
|
2892
2912
|
if (response.isBlob) value += `\n responseType: 'blob',`;
|
|
@@ -2903,7 +2923,7 @@ function generateAxiosOptions({ response, isExactOptionalPropertyTypes, queryPar
|
|
|
2903
2923
|
if (!isAngular && queryParams && (paramsSerializer || paramsSerializerOptions?.qs)) value += paramsSerializer ? `\n paramsSerializer: ${paramsSerializer.name},` : `\n paramsSerializer: (params) => qs.stringify(params, ${JSON.stringify(paramsSerializerOptions.qs)}),`;
|
|
2904
2924
|
return value;
|
|
2905
2925
|
}
|
|
2906
|
-
function generateOptions({ route, body, headers, queryParams, response, verb, requestOptions, isFormData, isFormUrlEncoded, isAngular, isExactOptionalPropertyTypes, hasSignal, isVue, paramsSerializer, paramsSerializerOptions }) {
|
|
2926
|
+
function generateOptions({ route, body, headers, queryParams, response, verb, requestOptions, isFormData, isFormUrlEncoded, isAngular, isExactOptionalPropertyTypes, hasSignal, hasSignalParam, isVue, paramsSerializer, paramsSerializerOptions }) {
|
|
2907
2927
|
const bodyOptions = getIsBodyVerb(verb) ? generateBodyOptions(body, isFormData, isFormUrlEncoded) : "";
|
|
2908
2928
|
const axiosOptions = generateAxiosOptions({
|
|
2909
2929
|
response,
|
|
@@ -2912,6 +2932,7 @@ function generateOptions({ route, body, headers, queryParams, response, verb, re
|
|
|
2912
2932
|
requestOptions,
|
|
2913
2933
|
isExactOptionalPropertyTypes,
|
|
2914
2934
|
hasSignal,
|
|
2935
|
+
hasSignalParam,
|
|
2915
2936
|
isVue: isVue ?? false,
|
|
2916
2937
|
isAngular: isAngular ?? false,
|
|
2917
2938
|
paramsSerializer,
|
|
@@ -2937,11 +2958,13 @@ function generateQueryParamsAxiosConfig(response, isVue, queryParams) {
|
|
|
2937
2958
|
if (response.isBlob) value += `,\n responseType: 'blob'`;
|
|
2938
2959
|
return value;
|
|
2939
2960
|
}
|
|
2940
|
-
function generateMutatorConfig({ route, body, headers, queryParams, response, verb, isFormData, isFormUrlEncoded, hasSignal, isExactOptionalPropertyTypes, isVue }) {
|
|
2961
|
+
function generateMutatorConfig({ route, body, headers, queryParams, response, verb, isFormData, isFormUrlEncoded, hasSignal, hasSignalParam = false, isExactOptionalPropertyTypes, isVue }) {
|
|
2941
2962
|
const bodyOptions = getIsBodyVerb(verb) ? generateBodyMutatorConfig(body, isFormData, isFormUrlEncoded) : "";
|
|
2942
2963
|
const queryParamsOptions = generateQueryParamsAxiosConfig(response, isVue ?? false, queryParams);
|
|
2943
2964
|
const headerOptions = body.contentType ? `,\n headers: {'Content-Type': '${body.contentType}', ${headers ? "...headers" : ""}}` : headers ? ",\n headers" : "";
|
|
2944
|
-
|
|
2965
|
+
const signalVar = hasSignalParam ? "querySignal" : "signal";
|
|
2966
|
+
const signalProp = hasSignalParam ? `signal: ${signalVar}` : "signal";
|
|
2967
|
+
return `{url: \`${route}\`, method: '${verb.toUpperCase()}'${headerOptions}${bodyOptions}${queryParamsOptions}${hasSignal ? `, ${isExactOptionalPropertyTypes ? `...(${signalVar} ? { ${signalProp} }: {})` : signalProp}` : ""}\n }`;
|
|
2945
2968
|
}
|
|
2946
2969
|
function generateMutatorRequestOptions(requestOptions, hasSecondArgument) {
|
|
2947
2970
|
if (!hasSecondArgument) return isObject(requestOptions) ? `{${stringify(requestOptions)?.slice(1, -1)}}` : "";
|
|
@@ -3364,7 +3387,7 @@ function fixSchemaImports(schemas, targetSchemaNames, fromPath, toPath, namingCo
|
|
|
3364
3387
|
const fileName = conventionName(imp.name, namingConvention);
|
|
3365
3388
|
return {
|
|
3366
3389
|
...imp,
|
|
3367
|
-
importPath:
|
|
3390
|
+
importPath: joinSafe(relativePath, fileName)
|
|
3368
3391
|
};
|
|
3369
3392
|
}
|
|
3370
3393
|
return imp;
|
|
@@ -3510,12 +3533,13 @@ function generateImportsForBuilder(output, imports, relativeSchemasPath) {
|
|
|
3510
3533
|
if (!output.indexFiles) return uniqueBy(imports, (x) => x.name).map((i) => {
|
|
3511
3534
|
const name = conventionName(i.schemaName || i.name, output.namingConvention);
|
|
3512
3535
|
const suffix = isZodSchemaOutput ? ".zod" : "";
|
|
3536
|
+
const importExtension = output.fileExtension?.replace(/\.ts$/, "") || "";
|
|
3513
3537
|
return {
|
|
3514
3538
|
exports: isZodSchemaOutput ? [{
|
|
3515
3539
|
...i,
|
|
3516
3540
|
values: true
|
|
3517
3541
|
}] : [i],
|
|
3518
|
-
dependency: joinSafe(relativeSchemasPath, `${name}${suffix}`)
|
|
3542
|
+
dependency: joinSafe(relativeSchemasPath, `${name}${suffix}${importExtension}`)
|
|
3519
3543
|
};
|
|
3520
3544
|
});
|
|
3521
3545
|
else if (isZodSchemaOutput) return [{
|