orval 8.19.0 → 8.20.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-C8B9Lol2.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.20.0";
32
33
  var description = "A swagger client generator for typescript";
33
34
  //#endregion
34
35
  //#region src/client.ts
@@ -909,6 +910,29 @@ function validatePackageSpecifier(value, fieldName) {
909
910
  if (value.startsWith(".")) throw new Error(`\`${fieldName}\` must be a package specifier (e.g. '@acme/models'), not a relative path. Received: "${value}"`);
910
911
  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
912
  }
913
+ function looksLikePackageSpecifier(value) {
914
+ return !!value && value.trim() === value && !value.startsWith(".") && !path.isAbsolute(value) && !/^[A-Za-z]:[\\/]/.test(value) && !value.startsWith("\\\\");
915
+ }
916
+ function resolvePackageSpecifier(workspace, value) {
917
+ try {
918
+ return createRequire(path.join(workspace, "package.json")).resolve(value);
919
+ } catch {
920
+ return;
921
+ }
922
+ }
923
+ function isPackageSpecifierCandidate(workspace, value) {
924
+ if (!looksLikePackageSpecifier(value)) return false;
925
+ if (existsSync(path.resolve(workspace, value))) return false;
926
+ if (value.startsWith("@")) return true;
927
+ const [packageName] = value.split("/");
928
+ if (!value.includes("/")) return true;
929
+ for (let dir = workspace;;) {
930
+ if (existsSync(path.join(dir, "node_modules", packageName))) return true;
931
+ const parent = path.dirname(dir);
932
+ if (parent === dir) return false;
933
+ dir = parent;
934
+ }
935
+ }
912
936
  function normalizeEffectOptions(effect) {
913
937
  return {
914
938
  strict: {
@@ -1096,6 +1120,7 @@ async function normalizeOptions(optionsExport, workspace = process.cwd(), global
1096
1120
  ...outputOptions.override?.zod?.preprocess?.response ? { response: normalizeMutator(outputWorkspace, outputOptions.override.zod.preprocess.response) } : {}
1097
1121
  },
1098
1122
  ...outputOptions.override?.zod?.params ? { params: normalizeMutator(outputWorkspace, outputOptions.override.zod.params) } : {},
1123
+ variant: outputOptions.override?.zod?.variant ?? "classic",
1099
1124
  version: outputOptions.override?.zod?.version ?? "auto",
1100
1125
  generateEachHttpStatus: outputOptions.override?.zod?.generateEachHttpStatus ?? false,
1101
1126
  useBrandedTypes: outputOptions.override?.zod?.useBrandedTypes ?? false,
@@ -1161,8 +1186,10 @@ function normalizeMutator(workspace, mutator) {
1161
1186
  if (isObject(mutator)) {
1162
1187
  const m = mutator;
1163
1188
  if (!m.path) throw new Error(styleText("red", `Mutator requires a path.`));
1189
+ const resolvedPath = looksLikePackageSpecifier(m.path) ? resolvePackageSpecifier(workspace, m.path) : void 0;
1164
1190
  return {
1165
- path: path.resolve(workspace, m.path),
1191
+ path: !!resolvedPath || isPackageSpecifierCandidate(workspace, m.path) ? m.path : path.resolve(workspace, m.path),
1192
+ ...resolvedPath ? { resolvedPath } : {},
1166
1193
  name: m.name,
1167
1194
  default: m.default ?? !m.name,
1168
1195
  alias: m.alias,
@@ -1170,10 +1197,14 @@ function normalizeMutator(workspace, mutator) {
1170
1197
  extension: m.extension
1171
1198
  };
1172
1199
  }
1173
- if (isString(mutator)) return {
1174
- path: path.resolve(workspace, mutator),
1175
- default: true
1176
- };
1200
+ if (isString(mutator)) {
1201
+ const resolvedPath = looksLikePackageSpecifier(mutator) ? resolvePackageSpecifier(workspace, mutator) : void 0;
1202
+ return {
1203
+ path: !!resolvedPath || isPackageSpecifierCandidate(workspace, mutator) ? mutator : path.resolve(workspace, mutator),
1204
+ ...resolvedPath ? { resolvedPath } : {},
1205
+ default: true
1206
+ };
1207
+ }
1177
1208
  }
1178
1209
  async function resolveFirstValidTarget(targets, workspace, parserOptions) {
1179
1210
  for (const target of targets) {
@@ -1238,6 +1269,7 @@ function normalizePath(path$1, workspace) {
1238
1269
  function normalizeOperationsAndTags(operationsOrTags, workspace, global, source) {
1239
1270
  const unsupportedZodKeys = [
1240
1271
  "version",
1272
+ "variant",
1241
1273
  "dateTimeOptions",
1242
1274
  "timeOptions",
1243
1275
  "generateEachHttpStatus",
@@ -1494,13 +1526,14 @@ const generateReusableSchemaSet = (refs, context, options) => {
1494
1526
  operationId: "",
1495
1527
  location: "schema",
1496
1528
  schemaName: name
1497
- } : void 0);
1529
+ } : void 0, options.variant);
1498
1530
  entries.push({
1499
1531
  ref,
1500
1532
  name,
1501
1533
  zod: parsed.zod,
1502
1534
  consts: parsed.consts,
1503
- usedRefs: parsed.usedRefs
1535
+ usedRefs: parsed.usedRefs,
1536
+ variant: options.variant
1504
1537
  });
1505
1538
  for (const usedName of parsed.usedRefs) {
1506
1539
  const usedRef = nameToRef.get(usedName);
@@ -1596,7 +1629,7 @@ const rewriteReusableSchemas = (entries) => {
1596
1629
  else if (lazyEdges.has(edgeKey(scc[0], scc[0]))) recursiveNames.add(scc[0]);
1597
1630
  const rewritten = new Map(entries.map((entry) => {
1598
1631
  const newZod = entry.zod.replaceAll(SENTINEL_PATTERN, (_match, refName) => {
1599
- return lazyEdges.has(edgeKey(entry.name, refName)) ? `zod.lazy(() => ${refName})` : refName;
1632
+ return lazyEdges.has(edgeKey(entry.name, refName)) ? `${entry.variant === "mini" ? "/*#__PURE__*/ " : ""}zod.lazy(() => ${refName})` : refName;
1600
1633
  });
1601
1634
  return [entry.name, {
1602
1635
  ...entry,
@@ -1613,6 +1646,7 @@ const rewriteReusableSchemas = (entries) => {
1613
1646
  };
1614
1647
  //#endregion
1615
1648
  //#region src/write-zod-specs.ts
1649
+ const getZodSchemaImportStatement = (variant) => variant === "mini" ? `import * as zod from '${getZodImportSource(variant)}';` : `import { z as zod } from '${getZodImportSource(variant)}';`;
1616
1650
  /**
1617
1651
  * Render the `import { ... } from '...'` line for a resolved
1618
1652
  * `GeneratorMutator`. Mirrors the format produced by
@@ -1647,9 +1681,9 @@ function adjustMutatorPathForDir(mutatorPath, tagDir) {
1647
1681
  function bodyReferencesMutator(body, mutator) {
1648
1682
  return new RegExp(String.raw`\b${mutator.name}\b`).test(body);
1649
1683
  }
1650
- function generateZodSchemaFileContent(header, schemas, includeZodImport = true) {
1684
+ function generateZodSchemaFileContent(header, schemas, zodVariant, includeZodImport = true) {
1651
1685
  const refImports = [...new Set(schemas.flatMap((s) => s.importStatements ?? []))].toSorted();
1652
- const importBlock = [...includeZodImport ? [`import { z as zod } from 'zod';`] : [], ...refImports].join("\n");
1686
+ const importBlock = [...includeZodImport ? [getZodSchemaImportStatement(zodVariant)] : [], ...refImports].join("\n");
1653
1687
  const schemaContent = schemas.map(({ schemaName, consts, zodExpression }) => {
1654
1688
  return `${consts ? `${consts}\n` : ""}export const ${schemaName} = ${zodExpression}
1655
1689
 
@@ -1658,7 +1692,7 @@ export type ${schemaName}Output = zod.output<typeof ${schemaName}>;`;
1658
1692
  }).join("\n\n");
1659
1693
  return `${header}${importBlock ? `${importBlock}\n\n` : ""}${schemaContent}\n`;
1660
1694
  }
1661
- function renderReusableSchemaEntry(entry, context) {
1695
+ function renderReusableSchemaEntry(entry, context, zodVariant) {
1662
1696
  const consts = entry.consts ? `${entry.consts}\n\n` : "";
1663
1697
  if (entry.isRecursive) {
1664
1698
  const rawName = isComponentRef(entry.ref) ? getRefInfo(entry.ref, context).originalName : void 0;
@@ -1669,10 +1703,18 @@ function renderReusableSchemaEntry(entry, context) {
1669
1703
  context
1670
1704
  }) : void 0;
1671
1705
  const typeBody = resolved ? resolved.value : "unknown";
1706
+ const seenSubModels = /* @__PURE__ */ new Set();
1707
+ const subModels = (resolved?.schemas ?? []).filter((s) => {
1708
+ if (seenSubModels.has(s.name)) return false;
1709
+ seenSubModels.add(s.name);
1710
+ return true;
1711
+ });
1712
+ const subModelBlock = subModels.length ? `${subModels.map((s) => s.model.trimEnd()).join("\n")}\n\n` : "";
1713
+ const localNames = new Set(subModels.map((s) => s.name));
1672
1714
  const seen = /* @__PURE__ */ new Set();
1673
1715
  const extraImports = [];
1674
1716
  for (const imp of resolved?.imports ?? []) {
1675
- if (!imp.name || imp.name === entry.name) continue;
1717
+ if (!imp.name || imp.name === entry.name || localNames.has(imp.name)) continue;
1676
1718
  const bindingKey = imp.alias ?? imp.name;
1677
1719
  if (seen.has(bindingKey)) continue;
1678
1720
  seen.add(bindingKey);
@@ -1682,7 +1724,7 @@ function renderReusableSchemaEntry(entry, context) {
1682
1724
  });
1683
1725
  }
1684
1726
  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}>;`,
1727
+ 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
1728
  extraImports
1687
1729
  };
1688
1730
  }
@@ -1791,6 +1833,10 @@ function generateZodSchemasInline(builder, output, includeZodImport = true, para
1791
1833
  const schemasWithOpenApiDef = builder.schemas.filter((s) => s.schema);
1792
1834
  if (schemasWithOpenApiDef.length === 0) return "";
1793
1835
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1836
+ assertZodTarget({
1837
+ variant: output.override.zod.variant,
1838
+ isZodV4
1839
+ });
1794
1840
  const strict = output.override.zod.strict.body;
1795
1841
  const coerce = output.override.zod.coerce.body;
1796
1842
  const schemas = [];
@@ -1805,7 +1851,7 @@ function generateZodSchemasInline(builder, output, includeZodImport = true, para
1805
1851
  const parsedZodDefinition = parseZodValidationSchemaDefinition(generateZodValidationSchemaDefinition(dereference(schemaObject, context), context, name, strict, isZodV4, {
1806
1852
  required: true,
1807
1853
  emitMeta: output.override.zod.generateMeta
1808
- }), context, coerce, strict, isZodV4);
1854
+ }), context, coerce, strict, isZodV4, void 0, void 0, output.override.zod.variant);
1809
1855
  schemas.push({
1810
1856
  schemaName: name,
1811
1857
  consts: parsedZodDefinition.consts,
@@ -1813,10 +1859,14 @@ function generateZodSchemasInline(builder, output, includeZodImport = true, para
1813
1859
  });
1814
1860
  }
1815
1861
  if (schemas.length === 0) return "";
1816
- return generateZodSchemaFileContent("", schemas, includeZodImport);
1862
+ return generateZodSchemaFileContent("", schemas, output.override.zod.variant, includeZodImport);
1817
1863
  }
1818
1864
  function generateZodSchemasInlineReusable(builder, output, includeZodImport = true, paramsMutator, includeParamsImport = false) {
1819
1865
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1866
+ assertZodTarget({
1867
+ variant: output.override.zod.variant,
1868
+ isZodV4
1869
+ });
1820
1870
  const strict = output.override.zod.strict.body;
1821
1871
  const coerce = output.override.zod.coerce.body;
1822
1872
  const context = {
@@ -1833,10 +1883,11 @@ function generateZodSchemasInlineReusable(builder, output, includeZodImport = tr
1833
1883
  strict,
1834
1884
  isZodV4,
1835
1885
  coerce,
1886
+ variant: output.override.zod.variant,
1836
1887
  generateMeta: output.override.zod.generateMeta,
1837
1888
  paramsMutator
1838
- })).map((entry) => renderReusableSchemaEntry(entry, context).content).join("\n\n");
1839
- const zodImport = includeZodImport ? `import { z as zod } from 'zod';\n` : "";
1889
+ })).map((entry) => renderReusableSchemaEntry(entry, context, output.override.zod.variant).content).join("\n\n");
1890
+ const zodImport = includeZodImport ? `${getZodSchemaImportStatement(output.override.zod.variant)}\n` : "";
1840
1891
  const paramsImport = paramsMutator && includeParamsImport && bodyReferencesMutator(body, paramsMutator) ? `${buildMutatorImportStatement(paramsMutator)}\n` : "";
1841
1892
  return `${zodImport || paramsImport ? `${zodImport}${paramsImport}\n` : ""}${body}\n`;
1842
1893
  }
@@ -1846,6 +1897,10 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1846
1897
  const schemasWithOpenApiDef = builder.schemas.filter((s) => s.schema);
1847
1898
  const schemasToWrite = [];
1848
1899
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1900
+ assertZodTarget({
1901
+ variant: output.override.zod.variant,
1902
+ isZodV4
1903
+ });
1849
1904
  const strict = output.override.zod.strict.body;
1850
1905
  const coerce = output.override.zod.coerce.body;
1851
1906
  for (const generatorSchema of schemasWithOpenApiDef) {
@@ -1863,7 +1918,7 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1863
1918
  const parsedZodDefinition = parseZodValidationSchemaDefinition(generateZodValidationSchemaDefinition(dereference(schemaObject, context), context, name, strict, isZodV4, {
1864
1919
  required: true,
1865
1920
  emitMeta: output.override.zod.generateMeta
1866
- }), context, coerce, strict, isZodV4);
1921
+ }), context, coerce, strict, isZodV4, void 0, void 0, output.override.zod.variant);
1867
1922
  schemasToWrite.push({
1868
1923
  schemaName: name,
1869
1924
  filePath,
@@ -1873,7 +1928,7 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1873
1928
  }
1874
1929
  const groupedSchemasToWrite = groupSchemasByFilePath(schemasToWrite);
1875
1930
  for (const schemaGroup of groupedSchemasToWrite) {
1876
- const fileContent = generateZodSchemaFileContent(header, schemaGroup);
1931
+ const fileContent = generateZodSchemaFileContent(header, schemaGroup, output.override.zod.variant);
1877
1932
  await fs.outputFile(schemaGroup[0].filePath, fileContent);
1878
1933
  }
1879
1934
  const writtenSchemaNames = groupedSchemasToWrite.map((schemaGroup) => schemaGroup[0].schemaName);
@@ -1892,6 +1947,10 @@ async function writeZodSchemas(builder, schemasPath, fileExtension, header, outp
1892
1947
  async function writeZodSchemasReusable(builder, schemasPath, fileExtension, header, output, paramsMutator, schemaTagMap) {
1893
1948
  const isSplit = !!schemaTagMap;
1894
1949
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
1950
+ assertZodTarget({
1951
+ variant: output.override.zod.variant,
1952
+ isZodV4
1953
+ });
1895
1954
  const strict = output.override.zod.strict.body;
1896
1955
  const coerce = output.override.zod.coerce.body;
1897
1956
  const context = {
@@ -1907,6 +1966,7 @@ async function writeZodSchemasReusable(builder, schemasPath, fileExtension, head
1907
1966
  strict,
1908
1967
  isZodV4,
1909
1968
  coerce,
1969
+ variant: output.override.zod.variant,
1910
1970
  generateMeta: output.override.zod.generateMeta,
1911
1971
  paramsMutator
1912
1972
  }));
@@ -1916,7 +1976,7 @@ async function writeZodSchemasReusable(builder, schemasPath, fileExtension, head
1916
1976
  const tagDir = getSchemaDir(schemaTagMap, entry.name);
1917
1977
  const filePath = isSplit ? path.join(schemasPath, tagDir, `${fileName}${fileExtension}`) : path.join(schemasPath, `${fileName}${fileExtension}`);
1918
1978
  const importExt = getImportExtension(fileExtension, output.tsconfig);
1919
- const rendered = renderReusableSchemaEntry(entry, context);
1979
+ const rendered = renderReusableSchemaEntry(entry, context, output.override.zod.variant);
1920
1980
  const refImports = buildSiblingImports({
1921
1981
  usedRefs: entry.usedRefs,
1922
1982
  extraImports: rendered.extraImports,
@@ -1935,7 +1995,7 @@ async function writeZodSchemasReusable(builder, schemasPath, fileExtension, head
1935
1995
  path: isSplit ? adjustMutatorPathForDir(paramsMutator.path, tagDir) : paramsMutator.path
1936
1996
  }) : void 0;
1937
1997
  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`;
1998
+ const fileContent = `${header}${getZodSchemaImportStatement(output.override.zod.variant)}\n` + (imports ? `${imports}\n\n` : "\n") + `${rendered.content}\n`;
1939
1999
  await fs.outputFile(filePath, fileContent);
1940
2000
  }
1941
2001
  if (output.indexFiles && !isSplit && rewritten.length > 0) await writeZodSchemaIndex(schemasPath, fileExtension, header, rewritten.map((e) => e.name), output.namingConvention, true, output.tsconfig);
@@ -1956,6 +2016,10 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
1956
2016
  const verbOptionsArray = Object.values(verbOptions);
1957
2017
  if (verbOptionsArray.length === 0) return /* @__PURE__ */ new Map();
1958
2018
  const isZodV4 = resolveIsZodV4(output.override.zod.version, output.packageJson);
2019
+ assertZodTarget({
2020
+ variant: output.override.zod.variant,
2021
+ isZodV4
2022
+ });
1959
2023
  const strict = output.override.zod.strict.body;
1960
2024
  const coerce = output.override.zod.coerce.body;
1961
2025
  const useReusableSchemas = output.override.zod.generateReusableSchemas === true;
@@ -2032,7 +2096,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
2032
2096
  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
2097
  required: true,
2034
2098
  useReusableSchemas
2035
- }), zodContext, coerce, strict, isZodV4);
2099
+ }), zodContext, coerce, strict, isZodV4, void 0, void 0, output.override.zod.variant);
2036
2100
  let zodExpression = parsedZodDefinition.zod;
2037
2101
  let importStatements;
2038
2102
  if (useReusableSchemas && parsedZodDefinition.usedRefs.size > 0) {
@@ -2053,7 +2117,7 @@ async function writeZodSchemasFromVerbs(verbOptions, schemasPath, fileExtension,
2053
2117
  }
2054
2118
  const groupedSchemasToWrite = groupSchemasByFilePath(schemasToWrite);
2055
2119
  for (const schemaGroup of groupedSchemasToWrite) {
2056
- const fileContent = generateZodSchemaFileContent(header, schemaGroup);
2120
+ const fileContent = generateZodSchemaFileContent(header, schemaGroup, output.override.zod.variant);
2057
2121
  await fs.outputFile(schemaGroup[0].filePath, fileContent);
2058
2122
  }
2059
2123
  const writtenSchemaNames = groupedSchemasToWrite.map((schemaGroup) => schemaGroup[0].schemaName);
@@ -2100,6 +2164,23 @@ async function runFormatter(formatter, paths, projectTitle) {
2100
2164
  break;
2101
2165
  }
2102
2166
  }
2167
+ function getComparableFilePath(filePath) {
2168
+ const resolvedPath = path.resolve(filePath);
2169
+ let comparablePath = resolvedPath;
2170
+ try {
2171
+ comparablePath = fs.realpathSync(resolvedPath);
2172
+ } catch (error) {
2173
+ if (error.code !== "ENOENT") throw error;
2174
+ }
2175
+ return process.platform === "win32" || process.platform === "darwin" ? comparablePath.toLowerCase() : comparablePath;
2176
+ }
2177
+ function excludeFilePath(filePaths, filePathToExclude) {
2178
+ const comparablePathToExclude = getComparableFilePath(filePathToExclude);
2179
+ return filePaths.map((filePath) => ({
2180
+ filePath,
2181
+ comparablePath: getComparableFilePath(filePath)
2182
+ })).filter(({ comparablePath }) => comparablePath !== comparablePathToExclude).map(({ filePath }) => filePath);
2183
+ }
2103
2184
  function getHeader(option, info) {
2104
2185
  if (!option) return "";
2105
2186
  const header = option(info);
@@ -2223,6 +2304,13 @@ function shouldGenerateZodSchemasInline(output, hasOperations) {
2223
2304
  function shouldGenerateSchemas(output, hasOperations) {
2224
2305
  return !output.schemas && !isSchemaValidatorClient(output.client) || shouldGenerateZodSchemasInline(output, hasOperations);
2225
2306
  }
2307
+ function getImplementationPathsForIndex(output, implementationPaths, indexFile) {
2308
+ const shouldExcludeSelf = output.indexFiles;
2309
+ const paths = shouldExcludeSelf ? excludeFilePath(implementationPaths, indexFile) : implementationPaths;
2310
+ if (!(shouldExcludeSelf && output.mode === OutputMode.SPLIT && getComparableFilePath(output.target) === getComparableFilePath(indexFile))) return paths;
2311
+ const targetInfo = getFileInfo(output.target, { extension: output.fileExtension });
2312
+ return excludeFilePath(paths, path.join(targetInfo.dirname, `${targetInfo.filename}.schemas${output.fileExtension}`));
2313
+ }
2226
2314
  async function writeSpecs(builder, workspace, options, projectName) {
2227
2315
  const { info, schemas, target } = builder;
2228
2316
  const { output } = options;
@@ -2357,7 +2445,8 @@ async function writeSpecs(builder, workspace, options, projectName) {
2357
2445
  const indexFile = path.join(workspacePath, "index.ts");
2358
2446
  const mockExtensions = output.mock.generators.map((g) => getMockFileExtensionByTypeName(g));
2359
2447
  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) => {
2448
+ const implementationPathsForIndex = getImplementationPathsForIndex(output, implementationPaths, indexFile);
2449
+ const imports = implementationPathsForIndex.filter((p) => mockExtensions.length === 0 || !mockExtensions.some((ext) => p.endsWith(`.${ext}.ts`))).map((p) => {
2361
2450
  const relative = upath.getRelativeImportPath(indexFile, p, true);
2362
2451
  return (relative.endsWith(output.fileExtension) ? relative.slice(0, -output.fileExtension.length) : relative.replace(/\.[^/.]+$/, "")) + importExtension;
2363
2452
  });
@@ -2369,10 +2458,10 @@ async function writeSpecs(builder, workspace, options, projectName) {
2369
2458
  if (output.indexFiles) {
2370
2459
  if (await fs.pathExists(indexFile)) {
2371
2460
  const data = await fs.readFile(indexFile, "utf8");
2372
- const importsNotDeclared = imports.filter((imp) => !data.includes(imp));
2461
+ const importsNotDeclared = imports.filter((imp) => !data.includes(`export * from '${imp}'`));
2373
2462
  await fs.appendFile(indexFile, unique(importsNotDeclared).map((imp) => `export * from '${imp}';\n`).join(""));
2374
2463
  } else await fs.outputFile(indexFile, unique(imports).map((imp) => `export * from '${imp}';`).join("\n") + "\n");
2375
- implementationPaths = [indexFile, ...implementationPaths];
2464
+ implementationPaths = [indexFile, ...implementationPathsForIndex];
2376
2465
  }
2377
2466
  }
2378
2467
  if (builder.extraFiles.length > 0) {
@@ -2512,4 +2601,4 @@ async function loadConfigFile(configFilePath) {
2512
2601
  //#endregion
2513
2602
  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
2603
 
2515
- //# sourceMappingURL=config-D-TQRn-G.mjs.map
2604
+ //# sourceMappingURL=config-C8B9Lol2.mjs.map