mobx-tanstack-query-api 0.40.0 → 0.41.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/cli.cjs CHANGED
@@ -7,7 +7,6 @@ const swaggerTypescriptApi = require("swagger-typescript-api");
7
7
  const text = require("yummies/text");
8
8
  const tsMorph = require("ts-morph");
9
9
  var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
10
- const fs = {};
11
10
  const LINTERS_IGNORE = `/* eslint-disable */
12
11
  /* tslint:disable */`;
13
12
  const buildGenerics = (contract) => {
@@ -220,6 +219,10 @@ const createShortModelType = (shortModelType) => {
220
219
  description: shortModelType.description || ""
221
220
  };
222
221
  };
222
+ const DEFAULT_ZOD_CONTRACT_SUFFIX = "Contract";
223
+ function getZodContractSuffix(zodContracts) {
224
+ return (typeof zodContracts === "object" && zodContracts !== null && typeof zodContracts.suffix === "string" ? zodContracts.suffix : void 0) ?? DEFAULT_ZOD_CONTRACT_SUFFIX;
225
+ }
223
226
  const REF_PREFIX = "#/components/schemas/";
224
227
  const REF_PREFIX_PARAMS = "#/components/parameters/";
225
228
  function parseRef(ref) {
@@ -271,14 +274,14 @@ function schemaToNumber(schema) {
271
274
  if (schema.maximum != null) n += `.max(${schema.maximum})`;
272
275
  return n;
273
276
  }
274
- function schemaToArray(schema, schemas, schemaKeyToVarName2, visited) {
275
- const items = schema.items ? schemaToZodExpr(schema.items, schemas, schemaKeyToVarName2, visited) : "z.any()";
277
+ function schemaToArray(schema, schemas, schemaKeyToVarName, visited) {
278
+ const items = schema.items ? schemaToZodExpr(schema.items, schemas, schemaKeyToVarName, visited) : "z.any()";
276
279
  let a = `z.array(${items})`;
277
280
  if (schema.minItems != null) a += `.min(${schema.minItems})`;
278
281
  if (schema.maxItems != null) a += `.max(${schema.maxItems})`;
279
282
  return a;
280
283
  }
281
- function schemaToObject(schema, schemas, schemaKeyToVarName2, visited) {
284
+ function schemaToObject(schema, schemas, schemaKeyToVarName, visited) {
282
285
  if (schema.properties && Object.keys(schema.properties).length > 0) {
283
286
  const required = new Set(schema.required ?? []);
284
287
  const entries = Object.entries(schema.properties).map(
@@ -286,7 +289,7 @@ function schemaToObject(schema, schemas, schemaKeyToVarName2, visited) {
286
289
  const expr = schemaToZodExpr(
287
290
  propSchema,
288
291
  schemas,
289
- schemaKeyToVarName2,
292
+ schemaKeyToVarName,
290
293
  visited
291
294
  );
292
295
  const optional = !required.has(propName);
@@ -304,26 +307,26 @@ ${entries.join(",\n")}
304
307
  const value = schemaToZodExpr(
305
308
  schema.additionalProperties,
306
309
  schemas,
307
- schemaKeyToVarName2,
310
+ schemaKeyToVarName,
308
311
  visited
309
312
  );
310
313
  return `z.record(z.string(), ${value})`;
311
314
  }
312
315
  return "z.record(z.string(), z.any())";
313
316
  }
314
- function schemaToZodExpr(schema, schemas, schemaKeyToVarName2, visited) {
317
+ function schemaToZodExpr(schema, schemas, schemaKeyToVarName, visited) {
315
318
  if (!schema) return "z.any()";
316
319
  if (schema.$ref) {
317
320
  const key = parseRef(schema.$ref);
318
321
  if (key && key in schemas) {
319
322
  const isCycle = visited.has(key);
320
- return isCycle ? `z.lazy((): z.ZodTypeAny => ${schemaKeyToVarName2(key)})` : `z.lazy(() => ${schemaKeyToVarName2(key)})`;
323
+ return isCycle ? `z.lazy((): z.ZodTypeAny => ${schemaKeyToVarName(key)})` : `z.lazy(() => ${schemaKeyToVarName(key)})`;
321
324
  }
322
325
  return "z.any()";
323
326
  }
324
327
  if (schema.allOf && schema.allOf.length > 0) {
325
328
  const parts = schema.allOf.map(
326
- (part) => schemaToZodExpr(part, schemas, schemaKeyToVarName2, visited)
329
+ (part) => schemaToZodExpr(part, schemas, schemaKeyToVarName, visited)
327
330
  );
328
331
  const base2 = parts.length === 1 ? parts[0] : parts.reduce((acc, p) => `z.intersection(${acc}, ${p})`);
329
332
  return schema.nullable === true ? `${base2}.nullable()` : base2;
@@ -342,10 +345,10 @@ function schemaToZodExpr(schema, schemas, schemaKeyToVarName2, visited) {
342
345
  base = "z.boolean()";
343
346
  break;
344
347
  case "array":
345
- base = schemaToArray(schema, schemas, schemaKeyToVarName2, visited);
348
+ base = schemaToArray(schema, schemas, schemaKeyToVarName, visited);
346
349
  break;
347
350
  case "object":
348
- base = schemaToObject(schema, schemas, schemaKeyToVarName2, visited);
351
+ base = schemaToObject(schema, schemas, schemaKeyToVarName, visited);
349
352
  break;
350
353
  default:
351
354
  base = "z.any()";
@@ -375,9 +378,9 @@ function collectRefs(schema, schemas, out) {
375
378
  collectRefs(schema.additionalProperties, schemas, out);
376
379
  }
377
380
  }
378
- function schemaKeyToVarName(key, utils) {
381
+ function schemaKeyToContractVarName(key, utils, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
379
382
  const _ = utils._;
380
- return `${_.camelCase(key)}Schema`;
383
+ return `${_.camelCase(key)}${contractSuffix}`;
381
384
  }
382
385
  function resolveQueryParameters(operation, componentsParameters) {
383
386
  const list = [];
@@ -406,13 +409,13 @@ function resolveQueryParameters(operation, componentsParameters) {
406
409
  }
407
410
  return list;
408
411
  }
409
- function queryParamsToZodObject(queryParams, schemas, schemaKeyToVarName2) {
412
+ function queryParamsToZodObject(queryParams, schemas, schemaKeyToContractVarName2) {
410
413
  if (queryParams.length === 0) return "z.object({})";
411
414
  const entries = queryParams.map(({ name, required, schema }) => {
412
415
  const expr = schemaToZodExpr(
413
416
  schema,
414
417
  schemas,
415
- schemaKeyToVarName2,
418
+ schemaKeyToContractVarName2,
416
419
  /* @__PURE__ */ new Set()
417
420
  );
418
421
  const field = required ? expr : `${expr}.optional()`;
@@ -422,32 +425,36 @@ function queryParamsToZodObject(queryParams, schemas, schemaKeyToVarName2) {
422
425
  ${entries.join(",\n")}
423
426
  })`;
424
427
  }
425
- function generateAuxiliarySchemas(schemaKeys, schemas, schemaKeyToVarNameFn, visited) {
428
+ function generateAuxiliarySchemas(schemaKeys, schemas, schemaKeyToContractVarNameFn, visited) {
426
429
  const lines = [];
427
430
  for (const key of schemaKeys) {
428
431
  if (visited.has(key)) continue;
429
432
  visited.add(key);
430
433
  const schema = schemas[key];
431
434
  if (!schema) continue;
432
- const varName = schemaKeyToVarNameFn(key);
435
+ const varName = schemaKeyToContractVarNameFn(key);
433
436
  const cyclePath = /* @__PURE__ */ new Set([key]);
434
437
  const expr = schemaToZodExpr(
435
438
  schema,
436
439
  schemas,
437
- schemaKeyToVarNameFn,
440
+ schemaKeyToContractVarNameFn,
438
441
  cyclePath
439
442
  );
440
443
  lines.push(`export const ${varName} = ${expr};`);
441
444
  }
442
445
  return lines;
443
446
  }
444
- function buildCentralZodSchemasFile(params) {
445
- const { componentsSchemas, utils } = params;
446
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
447
+ function buildCentralZodContractsFile(params) {
448
+ const {
449
+ componentsSchemas,
450
+ utils,
451
+ contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX
452
+ } = params;
453
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
447
454
  const lines = generateAuxiliarySchemas(
448
455
  Object.keys(componentsSchemas),
449
456
  componentsSchemas,
450
- schemaKeyToVarNameFn,
457
+ schemaKeyToContractVarNameFn,
451
458
  /* @__PURE__ */ new Set()
452
459
  );
453
460
  return `import * as z from "zod";
@@ -469,7 +476,7 @@ function typeToZodSchemaFallback(typeStr) {
469
476
  if (t === "unknown") return "z.unknown()";
470
477
  return "z.any()";
471
478
  }
472
- function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix) {
479
+ function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
473
480
  const t = typeStr.trim();
474
481
  if (!schemas || Object.keys(schemas).length === 0) {
475
482
  return { expr: typeToZodSchemaFallback(t), refs: [] };
@@ -482,36 +489,36 @@ function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix) {
482
489
  }
483
490
  const refs = /* @__PURE__ */ new Set();
484
491
  collectRefs(schema, schemas, refs);
485
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
492
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
486
493
  const expr = schemaToZodExpr(
487
494
  schema,
488
495
  schemas,
489
- schemaKeyToVarNameFn,
496
+ schemaKeyToContractVarNameFn,
490
497
  /* @__PURE__ */ new Set()
491
498
  );
492
499
  return { expr, refs: [...refs] };
493
500
  }
494
- function schemaKeyToZod(schemaKey, schemas, utils) {
501
+ function schemaKeyToZod(schemaKey, schemas, utils, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
495
502
  const schema = schemas[schemaKey];
496
503
  if (!schema) return { expr: "z.any()", refs: [] };
497
504
  const refs = /* @__PURE__ */ new Set();
498
505
  collectRefs(schema, schemas, refs);
499
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
506
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
500
507
  const expr = schemaToZodExpr(
501
508
  schema,
502
509
  schemas,
503
- schemaKeyToVarNameFn,
510
+ schemaKeyToContractVarNameFn,
504
511
  /* @__PURE__ */ new Set()
505
512
  );
506
513
  return { expr, refs: [...refs] };
507
514
  }
508
515
  function buildEndpointZodContractsCode(params) {
509
516
  const {
510
- routeNameUsage,
511
517
  inputParams,
512
518
  responseDataTypeName,
513
- contractsVarName,
519
+ contractVarName,
514
520
  utils,
521
+ contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX,
515
522
  componentsSchemas = null,
516
523
  typeSuffix = "DC",
517
524
  responseSchemaKey,
@@ -520,13 +527,11 @@ function buildEndpointZodContractsCode(params) {
520
527
  openApiComponentsParameters = null,
521
528
  queryParamName = "query"
522
529
  } = params;
523
- const _ = utils._;
524
- const paramsSchemaName = `${_.camelCase(routeNameUsage)}ParamsSchema`;
525
- const dataSchemaName = `${_.camelCase(routeNameUsage)}DataSchema`;
530
+ utils._;
526
531
  const allAuxiliaryKeys = /* @__PURE__ */ new Set();
527
532
  const paramParts = [];
528
533
  const resolvedQueryParams = openApiOperation && (openApiComponentsParameters || openApiOperation.parameters?.length) ? resolveQueryParameters(openApiOperation, openApiComponentsParameters) : [];
529
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
534
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix);
530
535
  for (const p of inputParams) {
531
536
  let expr;
532
537
  let refKeys = [];
@@ -534,14 +539,15 @@ function buildEndpointZodContractsCode(params) {
534
539
  expr = queryParamsToZodObject(
535
540
  resolvedQueryParams,
536
541
  componentsSchemas,
537
- schemaKeyToVarNameFn
542
+ schemaKeyToContractVarNameFn
538
543
  );
539
544
  } else {
540
545
  const result = typeToZodSchemaWithSchema(
541
546
  p.type,
542
547
  componentsSchemas,
543
548
  utils,
544
- typeSuffix
549
+ typeSuffix,
550
+ contractSuffix
545
551
  );
546
552
  expr = result.expr;
547
553
  refKeys = result.refs;
@@ -550,11 +556,17 @@ function buildEndpointZodContractsCode(params) {
550
556
  const schemaWithOptional = p.optional ? `${expr}.optional()` : expr;
551
557
  paramParts.push(`${p.name}: ${schemaWithOptional}`);
552
558
  }
553
- const responseResult = responseSchemaKey && componentsSchemas && responseSchemaKey in componentsSchemas ? schemaKeyToZod(responseSchemaKey, componentsSchemas, utils) : typeToZodSchemaWithSchema(
559
+ const responseResult = responseSchemaKey && componentsSchemas && responseSchemaKey in componentsSchemas ? schemaKeyToZod(
560
+ responseSchemaKey,
561
+ componentsSchemas,
562
+ utils,
563
+ contractSuffix
564
+ ) : typeToZodSchemaWithSchema(
554
565
  responseDataTypeName,
555
566
  componentsSchemas,
556
567
  utils,
557
- typeSuffix
568
+ typeSuffix,
569
+ contractSuffix
558
570
  );
559
571
  const useDataSchemaFromCentral = useExternalZodSchemas && responseSchemaKey && componentsSchemas && responseSchemaKey in componentsSchemas;
560
572
  if (useDataSchemaFromCentral) {
@@ -562,31 +574,27 @@ function buildEndpointZodContractsCode(params) {
562
574
  } else {
563
575
  for (const k of responseResult.refs) allAuxiliaryKeys.add(k);
564
576
  }
565
- const zodSchemaImportNames = useExternalZodSchemas && allAuxiliaryKeys.size > 0 ? [...allAuxiliaryKeys].map(schemaKeyToVarNameFn) : [];
577
+ const zodContractImportNames = useExternalZodSchemas && allAuxiliaryKeys.size > 0 ? [...allAuxiliaryKeys].map(schemaKeyToContractVarNameFn) : [];
566
578
  const allAuxiliary = useExternalZodSchemas ? [] : generateAuxiliarySchemas(
567
579
  [...allAuxiliaryKeys],
568
580
  componentsSchemas ?? {},
569
- schemaKeyToVarNameFn,
581
+ schemaKeyToContractVarNameFn,
570
582
  /* @__PURE__ */ new Set()
571
583
  );
572
- const paramsFields = paramParts.join(",\n ");
573
- const paramsSchemaCode = `export const ${paramsSchemaName} = z.object({
574
- ${paramsFields},
575
- });`;
576
- const dataSchemaCode = useDataSchemaFromCentral ? `export const ${dataSchemaName} = ${schemaKeyToVarNameFn(responseSchemaKey)};` : `export const ${dataSchemaName} = ${responseResult.expr};`;
577
- const contractsCode = `export const ${contractsVarName} = {
578
- params: ${paramsSchemaName},
579
- data: ${dataSchemaName},
584
+ const paramsFields = paramParts.join(",\n ");
585
+ const paramsSchemaExpr = `z.object({
586
+ ${paramsFields},
587
+ })`;
588
+ const dataSchemaExpr = useDataSchemaFromCentral ? schemaKeyToContractVarNameFn(responseSchemaKey) : responseResult.expr;
589
+ const contractsCode = `export const ${contractVarName} = {
590
+ params: ${paramsSchemaExpr},
591
+ data: ${dataSchemaExpr},
580
592
  };`;
581
593
  const auxiliaryBlock = allAuxiliary.length > 0 ? `${allAuxiliary.join("\n\n")}
582
594
 
583
595
  ` : "";
584
- const content = `${auxiliaryBlock}${paramsSchemaCode}
585
-
586
- ${dataSchemaCode}
587
-
588
- ${contractsCode}`;
589
- return { content, zodSchemaImportNames };
596
+ const content = `${auxiliaryBlock}${contractsCode}`;
597
+ return { content, zodContractImportNames };
590
598
  }
591
599
  const formatGroupNameEnumKey = (groupName, { _ }) => _.upperFirst(_.camelCase(groupName));
592
600
  const formatTagNameEnumKey = (tagName, utils) => formatGroupNameEnumKey(tagName, utils);
@@ -746,10 +754,7 @@ const newEndpointTmpl = ({
746
754
  }) => {
747
755
  const zodContractsIsObject = typeof zodContracts === "object" && zodContracts !== null;
748
756
  const hasZodContracts = zodContracts === true || zodContractsIsObject;
749
- const validateOpt = zodContractsIsObject ? zodContracts.validate : zodContracts === true ? true : void 0;
750
- const throwOpt = zodContractsIsObject ? zodContracts.throw : void 0;
751
- const validateOptObj = validateOpt != null && typeof validateOpt === "object" && !Array.isArray(validateOpt) ? validateOpt : null;
752
- const throwOptObj = throwOpt != null && typeof throwOpt === "object" && !Array.isArray(throwOpt) ? throwOpt : null;
757
+ const contractSuffix = getZodContractSuffix(zodContracts);
753
758
  const { _ } = utils;
754
759
  const positiveResponseTypes = route.raw.responsesTypes?.filter(
755
760
  (it) => +it.status >= 200 && +it.status < 300 && (!it.typeData || filterTypes(it.typeData))
@@ -863,7 +868,24 @@ const newEndpointTmpl = ({
863
868
  });
864
869
  const isAllowedInputType = filterTypes(requestInputTypeDc);
865
870
  const defaultOkResponseType = positiveResponseTypes?.[0]?.type ?? "unknown";
866
- const contractsVarName = hasZodContracts ? `${_.camelCase(route.routeName.usage)}Contracts` : null;
871
+ const contractVarName = hasZodContracts ? `${_.camelCase(route.routeName.usage)}${contractSuffix}` : null;
872
+ const routeInfoForContracts = contractVarName != null ? {
873
+ operationId: raw.operationId ?? "",
874
+ path: path2,
875
+ method,
876
+ contractName: contractVarName
877
+ } : null;
878
+ const resolveZodContractsMaybeFn = (value) => {
879
+ if (typeof value === "function" && routeInfoForContracts != null) {
880
+ return value(routeInfoForContracts.contractName, routeInfoForContracts);
881
+ }
882
+ return value;
883
+ };
884
+ const validateOpt = zodContractsIsObject ? resolveZodContractsMaybeFn(zodContracts.validate) : zodContracts === true ? true : void 0;
885
+ const throwOpt = zodContractsIsObject ? resolveZodContractsMaybeFn(zodContracts.throw) : void 0;
886
+ const isRuntimeContractsRuleObject = (value) => value != null && typeof value === "object" && !Array.isArray(value);
887
+ const validateOptObj = isRuntimeContractsRuleObject(validateOpt) ? validateOpt : null;
888
+ const throwOptObj = isRuntimeContractsRuleObject(throwOpt) ? throwOpt : null;
867
889
  const swaggerSchema = configuration.config?.swaggerSchema ?? configuration?.swaggerSchema;
868
890
  const componentsSchemas = swaggerSchema?.components?.schemas;
869
891
  let operationFromSpec = null;
@@ -900,46 +922,36 @@ const newEndpointTmpl = ({
900
922
  if (candidate in componentsSchemas) responseSchemaKey = candidate;
901
923
  }
902
924
  }
903
- const contractsCode = hasZodContracts && contractsVarName ? buildEndpointZodContractsCode({
925
+ const contractsCode = hasZodContracts && contractVarName ? buildEndpointZodContractsCode({
904
926
  routeNameUsage: route.routeName.usage,
905
927
  inputParams,
906
928
  responseDataTypeName: defaultOkResponseType,
907
- contractsVarName,
929
+ contractVarName,
908
930
  utils,
909
931
  componentsSchemas: componentsSchemas ?? void 0,
910
932
  typeSuffix: "DC",
911
933
  responseSchemaKey: responseSchemaKey ?? void 0,
912
934
  useExternalZodSchemas: Boolean(relativePathZodSchemas),
935
+ contractSuffix,
913
936
  openApiOperation: operationFromSpec ?? void 0,
914
937
  openApiComponentsParameters: swaggerSchema?.components?.parameters ?? void 0,
915
938
  queryParamName: queryName
916
939
  }) : null;
917
- const appendRuleOpt = zodContractsIsObject && zodContracts.appendRule != null ? zodContracts.appendRule : null;
918
- const routeInfoForAppend = contractsVarName != null ? {
919
- operationId: raw.operationId ?? "",
920
- path: path2,
921
- method,
922
- contractName: contractsVarName
923
- } : null;
924
- const contractsLine = (() => {
925
- if (contractsVarName == null) return "";
940
+ const appendRuleOpt = zodContractsIsObject && zodContracts.appendRule != null ? resolveZodContractsMaybeFn(zodContracts.appendRule) : null;
941
+ const contractLine = (() => {
942
+ if (contractVarName == null) return "";
926
943
  if (typeof appendRuleOpt === "string")
927
- return `contracts: ${appendRuleOpt} ? ${contractsVarName} : undefined,`;
928
- if (typeof appendRuleOpt === "function" && routeInfoForAppend) {
929
- const include = appendRuleOpt(
930
- routeInfoForAppend.contractName,
931
- routeInfoForAppend
932
- );
933
- return include ? `contracts: ${contractsVarName},` : "contracts: undefined,";
934
- }
935
- return `contracts: ${contractsVarName},`;
944
+ return `contract: ${appendRuleOpt} ? ${contractVarName} : undefined,`;
945
+ if (appendRuleOpt === false) return "contract: undefined,";
946
+ if (appendRuleOpt === true) return `contract: ${contractVarName},`;
947
+ return `contract: ${contractVarName},`;
936
948
  })();
937
- const validateContractsLine = (() => {
949
+ const validateContractLine = (() => {
938
950
  if (validateOpt === void 0) return "";
939
951
  if (typeof validateOpt === "string")
940
- return `validateContracts: ${validateOpt},`;
952
+ return `validateContract: ${validateOpt},`;
941
953
  if (typeof validateOpt === "boolean")
942
- return `validateContracts: ${validateOpt},`;
954
+ return `validateContract: ${validateOpt},`;
943
955
  if (validateOptObj !== null) {
944
956
  const parts = [];
945
957
  if (validateOptObj.params !== void 0)
@@ -950,7 +962,7 @@ const newEndpointTmpl = ({
950
962
  parts.push(
951
963
  `data: ${typeof validateOptObj.data === "string" ? validateOptObj.data : validateOptObj.data}`
952
964
  );
953
- return parts.length > 0 ? `validateContracts: { ${parts.join(", ")} },` : "";
965
+ return parts.length > 0 ? `validateContract: { ${parts.join(", ")} },` : "";
954
966
  }
955
967
  return "";
956
968
  })();
@@ -972,7 +984,7 @@ const newEndpointTmpl = ({
972
984
  reservedDataContractNames,
973
985
  localModelTypes: isAllowedInputType ? [requestInputTypeDc] : [],
974
986
  contractsCode: contractsCode ?? void 0,
975
- contractsVarName: contractsVarName ?? void 0,
987
+ contractVarName: contractVarName ?? void 0,
976
988
  content: `
977
989
  new ${importFileParams.endpoint.exportName}<
978
990
  ${getHttpRequestGenerics()},
@@ -1005,8 +1017,8 @@ new ${importFileParams.endpoint.exportName}<
1005
1017
  ${groupName ? `group: ${metaInfo ? `Group.${formatGroupNameEnumKey(groupName, utils)}` : `"${groupName}"`},` : ""}
1006
1018
  ${metaInfo?.namespace ? `namespace,` : ""}
1007
1019
  meta: ${requestInfoMeta?.tmplData ?? "{} as any"},
1008
- ${contractsLine}
1009
- ${validateContractsLine}
1020
+ ${contractLine}
1021
+ ${validateContractLine}
1010
1022
  ${throwContractsLine}
1011
1023
  },
1012
1024
  ${importFileParams.queryClient.exportName},
@@ -1056,17 +1068,17 @@ const allEndpointPerFileTmpl = async (params) => {
1056
1068
  const hasAnyZodContracts = newEndpointTemplates.some(
1057
1069
  (t) => t.contractsCode != null
1058
1070
  );
1059
- const allZodSchemaImportNames = /* @__PURE__ */ new Set();
1071
+ const allZodContractImportNames = /* @__PURE__ */ new Set();
1060
1072
  newEndpointTemplates.forEach((t) => {
1061
1073
  const c = t.contractsCode;
1062
- if (c != null && typeof c === "object" && c.zodSchemaImportNames?.length) {
1063
- for (const n of c.zodSchemaImportNames) {
1064
- allZodSchemaImportNames.add(n);
1074
+ if (c != null && typeof c === "object" && c.zodContractImportNames?.length) {
1075
+ for (const n of c.zodContractImportNames) {
1076
+ allZodContractImportNames.add(n);
1065
1077
  }
1066
1078
  }
1067
1079
  });
1068
1080
  const zodImportLine = hasAnyZodContracts ? 'import * as z from "zod";' : "";
1069
- const zodSchemasImportLine = allZodSchemaImportNames.size && relativePathZodSchemas ? `import { ${[...allZodSchemaImportNames].sort().join(", ")} } from "${relativePathZodSchemas}";` : "";
1081
+ const zodSchemasImportLine = allZodContractImportNames.size && relativePathZodSchemas ? `import { ${[...allZodContractImportNames].sort().join(", ")} } from "${relativePathZodSchemas}";` : "";
1070
1082
  const endpointTemplates = await Promise.all(
1071
1083
  newEndpointTemplates.map(
1072
1084
  async ({
@@ -1170,7 +1182,7 @@ const allExportsTmpl = async ({
1170
1182
  }) => {
1171
1183
  return await formatTSContent(`${LINTERS_IGNORE}
1172
1184
  export * from './data-contracts';
1173
- ${exportSchemas ? " export * from './schemas';\n " : ""}${collectedExportFiles.map((fileName) => `export * from './${fileName}';`).join("\n")}
1185
+ ${exportSchemas ? " export * from './contracts';\n " : ""}${collectedExportFiles.map((fileName) => `export * from './${fileName}';`).join("\n")}
1174
1186
  ${metaInfo ? 'export * from "./meta-info";' : ""}
1175
1187
  `);
1176
1188
  };
@@ -1252,7 +1264,7 @@ const endpointPerFileTmpl = async (params) => {
1252
1264
  const dataContractImportToken = "/*__DATA_CONTRACT_IMPORTS__*/";
1253
1265
  const contractsResult = contractsCode != null && typeof contractsCode === "object" ? contractsCode : null;
1254
1266
  const zodImportLine = contractsResult != null ? 'import * as z from "zod";' : "";
1255
- const zodSchemasImportLine = contractsResult?.zodSchemaImportNames?.length && relativePathZodSchemas ? `import { ${contractsResult.zodSchemaImportNames.join(", ")} } from "${relativePathZodSchemas}";` : "";
1267
+ const zodSchemasImportLine = contractsResult?.zodContractImportNames?.length && relativePathZodSchemas ? `import { ${contractsResult.zodContractImportNames.join(", ")} } from "${relativePathZodSchemas}";` : "";
1256
1268
  const contractsBlock = contractsResult != null ? `
1257
1269
 
1258
1270
  ${contractsResult.content}
@@ -1635,7 +1647,6 @@ const generateApi = async (params) => {
1635
1647
  }
1636
1648
  const codegenFs = codegenProcess.fileSystem;
1637
1649
  await Promise.resolve(codegenFs.cleanDir(paths.outputDir));
1638
- await fs.mkdir(paths.outputDir, { recursive: true });
1639
1650
  await Promise.resolve(codegenFs.createDir(paths.outputDir));
1640
1651
  const filterTypes = unpackFilterOption(
1641
1652
  params.filterTypes,
@@ -1663,7 +1674,8 @@ const generateApi = async (params) => {
1663
1674
  };
1664
1675
  const reservedDataContractNamesMap = /* @__PURE__ */ new Map();
1665
1676
  const componentsSchemasForZod = generated.configuration.config?.swaggerSchema?.components?.schemas ?? generated.configuration.swaggerSchema?.components?.schemas;
1666
- const hasZodSchemasFile = (params.zodContracts === true || typeof params.zodContracts === "object" && params.zodContracts != null) && componentsSchemasForZod && typeof componentsSchemasForZod === "object" && Object.keys(componentsSchemasForZod).length > 0;
1677
+ const zodContractSuffix = getZodContractSuffix(params.zodContracts);
1678
+ const hasZodContractsFile = (params.zodContracts === true || typeof params.zodContracts === "object" && params.zodContracts != null) && componentsSchemasForZod && typeof componentsSchemasForZod === "object" && Object.keys(componentsSchemasForZod).length > 0;
1667
1679
  const collectedExportFilesFromIndexFile = [];
1668
1680
  const groupsMap = /* @__PURE__ */ new Map();
1669
1681
  const nonEmptyGroups = /* @__PURE__ */ new Set();
@@ -1671,12 +1683,7 @@ const generateApi = async (params) => {
1671
1683
  if (params.groupBy == null) {
1672
1684
  collectedExportFilesFromIndexFile.push("endpoints");
1673
1685
  if (outputType === "one-endpoint-per-file") {
1674
- await fs.mkdir(path.resolve(paths.outputDir, "endpoints"), {
1675
- recursive: true
1676
- });
1677
- await Promise.resolve(
1678
- codegenFs.createDir(path.resolve(params.output, "endpoints"))
1679
- );
1686
+ codegenFs.createDir(path.resolve(params.output, "endpoints"));
1680
1687
  const fileNamesWithRequestInfo = [];
1681
1688
  for await (const route of allRoutes) {
1682
1689
  const {
@@ -1691,7 +1698,7 @@ const generateApi = async (params) => {
1691
1698
  groupNames: [],
1692
1699
  namespace
1693
1700
  },
1694
- relativePathZodSchemas: hasZodSchemasFile ? "../schemas" : null
1701
+ relativePathZodSchemas: hasZodContractsFile ? "../contracts" : null
1695
1702
  });
1696
1703
  if (Array.isArray(route.raw.tags)) {
1697
1704
  route.raw.tags.forEach((tag) => {
@@ -1736,7 +1743,7 @@ const generateApi = async (params) => {
1736
1743
  namespace,
1737
1744
  groupNames: []
1738
1745
  },
1739
- relativePathZodSchemas: hasZodSchemasFile ? "./schemas" : null
1746
+ relativePathZodSchemas: hasZodContractsFile ? "./contracts" : null
1740
1747
  });
1741
1748
  reservedDataContractNames.forEach((name) => {
1742
1749
  reservedDataContractNamesMap.set(
@@ -1809,6 +1816,7 @@ const generateApi = async (params) => {
1809
1816
  ...baseTmplParams,
1810
1817
  route,
1811
1818
  relativePathDataContracts: "../../data-contracts",
1819
+ relativePathZodSchemas: hasZodContractsFile ? "../../contracts" : null,
1812
1820
  groupName,
1813
1821
  metaInfo: params.noMetaInfo ? null : {
1814
1822
  namespace,
@@ -1851,6 +1859,7 @@ const generateApi = async (params) => {
1851
1859
  ...baseTmplParams,
1852
1860
  routes,
1853
1861
  relativePathDataContracts: "../data-contracts",
1862
+ relativePathZodSchemas: hasZodContractsFile ? "../contracts" : null,
1854
1863
  groupName,
1855
1864
  metaInfo: params.noMetaInfo ? null : {
1856
1865
  namespace,
@@ -1932,20 +1941,21 @@ export * as ${exportGroupName} from './endpoints';
1932
1941
  withPrefix: false,
1933
1942
  content: dataContractsContent
1934
1943
  });
1935
- if (hasZodSchemasFile && componentsSchemasForZod) {
1936
- const schemasTsContent = buildCentralZodSchemasFile({
1944
+ if (hasZodContractsFile && componentsSchemasForZod) {
1945
+ const contractsTsContent = buildCentralZodContractsFile({
1937
1946
  componentsSchemas: componentsSchemasForZod,
1938
- utils
1947
+ utils,
1948
+ contractSuffix: zodContractSuffix
1939
1949
  });
1940
- const formattedSchemasContent = await generated.formatTSContent(
1950
+ const formattedContractsContent = await generated.formatTSContent(
1941
1951
  `${LINTERS_IGNORE}
1942
- ${schemasTsContent}`
1952
+ ${contractsTsContent}`
1943
1953
  );
1944
1954
  codegenFs.createFile({
1945
1955
  path: paths.outputDir,
1946
- fileName: "schemas.ts",
1956
+ fileName: "contracts.ts",
1947
1957
  withPrefix: false,
1948
- content: formattedSchemasContent
1958
+ content: formattedContractsContent
1949
1959
  });
1950
1960
  }
1951
1961
  if (metaInfo) {
@@ -1968,7 +1978,7 @@ ${schemasTsContent}`
1968
1978
  ...baseTmplParams,
1969
1979
  collectedExportFiles: collectedExportFilesFromIndexFile,
1970
1980
  metaInfo,
1971
- exportSchemas: hasZodSchemasFile
1981
+ exportSchemas: hasZodContractsFile
1972
1982
  })
1973
1983
  });
1974
1984
  if (shouldGenerateBarrelFiles) {
@@ -1991,7 +2001,7 @@ export * as ${namespace} from './__exports';
1991
2001
  ...baseTmplParams,
1992
2002
  collectedExportFiles: collectedExportFilesFromIndexFile,
1993
2003
  metaInfo,
1994
- exportSchemas: hasZodSchemasFile
2004
+ exportSchemas: hasZodContractsFile
1995
2005
  })
1996
2006
  });
1997
2007
  }