orval 8.19.0 → 8.21.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.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { c as description, i as startWatcher, l as name, n as loadConfigFile, r as generateSpec, s as normalizeOptions, t as findConfigFile, u as version } from "../config-D-TQRn-G.mjs";
2
+ import { c as description, i as startWatcher, l as name, n as loadConfigFile, r as generateSpec, s as normalizeOptions, t as findConfigFile, u as version } from "../config-DGhExJ4J.mjs";
3
3
  import path from "node:path";
4
4
  import { Option, program } from "@commander-js/extra-typings";
5
5
  import { ErrorWithTag, OutputClient, OutputMode, SupportedFormatter, getWarningCount, isString, log, logError, resetWarnings, setVerbose, startMessage } from "@orval/core";
@@ -1,3 +1,4 @@
1
+ import { createRequire } from "node:module";
1
2
  import path from "node:path";
2
3
  import { DefaultTag, FormDataArrayHandling, GetterPropType, NamingConvention, OutputClient, OutputHttpClient, OutputMockType, OutputMode, PropertySortOrder, RefComponentSuffix, SupportedFormatter, asyncReduce, buildDynamicScope, buildSchemaTagMap, collectReferencedComponents, conventionName, createSuccessMessage, dynamicImport, fixCrossDirectoryImports, fixRegularSchemaImports, generateComponentDefinition, generateDependencyImports, generateMutator, generateParameterDefinition, generateSchemasDefinition, generateVerbsOptions, getBaseUrlRuntimeImports, getFileInfo, getFullRoute, getImportExtension, getMockFileExtensionByTypeName, getRefInfo, getRoute, isBoolean, isComponentRef, isFunction, isNullish, isObject, isReference, isString, isUrl, jsDoc, kebab, log, logError, logVerbose, logWarning, pascal, removeFilesAndEmptyFolders, resolveInstalledVersions, resolveRef, resolveValue, splitSchemasByType, upath, writeGeneratedFile, writeSchemas, writeSchemasTagsSplit, writeSingleMode, writeSplitMode, writeSplitTagsMode, writeTagsMode } from "@orval/core";
3
4
  import { bundle } from "@scalar/json-magic/bundle";
@@ -15,20 +16,20 @@ import mcp from "@orval/mcp";
15
16
  import query from "@orval/query";
16
17
  import solidStart from "@orval/solid-start";
17
18
  import swr from "@orval/swr";
18
- import zod, { dereference, generateFormDataZodSchema, generateZodValidationSchemaDefinition, parseZodValidationSchemaDefinition, resolveIsZodV4 } from "@orval/zod";
19
+ import zod, { assertZodTarget, dereference, generateFormDataZodSchema, generateZodValidationSchemaDefinition, getZodImportSource, getZodTypeName, parseZodValidationSchemaDefinition, resolveIsZodV4 } from "@orval/zod";
19
20
  import { ExecaError, execa } from "execa";
20
21
  import fs from "fs-extra";
21
22
  import fs$1, { access } from "node:fs/promises";
22
23
  import { styleText } from "node:util";
23
24
  import { parseArgsStringToArgv } from "string-argv";
25
+ import fs$2, { existsSync } from "node:fs";
24
26
  import { findUp, findUpMultiple } from "find-up";
25
27
  import yaml from "js-yaml";
26
28
  import { parseTsconfig } from "get-tsconfig";
27
- import fs$2 from "node:fs";
28
29
  import { createJiti } from "jiti";
29
30
  //#region package.json
30
31
  var name = "orval";
31
- var version = "8.19.0";
32
+ var version = "8.21.0";
32
33
  var description = "A swagger client generator for typescript";
33
34
  //#endregion
34
35
  //#region src/client.ts
@@ -97,7 +98,7 @@ const generateClientHeader = ({ outputClient = DEFAULT_CLIENT, isRequestOptions,
97
98
  sharedTypes: normalizedHeader.sharedTypes
98
99
  };
99
100
  };
100
- const generateClientFooter = ({ outputClient, operationNames, hasMutator, hasAwaitedType, titles, output }) => {
101
+ const generateClientFooter = ({ outputClient, operationNames, operations, hasMutator, hasAwaitedType, titles, output }) => {
101
102
  const { footer } = getGeneratorClient(outputClient, output);
102
103
  if (!footer) return {
103
104
  implementation: "",
@@ -110,6 +111,7 @@ const generateClientFooter = ({ outputClient, operationNames, hasMutator, hasAwa
110
111
  logWarning("⚠️ Passing an array of strings for operations names to the footer function is deprecated and will be removed in a future major release. Please pass them in an object instead: { operationNames: string[] }.");
111
112
  } else implementation = footer({
112
113
  operationNames,
114
+ operations,
113
115
  title: titles.implementation,
114
116
  hasMutator,
115
117
  hasAwaitedType
@@ -117,6 +119,7 @@ const generateClientFooter = ({ outputClient, operationNames, hasMutator, hasAwa
117
119
  } catch {
118
120
  implementation = footer({
119
121
  operationNames,
122
+ operations,
120
123
  title: titles.implementation,
121
124
  hasMutator,
122
125
  hasAwaitedType
@@ -201,7 +204,8 @@ const generateOperations = (outputClient = DEFAULT_CLIENT, verbsOptions, options
201
204
  paramsSerializer: verbOption.paramsSerializer,
202
205
  paramsFilter: verbOption.paramsFilter,
203
206
  operationName: verbOption.operationName,
204
- fetchReviver: verbOption.fetchReviver
207
+ fetchReviver: verbOption.fetchReviver,
208
+ ...client.returnType ? { types: { result: client.returnType } } : void 0
205
209
  };
206
210
  return acc;
207
211
  }, {});
@@ -251,10 +255,12 @@ async function getApiBuilder({ input, output, context }) {
251
255
  }, output);
252
256
  for (const verbOption of verbsOptions) acc.verbOptions[verbOption.operationId] = verbOption;
253
257
  acc.schemas.push(...schemas);
254
- acc.operations = {
255
- ...acc.operations,
256
- ...pathOperations
257
- };
258
+ for (const [key, value] of Object.entries(pathOperations)) {
259
+ let operationKey = key;
260
+ let counter = 1;
261
+ while (Object.hasOwn(acc.operations, operationKey)) operationKey = `${key}::${++counter}`;
262
+ acc.operations[operationKey] = value;
263
+ }
258
264
  return acc;
259
265
  }, {
260
266
  operations: {},
@@ -909,6 +915,29 @@ function validatePackageSpecifier(value, fieldName) {
909
915
  if (value.startsWith(".")) throw new Error(`\`${fieldName}\` must be a package specifier (e.g. '@acme/models'), not a relative path. Received: "${value}"`);
910
916
  if (path.isAbsolute(value) || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\")) throw new Error(`\`${fieldName}\` must be a package specifier (e.g. '@acme/models'), not an absolute path. Received: "${value}"`);
911
917
  }
918
+ function looksLikePackageSpecifier(value) {
919
+ return !!value && value.trim() === value && !value.startsWith(".") && !path.isAbsolute(value) && !/^[A-Za-z]:[\\/]/.test(value) && !value.startsWith("\\\\");
920
+ }
921
+ function resolvePackageSpecifier(workspace, value) {
922
+ try {
923
+ return createRequire(path.join(workspace, "package.json")).resolve(value);
924
+ } catch {
925
+ return;
926
+ }
927
+ }
928
+ function isPackageSpecifierCandidate(workspace, value) {
929
+ if (!looksLikePackageSpecifier(value)) return false;
930
+ if (existsSync(path.resolve(workspace, value))) return false;
931
+ if (value.startsWith("@")) return true;
932
+ const [packageName] = value.split("/");
933
+ if (!value.includes("/")) return true;
934
+ for (let dir = workspace;;) {
935
+ if (existsSync(path.join(dir, "node_modules", packageName))) return true;
936
+ const parent = path.dirname(dir);
937
+ if (parent === dir) return false;
938
+ dir = parent;
939
+ }
940
+ }
912
941
  function normalizeEffectOptions(effect) {
913
942
  return {
914
943
  strict: {
@@ -1096,11 +1125,13 @@ async function normalizeOptions(optionsExport, workspace = process.cwd(), global
1096
1125
  ...outputOptions.override?.zod?.preprocess?.response ? { response: normalizeMutator(outputWorkspace, outputOptions.override.zod.preprocess.response) } : {}
1097
1126
  },
1098
1127
  ...outputOptions.override?.zod?.params ? { params: normalizeMutator(outputWorkspace, outputOptions.override.zod.params) } : {},
1128
+ variant: outputOptions.override?.zod?.variant ?? "classic",
1099
1129
  version: outputOptions.override?.zod?.version ?? "auto",
1100
1130
  generateEachHttpStatus: outputOptions.override?.zod?.generateEachHttpStatus ?? false,
1101
1131
  useBrandedTypes: outputOptions.override?.zod?.useBrandedTypes ?? false,
1102
1132
  generateReusableSchemas: outputOptions.override?.zod?.generateReusableSchemas ?? false,
1103
1133
  generateMeta: outputOptions.override?.zod?.generateMeta ?? false,
1134
+ generateDiscriminatedUnion: outputOptions.override?.zod?.generateDiscriminatedUnion ?? false,
1104
1135
  dateTimeOptions: outputOptions.override?.zod?.dateTimeOptions ?? { offset: true },
1105
1136
  timeOptions: outputOptions.override?.zod?.timeOptions ?? {}
1106
1137
  },
@@ -1113,6 +1144,7 @@ async function normalizeOptions(optionsExport, workspace = process.cwd(), global
1113
1144
  provideIn: outputOptions.override?.angular?.provideIn ?? "root",
1114
1145
  client: outputOptions.override?.angular?.retrievalClient ?? outputOptions.override?.angular?.client ?? "httpClient",
1115
1146
  runtimeValidation: outputOptions.override?.angular?.runtimeValidation ?? false,
1147
+ queryObjectSerialization: outputOptions.override?.angular?.queryObjectSerialization ?? "spec",
1116
1148
  ...outputOptions.override?.angular?.httpResource ? { httpResource: outputOptions.override.angular.httpResource } : {}
1117
1149
  },
1118
1150
  fetch: {
@@ -1161,8 +1193,10 @@ function normalizeMutator(workspace, mutator) {
1161
1193
  if (isObject(mutator)) {
1162
1194
  const m = mutator;
1163
1195
  if (!m.path) throw new Error(styleText("red", `Mutator requires a path.`));
1196
+ const resolvedPath = looksLikePackageSpecifier(m.path) ? resolvePackageSpecifier(workspace, m.path) : void 0;
1164
1197
  return {
1165
- path: path.resolve(workspace, m.path),
1198
+ path: !!resolvedPath || isPackageSpecifierCandidate(workspace, m.path) ? m.path : path.resolve(workspace, m.path),
1199
+ ...resolvedPath ? { resolvedPath } : {},
1166
1200
  name: m.name,
1167
1201
  default: m.default ?? !m.name,
1168
1202
  alias: m.alias,
@@ -1170,10 +1204,14 @@ function normalizeMutator(workspace, mutator) {
1170
1204
  extension: m.extension
1171
1205
  };
1172
1206
  }
1173
- if (isString(mutator)) return {
1174
- path: path.resolve(workspace, mutator),
1175
- default: true
1176
- };
1207
+ if (isString(mutator)) {
1208
+ const resolvedPath = looksLikePackageSpecifier(mutator) ? resolvePackageSpecifier(workspace, mutator) : void 0;
1209
+ return {
1210
+ path: !!resolvedPath || isPackageSpecifierCandidate(workspace, mutator) ? mutator : path.resolve(workspace, mutator),
1211
+ ...resolvedPath ? { resolvedPath } : {},
1212
+ default: true
1213
+ };
1214
+ }
1177
1215
  }
1178
1216
  async function resolveFirstValidTarget(targets, workspace, parserOptions) {
1179
1217
  for (const target of targets) {
@@ -1238,11 +1276,13 @@ function normalizePath(path$1, workspace) {
1238
1276
  function normalizeOperationsAndTags(operationsOrTags, workspace, global, source) {
1239
1277
  const unsupportedZodKeys = [
1240
1278
  "version",
1279
+ "variant",
1241
1280
  "dateTimeOptions",
1242
1281
  "timeOptions",
1243
1282
  "generateEachHttpStatus",
1244
1283
  "generateReusableSchemas",
1245
- "generateMeta"
1284
+ "generateMeta",
1285
+ "generateDiscriminatedUnion"
1246
1286
  ];
1247
1287
  return Object.fromEntries(Object.entries(operationsOrTags).map(([key, { transformer, mutator, formData, formUrlEncoded, paramsSerializer, paramsFilter, query, angular, zod, effect, ...rest }]) => {
1248
1288
  const unsupportedOperationZodKeys = zod && unsupportedZodKeys.filter((unsupportedKey) => zod[unsupportedKey] !== void 0);
@@ -1254,6 +1294,7 @@ function normalizeOperationsAndTags(operationsOrTags, workspace, global, source)
1254
1294
  provideIn: angular.provideIn ?? "root",
1255
1295
  client: angular.retrievalClient ?? angular.client ?? "httpClient",
1256
1296
  runtimeValidation: angular.runtimeValidation ?? false,
1297
+ queryObjectSerialization: angular.queryObjectSerialization ?? "spec",
1257
1298
  ...angular.httpResource ? { httpResource: angular.httpResource } : {}
1258
1299
  } } : {},
1259
1300
  ...query ? { query: normalizeQueryOptions(query, workspace, global.query) } : {},
@@ -1494,13 +1535,14 @@ const generateReusableSchemaSet = (refs, context, options) => {
1494
1535
  operationId: "",
1495
1536
  location: "schema",
1496
1537
  schemaName: name
1497
- } : void 0);
1538
+ } : void 0, options.variant);
1498
1539
  entries.push({
1499
1540
  ref,
1500
1541
  name,
1501
1542
  zod: parsed.zod,
1502
1543
  consts: parsed.consts,
1503
- usedRefs: parsed.usedRefs
1544
+ usedRefs: parsed.usedRefs,
1545
+ variant: options.variant
1504
1546
  });
1505
1547
  for (const usedName of parsed.usedRefs) {
1506
1548
  const usedRef = nameToRef.get(usedName);
@@ -1596,7 +1638,7 @@ const rewriteReusableSchemas = (entries) => {
1596
1638
  else if (lazyEdges.has(edgeKey(scc[0], scc[0]))) recursiveNames.add(scc[0]);
1597
1639
  const rewritten = new Map(entries.map((entry) => {
1598
1640
  const newZod = entry.zod.replaceAll(SENTINEL_PATTERN, (_match, refName) => {
1599
- return lazyEdges.has(edgeKey(entry.name, refName)) ? `zod.lazy(() => ${refName})` : refName;
1641
+ return lazyEdges.has(edgeKey(entry.name, refName)) ? `${entry.variant === "mini" ? "/*#__PURE__*/ " : ""}zod.lazy(() => ${refName})` : refName;
1600
1642
  });
1601
1643
  return [entry.name, {
1602
1644
  ...entry,
@@ -1613,6 +1655,7 @@ const rewriteReusableSchemas = (entries) => {
1613
1655
  };
1614
1656
  //#endregion
1615
1657
  //#region src/write-zod-specs.ts
1658
+ const getZodSchemaImportStatement = (variant) => variant === "mini" ? `import * as zod from '${getZodImportSource(variant)}';` : `import { z as zod } from '${getZodImportSource(variant)}';`;
1616
1659
  /**
1617
1660
  * Render the `import { ... } from '...'` line for a resolved
1618
1661
  * `GeneratorMutator`. Mirrors the format produced by
@@ -1647,9 +1690,9 @@ function adjustMutatorPathForDir(mutatorPath, tagDir) {
1647
1690
  function bodyReferencesMutator(body, mutator) {
1648
1691
  return new RegExp(String.raw`\b${mutator.name}\b`).test(body);
1649
1692
  }
1650
- function generateZodSchemaFileContent(header, schemas, includeZodImport = true) {
1693
+ function generateZodSchemaFileContent(header, schemas, zodVariant, includeZodImport = true) {
1651
1694
  const refImports = [...new Set(schemas.flatMap((s) => s.importStatements ?? []))].toSorted();
1652
- const importBlock = [...includeZodImport ? [`import { z as zod } from 'zod';`] : [], ...refImports].join("\n");
1695
+ const importBlock = [...includeZodImport ? [getZodSchemaImportStatement(zodVariant)] : [], ...refImports].join("\n");
1653
1696
  const schemaContent = schemas.map(({ schemaName, consts, zodExpression }) => {
1654
1697
  return `${consts ? `${consts}\n` : ""}export const ${schemaName} = ${zodExpression}
1655
1698
 
@@ -1658,7 +1701,7 @@ export type ${schemaName}Output = zod.output<typeof ${schemaName}>;`;
1658
1701
  }).join("\n\n");
1659
1702
  return `${header}${importBlock ? `${importBlock}\n\n` : ""}${schemaContent}\n`;
1660
1703
  }
1661
- function renderReusableSchemaEntry(entry, context) {
1704
+ function renderReusableSchemaEntry(entry, context, zodVariant) {
1662
1705
  const consts = entry.consts ? `${entry.consts}\n\n` : "";
1663
1706
  if (entry.isRecursive) {
1664
1707
  const rawName = isComponentRef(entry.ref) ? getRefInfo(entry.ref, context).originalName : void 0;
@@ -1669,10 +1712,18 @@ function renderReusableSchemaEntry(entry, context) {
1669
1712
  context
1670
1713
  }) : void 0;
1671
1714
  const typeBody = resolved ? resolved.value : "unknown";
1715
+ const seenSubModels = /* @__PURE__ */ new Set();
1716
+ const subModels = (resolved?.schemas ?? []).filter((s) => {
1717
+ if (seenSubModels.has(s.name)) return false;
1718
+ seenSubModels.add(s.name);
1719
+ return true;
1720
+ });
1721
+ const subModelBlock = subModels.length ? `${subModels.map((s) => s.model.trimEnd()).join("\n")}\n\n` : "";
1722
+ const localNames = new Set(subModels.map((s) => s.name));
1672
1723
  const seen = /* @__PURE__ */ new Set();
1673
1724
  const extraImports = [];
1674
1725
  for (const imp of resolved?.imports ?? []) {
1675
- if (!imp.name || imp.name === entry.name) continue;
1726
+ if (!imp.name || imp.name === entry.name || localNames.has(imp.name)) continue;
1676
1727
  const bindingKey = imp.alias ?? imp.name;
1677
1728
  if (seen.has(bindingKey)) continue;
1678
1729
  seen.add(bindingKey);
@@ -1682,7 +1733,7 @@ function renderReusableSchemaEntry(entry, context) {
1682
1733
  });
1683
1734
  }
1684
1735
  return {
1685
- content: `${consts}export type ${entry.name} = ${typeBody};\n\nexport const ${entry.name}: zod.ZodType<${entry.name}> = ${entry.zod};\n\nexport type ${entry.name}Output = zod.output<typeof ${entry.name}>;`,
1736
+ content: `${consts}${subModelBlock}export type ${entry.name} = ${typeBody};\n\nexport const ${entry.name}: zod.${getZodTypeName(zodVariant)}<${entry.name}> = ${entry.zod};\n\nexport type ${entry.name}Output = zod.output<typeof ${entry.name}>;`,
1686
1737
  extraImports
1687
1738
  };
1688
1739
  }
@@ -1791,6 +1842,10 @@ function generateZodSchemasInline(builder, output, includeZodImport = true, para
1791
1842
  const schemasWithOpenApiDef = builder.schemas.filter((s) => s.schema);
1792
1843
  if (schemasWithOpenApiDef.length === 0) return "";
1793
1844
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1845
+ assertZodTarget({
1846
+ variant: output.override.zod.variant,
1847
+ isZodV4
1848
+ });
1794
1849
  const strict = output.override.zod.strict.body;
1795
1850
  const coerce = output.override.zod.coerce.body;
1796
1851
  const schemas = [];
@@ -1805,7 +1860,7 @@ function generateZodSchemasInline(builder, output, includeZodImport = true, para
1805
1860
  const parsedZodDefinition = parseZodValidationSchemaDefinition(generateZodValidationSchemaDefinition(dereference(schemaObject, context), context, name, strict, isZodV4, {
1806
1861
  required: true,
1807
1862
  emitMeta: output.override.zod.generateMeta
1808
- }), context, coerce, strict, isZodV4);
1863
+ }), context, coerce, strict, isZodV4, void 0, void 0, output.override.zod.variant);
1809
1864
  schemas.push({
1810
1865
  schemaName: name,
1811
1866
  consts: parsedZodDefinition.consts,
@@ -1813,10 +1868,14 @@ function generateZodSchemasInline(builder, output, includeZodImport = true, para
1813
1868
  });
1814
1869
  }
1815
1870
  if (schemas.length === 0) return "";
1816
- return generateZodSchemaFileContent("", schemas, includeZodImport);
1871
+ return generateZodSchemaFileContent("", schemas, output.override.zod.variant, includeZodImport);
1817
1872
  }
1818
1873
  function generateZodSchemasInlineReusable(builder, output, includeZodImport = true, paramsMutator, includeParamsImport = false) {
1819
1874
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1875
+ assertZodTarget({
1876
+ variant: output.override.zod.variant,
1877
+ isZodV4
1878
+ });
1820
1879
  const strict = output.override.zod.strict.body;
1821
1880
  const coerce = output.override.zod.coerce.body;
1822
1881
  const context = {
@@ -1833,10 +1892,11 @@ function generateZodSchemasInlineReusable(builder, output, includeZodImport = tr
1833
1892
  strict,
1834
1893
  isZodV4,
1835
1894
  coerce,
1895
+ variant: output.override.zod.variant,
1836
1896
  generateMeta: output.override.zod.generateMeta,
1837
1897
  paramsMutator
1838
- })).map((entry) => renderReusableSchemaEntry(entry, context).content).join("\n\n");
1839
- const zodImport = includeZodImport ? `import { z as zod } from 'zod';\n` : "";
1898
+ })).map((entry) => renderReusableSchemaEntry(entry, context, output.override.zod.variant).content).join("\n\n");
1899
+ const zodImport = includeZodImport ? `${getZodSchemaImportStatement(output.override.zod.variant)}\n` : "";
1840
1900
  const paramsImport = paramsMutator && includeParamsImport && bodyReferencesMutator(body, paramsMutator) ? `${buildMutatorImportStatement(paramsMutator)}\n` : "";
1841
1901
  return `${zodImport || paramsImport ? `${zodImport}${paramsImport}\n` : ""}${body}\n`;
1842
1902
  }
@@ -1846,6 +1906,10 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1846
1906
  const schemasWithOpenApiDef = builder.schemas.filter((s) => s.schema);
1847
1907
  const schemasToWrite = [];
1848
1908
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1909
+ assertZodTarget({
1910
+ variant: output.override.zod.variant,
1911
+ isZodV4
1912
+ });
1849
1913
  const strict = output.override.zod.strict.body;
1850
1914
  const coerce = output.override.zod.coerce.body;
1851
1915
  for (const generatorSchema of schemasWithOpenApiDef) {
@@ -1863,7 +1927,7 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1863
1927
  const parsedZodDefinition = parseZodValidationSchemaDefinition(generateZodValidationSchemaDefinition(dereference(schemaObject, context), context, name, strict, isZodV4, {
1864
1928
  required: true,
1865
1929
  emitMeta: output.override.zod.generateMeta
1866
- }), context, coerce, strict, isZodV4);
1930
+ }), context, coerce, strict, isZodV4, void 0, void 0, output.override.zod.variant);
1867
1931
  schemasToWrite.push({
1868
1932
  schemaName: name,
1869
1933
  filePath,
@@ -1873,7 +1937,7 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1873
1937
  }
1874
1938
  const groupedSchemasToWrite = groupSchemasByFilePath(schemasToWrite);
1875
1939
  for (const schemaGroup of groupedSchemasToWrite) {
1876
- const fileContent = generateZodSchemaFileContent(header, schemaGroup);
1940
+ const fileContent = generateZodSchemaFileContent(header, schemaGroup, output.override.zod.variant);
1877
1941
  await fs.outputFile(schemaGroup[0].filePath, fileContent);
1878
1942
  }
1879
1943
  const writtenSchemaNames = groupedSchemasToWrite.map((schemaGroup) => schemaGroup[0].schemaName);
@@ -1892,6 +1956,10 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1892
1956
  async function writeZodSchemasReusable(builder, schemasPath, fileExtension, header, output, paramsMutator, schemaTagMap) {
1893
1957
  const isSplit = !!schemaTagMap;
1894
1958
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1959
+ assertZodTarget({
1960
+ variant: output.override.zod.variant,
1961
+ isZodV4
1962
+ });
1895
1963
  const strict = output.override.zod.strict.body;
1896
1964
  const coerce = output.override.zod.coerce.body;
1897
1965
  const context = {
@@ -1907,6 +1975,7 @@ async function writeZodSchemasReusable(builder, schemasPath, fileExtension, head
1907
1975
  strict,
1908
1976
  isZodV4,
1909
1977
  coerce,
1978
+ variant: output.override.zod.variant,
1910
1979
  generateMeta: output.override.zod.generateMeta,
1911
1980
  paramsMutator
1912
1981
  }));
@@ -1916,7 +1985,7 @@ async function writeZodSchemasReusable(builder, schemasPath, fileExtension, head
1916
1985
  const tagDir = getSchemaDir(schemaTagMap, entry.name);
1917
1986
  const filePath = isSplit ? path.join(schemasPath, tagDir, `${fileName}${fileExtension}`) : path.join(schemasPath, `${fileName}${fileExtension}`);
1918
1987
  const importExt = getImportExtension(fileExtension, output.tsconfig);
1919
- const rendered = renderReusableSchemaEntry(entry, context);
1988
+ const rendered = renderReusableSchemaEntry(entry, context, output.override.zod.variant);
1920
1989
  const refImports = buildSiblingImports({
1921
1990
  usedRefs: entry.usedRefs,
1922
1991
  extraImports: rendered.extraImports,
@@ -1935,7 +2004,7 @@ async function writeZodSchemasReusable(builder, schemasPath, fileExtension, head
1935
2004
  path: isSplit ? adjustMutatorPathForDir(paramsMutator.path, tagDir) : paramsMutator.path
1936
2005
  }) : void 0;
1937
2006
  const imports = [...mutatorImportStr ? [mutatorImportStr] : [], ...refImports ? [refImports] : []].join("\n");
1938
- const fileContent = `${header}import { z as zod } from 'zod';\n` + (imports ? `${imports}\n\n` : "\n") + `${rendered.content}\n`;
2007
+ const fileContent = `${header}${getZodSchemaImportStatement(output.override.zod.variant)}\n` + (imports ? `${imports}\n\n` : "\n") + `${rendered.content}\n`;
1939
2008
  await fs.outputFile(filePath, fileContent);
1940
2009
  }
1941
2010
  if (output.indexFiles && !isSplit && rewritten.length > 0) await writeZodSchemaIndex(schemasPath, fileExtension, header, rewritten.map((e) => e.name), output.namingConvention, true, output.tsconfig);
@@ -1956,6 +2025,10 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
1956
2025
  const verbOptionsArray = Object.values(verbOptions);
1957
2026
  if (verbOptionsArray.length === 0) return /* @__PURE__ */ new Map();
1958
2027
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
2028
+ assertZodTarget({
2029
+ variant: output.override.zod.variant,
2030
+ isZodV4
2031
+ });
1959
2032
  const strict = output.override.zod.strict.body;
1960
2033
  const coerce = output.override.zod.coerce.body;
1961
2034
  const useReusableSchemas = output.override.zod.generateReusableSchemas === true;
@@ -1974,7 +2047,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
1974
2047
  const [bodyContentType, bodyMedia] = jsonBodyMedia ? ["application/json", jsonBodyMedia] : formDataBodyMedia ? ["multipart/form-data", formDataBodyMedia] : formUrlEncodedBodyMedia ? ["application/x-www-form-urlencoded", formUrlEncodedBodyMedia] : [void 0, void 0];
1975
2048
  const bodySchema = bodyMedia?.schema;
1976
2049
  const bodySchemas = shouldGenerate.body && bodySchema ? [{
1977
- name: `${pascal(verbOption.operationName)}Body`,
2050
+ name: `${pascal(verbOption.typeName)}Body`,
1978
2051
  schema: useReusableSchemas ? bodySchema : dereference(bodySchema, zodContext),
1979
2052
  bodyContentType,
1980
2053
  encoding: bodyMedia?.encoding
@@ -1982,7 +2055,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
1982
2055
  const parameters = operation.parameters;
1983
2056
  const pathParams = parameters?.filter((p) => "in" in p && p.in === "path");
1984
2057
  const pathParamsSchemas = useNamedParameters && shouldGenerate.param && pathParams && pathParams.length > 0 ? [{
1985
- name: `${pascal(verbOption.operationName)}PathParameters`,
2058
+ name: `${pascal(verbOption.typeName)}PathParameters`,
1986
2059
  schema: {
1987
2060
  type: "object",
1988
2061
  properties: Object.fromEntries(pathParams.filter((p) => "schema" in p && p.schema).map((p) => [p.name, useReusableSchemas ? p.schema : dereference(p.schema, zodContext)])),
@@ -1991,7 +2064,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
1991
2064
  }] : [];
1992
2065
  const queryParams = parameters?.filter((p) => "in" in p && p.in === "query");
1993
2066
  const queryParamsSchemas = shouldGenerate.query && queryParams && queryParams.length > 0 ? [{
1994
- name: `${pascal(verbOption.operationName)}Params`,
2067
+ name: `${pascal(verbOption.typeName)}Params`,
1995
2068
  schema: {
1996
2069
  type: "object",
1997
2070
  properties: Object.fromEntries(queryParams.filter((p) => "schema" in p && p.schema).map((p) => [p.name, useReusableSchemas ? p.schema : dereference(p.schema, zodContext)])),
@@ -2000,7 +2073,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
2000
2073
  }] : [];
2001
2074
  const headerParams = parameters?.filter((p) => "in" in p && p.in === "header");
2002
2075
  const headerParamsSchemas = shouldGenerate.header && headerParams && headerParams.length > 0 ? [{
2003
- name: `${pascal(verbOption.operationName)}Headers`,
2076
+ name: `${pascal(verbOption.typeName)}Headers`,
2004
2077
  schema: {
2005
2078
  type: "object",
2006
2079
  properties: Object.fromEntries(headerParams.filter((p) => "schema" in p && p.schema).map((p) => [p.name, useReusableSchemas ? p.schema : dereference(p.schema, zodContext)])),
@@ -2032,7 +2105,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
2032
2105
  const parsedZodDefinition = parseZodValidationSchemaDefinition("bodyContentType" in entry && entry.bodyContentType === "multipart/form-data" ? generateFormDataZodSchema(schema, zodContext, name, strict, isZodV4, "encoding" in entry ? entry.encoding : void 0, useReusableSchemas) : generateZodValidationSchemaDefinition(schema, zodContext, name, strict, isZodV4, {
2033
2106
  required: true,
2034
2107
  useReusableSchemas
2035
- }), zodContext, coerce, strict, isZodV4);
2108
+ }), zodContext, coerce, strict, isZodV4, void 0, void 0, output.override.zod.variant);
2036
2109
  let zodExpression = parsedZodDefinition.zod;
2037
2110
  let importStatements;
2038
2111
  if (useReusableSchemas && parsedZodDefinition.usedRefs.size > 0) {
@@ -2053,7 +2126,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
2053
2126
  }
2054
2127
  const groupedSchemasToWrite = groupSchemasByFilePath(schemasToWrite);
2055
2128
  for (const schemaGroup of groupedSchemasToWrite) {
2056
- const fileContent = generateZodSchemaFileContent(header, schemaGroup);
2129
+ const fileContent = generateZodSchemaFileContent(header, schemaGroup, output.override.zod.variant);
2057
2130
  await fs.outputFile(schemaGroup[0].filePath, fileContent);
2058
2131
  }
2059
2132
  const writtenSchemaNames = groupedSchemasToWrite.map((schemaGroup) => schemaGroup[0].schemaName);
@@ -2100,6 +2173,23 @@ async function runFormatter(formatter, paths, projectTitle) {
2100
2173
  break;
2101
2174
  }
2102
2175
  }
2176
+ function getComparableFilePath(filePath) {
2177
+ const resolvedPath = path.resolve(filePath);
2178
+ let comparablePath = resolvedPath;
2179
+ try {
2180
+ comparablePath = fs.realpathSync(resolvedPath);
2181
+ } catch (error) {
2182
+ if (error.code !== "ENOENT") throw error;
2183
+ }
2184
+ return process.platform === "win32" || process.platform === "darwin" ? comparablePath.toLowerCase() : comparablePath;
2185
+ }
2186
+ function excludeFilePath(filePaths, filePathToExclude) {
2187
+ const comparablePathToExclude = getComparableFilePath(filePathToExclude);
2188
+ return filePaths.map((filePath) => ({
2189
+ filePath,
2190
+ comparablePath: getComparableFilePath(filePath)
2191
+ })).filter(({ comparablePath }) => comparablePath !== comparablePathToExclude).map(({ filePath }) => filePath);
2192
+ }
2103
2193
  function getHeader(option, info) {
2104
2194
  if (!option) return "";
2105
2195
  const header = option(info);
@@ -2223,6 +2313,13 @@ function shouldGenerateZodSchemasInline(output, hasOperations) {
2223
2313
  function shouldGenerateSchemas(output, hasOperations) {
2224
2314
  return !output.schemas && !isSchemaValidatorClient(output.client) || shouldGenerateZodSchemasInline(output, hasOperations);
2225
2315
  }
2316
+ function getImplementationPathsForIndex(output, implementationPaths, indexFile) {
2317
+ const shouldExcludeSelf = output.indexFiles;
2318
+ const paths = shouldExcludeSelf ? excludeFilePath(implementationPaths, indexFile) : implementationPaths;
2319
+ if (!(shouldExcludeSelf && output.mode === OutputMode.SPLIT && getComparableFilePath(output.target) === getComparableFilePath(indexFile))) return paths;
2320
+ const targetInfo = getFileInfo(output.target, { extension: output.fileExtension });
2321
+ return excludeFilePath(paths, path.join(targetInfo.dirname, `${targetInfo.filename}.schemas${output.fileExtension}`));
2322
+ }
2226
2323
  async function writeSpecs(builder, workspace, options, projectName) {
2227
2324
  const { info, schemas, target } = builder;
2228
2325
  const { output } = options;
@@ -2357,7 +2454,8 @@ async function writeSpecs(builder, workspace, options, projectName) {
2357
2454
  const indexFile = path.join(workspacePath, "index.ts");
2358
2455
  const mockExtensions = output.mock.generators.map((g) => getMockFileExtensionByTypeName(g));
2359
2456
  const importExtension = getImportExtension(output.fileExtension, output.tsconfig);
2360
- const imports = implementationPaths.filter((p) => mockExtensions.length === 0 || !mockExtensions.some((ext) => p.endsWith(`.${ext}.ts`))).map((p) => {
2457
+ const implementationPathsForIndex = getImplementationPathsForIndex(output, implementationPaths, indexFile);
2458
+ const imports = implementationPathsForIndex.filter((p) => mockExtensions.length === 0 || !mockExtensions.some((ext) => p.endsWith(`.${ext}.ts`))).map((p) => {
2361
2459
  const relative = upath.getRelativeImportPath(indexFile, p, true);
2362
2460
  return (relative.endsWith(output.fileExtension) ? relative.slice(0, -output.fileExtension.length) : relative.replace(/\.[^/.]+$/, "")) + importExtension;
2363
2461
  });
@@ -2369,10 +2467,10 @@ async function writeSpecs(builder, workspace, options, projectName) {
2369
2467
  if (output.indexFiles) {
2370
2468
  if (await fs.pathExists(indexFile)) {
2371
2469
  const data = await fs.readFile(indexFile, "utf8");
2372
- const importsNotDeclared = imports.filter((imp) => !data.includes(imp));
2470
+ const importsNotDeclared = imports.filter((imp) => !data.includes(`export * from '${imp}'`));
2373
2471
  await fs.appendFile(indexFile, unique(importsNotDeclared).map((imp) => `export * from '${imp}';\n`).join(""));
2374
2472
  } else await fs.outputFile(indexFile, unique(imports).map((imp) => `export * from '${imp}';`).join("\n") + "\n");
2375
- implementationPaths = [indexFile, ...implementationPaths];
2473
+ implementationPaths = [indexFile, ...implementationPathsForIndex];
2376
2474
  }
2377
2475
  }
2378
2476
  if (builder.extraFiles.length > 0) {
@@ -2512,4 +2610,4 @@ async function loadConfigFile(configFilePath) {
2512
2610
  //#endregion
2513
2611
  export { defineConfig as a, description as c, startWatcher as i, name as l, loadConfigFile as n, defineTransformer as o, generateSpec as r, normalizeOptions as s, findConfigFile as t, version as u };
2514
2612
 
2515
- //# sourceMappingURL=config-D-TQRn-G.mjs.map
2613
+ //# sourceMappingURL=config-DGhExJ4J.mjs.map