mobx-tanstack-query-api 0.40.1 → 0.41.1

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.js CHANGED
@@ -216,6 +216,15 @@ const createShortModelType = (shortModelType) => {
216
216
  description: shortModelType.description || ""
217
217
  };
218
218
  };
219
+ const DEFAULT_DATA_CONTRACT_TYPE_SUFFIX = "DC";
220
+ const DEFAULT_ZOD_CONTRACT_SUFFIX = "";
221
+ const DEFAULT_ENDPOINT_ZOD_CONTRACT_SUFFIX = "Contract";
222
+ function getZodContractSuffix(zodContracts) {
223
+ return (typeof zodContracts === "object" && zodContracts !== null && typeof zodContracts.suffix === "string" ? zodContracts.suffix : void 0) ?? DEFAULT_ZOD_CONTRACT_SUFFIX;
224
+ }
225
+ function getEndpointZodContractSuffix(zodContracts) {
226
+ return (typeof zodContracts === "object" && zodContracts !== null && typeof zodContracts.suffix === "string" ? zodContracts.suffix : void 0) ?? DEFAULT_ENDPOINT_ZOD_CONTRACT_SUFFIX;
227
+ }
219
228
  const REF_PREFIX = "#/components/schemas/";
220
229
  const REF_PREFIX_PARAMS = "#/components/parameters/";
221
230
  function parseRef(ref) {
@@ -244,7 +253,7 @@ function getResponseSchemaKeyFromOperation(rawOperation) {
244
253
  if (typeof ref !== "string") return null;
245
254
  return parseRef(ref);
246
255
  }
247
- function typeNameToSchemaKey(typeName, typeSuffix = "DC") {
256
+ function typeNameToSchemaKey(typeName, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX) {
248
257
  const t = typeName.trim();
249
258
  if (typeSuffix && t.endsWith(typeSuffix))
250
259
  return t.slice(0, -typeSuffix.length);
@@ -267,14 +276,14 @@ function schemaToNumber(schema) {
267
276
  if (schema.maximum != null) n += `.max(${schema.maximum})`;
268
277
  return n;
269
278
  }
270
- function schemaToArray(schema, schemas, schemaKeyToVarName2, visited) {
271
- const items = schema.items ? schemaToZodExpr(schema.items, schemas, schemaKeyToVarName2, visited) : "z.any()";
279
+ function schemaToArray(schema, schemas, schemaKeyToVarName, visited) {
280
+ const items = schema.items ? schemaToZodExpr(schema.items, schemas, schemaKeyToVarName, visited) : "z.any()";
272
281
  let a = `z.array(${items})`;
273
282
  if (schema.minItems != null) a += `.min(${schema.minItems})`;
274
283
  if (schema.maxItems != null) a += `.max(${schema.maxItems})`;
275
284
  return a;
276
285
  }
277
- function schemaToObject(schema, schemas, schemaKeyToVarName2, visited) {
286
+ function schemaToObject(schema, schemas, schemaKeyToVarName, visited) {
278
287
  if (schema.properties && Object.keys(schema.properties).length > 0) {
279
288
  const required = new Set(schema.required ?? []);
280
289
  const entries = Object.entries(schema.properties).map(
@@ -282,7 +291,7 @@ function schemaToObject(schema, schemas, schemaKeyToVarName2, visited) {
282
291
  const expr = schemaToZodExpr(
283
292
  propSchema,
284
293
  schemas,
285
- schemaKeyToVarName2,
294
+ schemaKeyToVarName,
286
295
  visited
287
296
  );
288
297
  const optional = !required.has(propName);
@@ -300,26 +309,26 @@ ${entries.join(",\n")}
300
309
  const value = schemaToZodExpr(
301
310
  schema.additionalProperties,
302
311
  schemas,
303
- schemaKeyToVarName2,
312
+ schemaKeyToVarName,
304
313
  visited
305
314
  );
306
315
  return `z.record(z.string(), ${value})`;
307
316
  }
308
317
  return "z.record(z.string(), z.any())";
309
318
  }
310
- function schemaToZodExpr(schema, schemas, schemaKeyToVarName2, visited) {
319
+ function schemaToZodExpr(schema, schemas, schemaKeyToVarName, visited) {
311
320
  if (!schema) return "z.any()";
312
321
  if (schema.$ref) {
313
322
  const key = parseRef(schema.$ref);
314
323
  if (key && key in schemas) {
315
324
  const isCycle = visited.has(key);
316
- return isCycle ? `z.lazy((): z.ZodTypeAny => ${schemaKeyToVarName2(key)})` : `z.lazy(() => ${schemaKeyToVarName2(key)})`;
325
+ return isCycle ? `z.lazy((): z.ZodTypeAny => ${schemaKeyToVarName(key)})` : `z.lazy(() => ${schemaKeyToVarName(key)})`;
317
326
  }
318
327
  return "z.any()";
319
328
  }
320
329
  if (schema.allOf && schema.allOf.length > 0) {
321
330
  const parts = schema.allOf.map(
322
- (part) => schemaToZodExpr(part, schemas, schemaKeyToVarName2, visited)
331
+ (part) => schemaToZodExpr(part, schemas, schemaKeyToVarName, visited)
323
332
  );
324
333
  const base2 = parts.length === 1 ? parts[0] : parts.reduce((acc, p) => `z.intersection(${acc}, ${p})`);
325
334
  return schema.nullable === true ? `${base2}.nullable()` : base2;
@@ -338,10 +347,10 @@ function schemaToZodExpr(schema, schemas, schemaKeyToVarName2, visited) {
338
347
  base = "z.boolean()";
339
348
  break;
340
349
  case "array":
341
- base = schemaToArray(schema, schemas, schemaKeyToVarName2, visited);
350
+ base = schemaToArray(schema, schemas, schemaKeyToVarName, visited);
342
351
  break;
343
352
  case "object":
344
- base = schemaToObject(schema, schemas, schemaKeyToVarName2, visited);
353
+ base = schemaToObject(schema, schemas, schemaKeyToVarName, visited);
345
354
  break;
346
355
  default:
347
356
  base = "z.any()";
@@ -371,9 +380,16 @@ function collectRefs(schema, schemas, out) {
371
380
  collectRefs(schema.additionalProperties, schemas, out);
372
381
  }
373
382
  }
374
- function schemaKeyToVarName(key, utils) {
383
+ function dataContractTypeNameToZodVarName(typeName, utils, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
375
384
  const _ = utils._;
376
- return `${_.camelCase(key)}Schema`;
385
+ return `${_.camelCase(typeName)}${contractSuffix}`;
386
+ }
387
+ function schemaKeyToContractVarName(key, utils, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX) {
388
+ return dataContractTypeNameToZodVarName(
389
+ `${key}${typeSuffix}`,
390
+ utils,
391
+ contractSuffix
392
+ );
377
393
  }
378
394
  function resolveQueryParameters(operation, componentsParameters) {
379
395
  const list = [];
@@ -402,13 +418,13 @@ function resolveQueryParameters(operation, componentsParameters) {
402
418
  }
403
419
  return list;
404
420
  }
405
- function queryParamsToZodObject(queryParams, schemas, schemaKeyToVarName2) {
421
+ function queryParamsToZodObject(queryParams, schemas, schemaKeyToContractVarName2) {
406
422
  if (queryParams.length === 0) return "z.object({})";
407
423
  const entries = queryParams.map(({ name, required, schema }) => {
408
424
  const expr = schemaToZodExpr(
409
425
  schema,
410
426
  schemas,
411
- schemaKeyToVarName2,
427
+ schemaKeyToContractVarName2,
412
428
  /* @__PURE__ */ new Set()
413
429
  );
414
430
  const field = required ? expr : `${expr}.optional()`;
@@ -418,32 +434,37 @@ function queryParamsToZodObject(queryParams, schemas, schemaKeyToVarName2) {
418
434
  ${entries.join(",\n")}
419
435
  })`;
420
436
  }
421
- function generateAuxiliarySchemas(schemaKeys, schemas, schemaKeyToVarNameFn, visited) {
437
+ function generateAuxiliarySchemas(schemaKeys, schemas, schemaKeyToContractVarNameFn, visited) {
422
438
  const lines = [];
423
439
  for (const key of schemaKeys) {
424
440
  if (visited.has(key)) continue;
425
441
  visited.add(key);
426
442
  const schema = schemas[key];
427
443
  if (!schema) continue;
428
- const varName = schemaKeyToVarNameFn(key);
444
+ const varName = schemaKeyToContractVarNameFn(key);
429
445
  const cyclePath = /* @__PURE__ */ new Set([key]);
430
446
  const expr = schemaToZodExpr(
431
447
  schema,
432
448
  schemas,
433
- schemaKeyToVarNameFn,
449
+ schemaKeyToContractVarNameFn,
434
450
  cyclePath
435
451
  );
436
452
  lines.push(`export const ${varName} = ${expr};`);
437
453
  }
438
454
  return lines;
439
455
  }
440
- function buildCentralZodSchemasFile(params) {
441
- const { componentsSchemas, utils } = params;
442
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
456
+ function buildCentralZodContractsFile(params) {
457
+ const {
458
+ componentsSchemas,
459
+ utils,
460
+ contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX,
461
+ typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX
462
+ } = params;
463
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
443
464
  const lines = generateAuxiliarySchemas(
444
465
  Object.keys(componentsSchemas),
445
466
  componentsSchemas,
446
- schemaKeyToVarNameFn,
467
+ schemaKeyToContractVarNameFn,
447
468
  /* @__PURE__ */ new Set()
448
469
  );
449
470
  return `import * as z from "zod";
@@ -465,7 +486,7 @@ function typeToZodSchemaFallback(typeStr) {
465
486
  if (t === "unknown") return "z.unknown()";
466
487
  return "z.any()";
467
488
  }
468
- function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix) {
489
+ function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
469
490
  const t = typeStr.trim();
470
491
  if (!schemas || Object.keys(schemas).length === 0) {
471
492
  return { expr: typeToZodSchemaFallback(t), refs: [] };
@@ -478,51 +499,49 @@ function typeToZodSchemaWithSchema(typeStr, schemas, utils, typeSuffix) {
478
499
  }
479
500
  const refs = /* @__PURE__ */ new Set();
480
501
  collectRefs(schema, schemas, refs);
481
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
502
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
482
503
  const expr = schemaToZodExpr(
483
504
  schema,
484
505
  schemas,
485
- schemaKeyToVarNameFn,
506
+ schemaKeyToContractVarNameFn,
486
507
  /* @__PURE__ */ new Set()
487
508
  );
488
509
  return { expr, refs: [...refs] };
489
510
  }
490
- function schemaKeyToZod(schemaKey, schemas, utils) {
511
+ function schemaKeyToZod(schemaKey, schemas, utils, typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX, contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX) {
491
512
  const schema = schemas[schemaKey];
492
513
  if (!schema) return { expr: "z.any()", refs: [] };
493
514
  const refs = /* @__PURE__ */ new Set();
494
515
  collectRefs(schema, schemas, refs);
495
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
516
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
496
517
  const expr = schemaToZodExpr(
497
518
  schema,
498
519
  schemas,
499
- schemaKeyToVarNameFn,
520
+ schemaKeyToContractVarNameFn,
500
521
  /* @__PURE__ */ new Set()
501
522
  );
502
523
  return { expr, refs: [...refs] };
503
524
  }
504
525
  function buildEndpointZodContractsCode(params) {
505
526
  const {
506
- routeNameUsage,
507
527
  inputParams,
508
528
  responseDataTypeName,
509
- contractsVarName,
529
+ contractVarName,
510
530
  utils,
531
+ contractSuffix = DEFAULT_ZOD_CONTRACT_SUFFIX,
511
532
  componentsSchemas = null,
512
- typeSuffix = "DC",
533
+ typeSuffix = DEFAULT_DATA_CONTRACT_TYPE_SUFFIX,
513
534
  responseSchemaKey,
514
535
  useExternalZodSchemas = false,
515
536
  openApiOperation = null,
516
537
  openApiComponentsParameters = null,
517
538
  queryParamName = "query"
518
539
  } = params;
519
- const _ = utils._;
520
- const paramsSchemaName = `${_.camelCase(routeNameUsage)}ParamsSchema`;
521
- const dataSchemaName = `${_.camelCase(routeNameUsage)}DataSchema`;
540
+ utils._;
522
541
  const allAuxiliaryKeys = /* @__PURE__ */ new Set();
523
542
  const paramParts = [];
524
543
  const resolvedQueryParams = openApiOperation && (openApiComponentsParameters || openApiOperation.parameters?.length) ? resolveQueryParameters(openApiOperation, openApiComponentsParameters) : [];
525
- const schemaKeyToVarNameFn = (key) => schemaKeyToVarName(key, utils);
544
+ const schemaKeyToContractVarNameFn = (key) => schemaKeyToContractVarName(key, utils, contractSuffix, typeSuffix);
526
545
  for (const p of inputParams) {
527
546
  let expr;
528
547
  let refKeys = [];
@@ -530,14 +549,15 @@ function buildEndpointZodContractsCode(params) {
530
549
  expr = queryParamsToZodObject(
531
550
  resolvedQueryParams,
532
551
  componentsSchemas,
533
- schemaKeyToVarNameFn
552
+ schemaKeyToContractVarNameFn
534
553
  );
535
554
  } else {
536
555
  const result = typeToZodSchemaWithSchema(
537
556
  p.type,
538
557
  componentsSchemas,
539
558
  utils,
540
- typeSuffix
559
+ typeSuffix,
560
+ contractSuffix
541
561
  );
542
562
  expr = result.expr;
543
563
  refKeys = result.refs;
@@ -546,11 +566,18 @@ function buildEndpointZodContractsCode(params) {
546
566
  const schemaWithOptional = p.optional ? `${expr}.optional()` : expr;
547
567
  paramParts.push(`${p.name}: ${schemaWithOptional}`);
548
568
  }
549
- const responseResult = responseSchemaKey && componentsSchemas && responseSchemaKey in componentsSchemas ? schemaKeyToZod(responseSchemaKey, componentsSchemas, utils) : typeToZodSchemaWithSchema(
569
+ const responseResult = responseSchemaKey && componentsSchemas && responseSchemaKey in componentsSchemas ? schemaKeyToZod(
570
+ responseSchemaKey,
571
+ componentsSchemas,
572
+ utils,
573
+ typeSuffix,
574
+ contractSuffix
575
+ ) : typeToZodSchemaWithSchema(
550
576
  responseDataTypeName,
551
577
  componentsSchemas,
552
578
  utils,
553
- typeSuffix
579
+ typeSuffix,
580
+ contractSuffix
554
581
  );
555
582
  const useDataSchemaFromCentral = useExternalZodSchemas && responseSchemaKey && componentsSchemas && responseSchemaKey in componentsSchemas;
556
583
  if (useDataSchemaFromCentral) {
@@ -558,31 +585,27 @@ function buildEndpointZodContractsCode(params) {
558
585
  } else {
559
586
  for (const k of responseResult.refs) allAuxiliaryKeys.add(k);
560
587
  }
561
- const zodSchemaImportNames = useExternalZodSchemas && allAuxiliaryKeys.size > 0 ? [...allAuxiliaryKeys].map(schemaKeyToVarNameFn) : [];
588
+ const zodContractImportNames = useExternalZodSchemas && allAuxiliaryKeys.size > 0 ? [...allAuxiliaryKeys].map(schemaKeyToContractVarNameFn) : [];
562
589
  const allAuxiliary = useExternalZodSchemas ? [] : generateAuxiliarySchemas(
563
590
  [...allAuxiliaryKeys],
564
591
  componentsSchemas ?? {},
565
- schemaKeyToVarNameFn,
592
+ schemaKeyToContractVarNameFn,
566
593
  /* @__PURE__ */ new Set()
567
594
  );
568
- const paramsFields = paramParts.join(",\n ");
569
- const paramsSchemaCode = `export const ${paramsSchemaName} = z.object({
570
- ${paramsFields},
571
- });`;
572
- const dataSchemaCode = useDataSchemaFromCentral ? `export const ${dataSchemaName} = ${schemaKeyToVarNameFn(responseSchemaKey)};` : `export const ${dataSchemaName} = ${responseResult.expr};`;
573
- const contractsCode = `export const ${contractsVarName} = {
574
- params: ${paramsSchemaName},
575
- data: ${dataSchemaName},
595
+ const paramsFields = paramParts.join(",\n ");
596
+ const paramsSchemaExpr = `z.object({
597
+ ${paramsFields},
598
+ })`;
599
+ const dataSchemaExpr = useDataSchemaFromCentral ? schemaKeyToContractVarNameFn(responseSchemaKey) : responseResult.expr;
600
+ const contractsCode = `export const ${contractVarName} = {
601
+ params: ${paramsSchemaExpr},
602
+ data: ${dataSchemaExpr},
576
603
  };`;
577
604
  const auxiliaryBlock = allAuxiliary.length > 0 ? `${allAuxiliary.join("\n\n")}
578
605
 
579
606
  ` : "";
580
- const content = `${auxiliaryBlock}${paramsSchemaCode}
581
-
582
- ${dataSchemaCode}
583
-
584
- ${contractsCode}`;
585
- return { content, zodSchemaImportNames };
607
+ const content = `${auxiliaryBlock}${contractsCode}`;
608
+ return { content, zodContractImportNames };
586
609
  }
587
610
  const formatGroupNameEnumKey = (groupName, { _ }) => _.upperFirst(_.camelCase(groupName));
588
611
  const formatTagNameEnumKey = (tagName, utils) => formatGroupNameEnumKey(tagName, utils);
@@ -742,10 +765,8 @@ const newEndpointTmpl = ({
742
765
  }) => {
743
766
  const zodContractsIsObject = typeof zodContracts === "object" && zodContracts !== null;
744
767
  const hasZodContracts = zodContracts === true || zodContractsIsObject;
745
- const validateOpt = zodContractsIsObject ? zodContracts.validate : zodContracts === true ? true : void 0;
746
- const throwOpt = zodContractsIsObject ? zodContracts.throw : void 0;
747
- const validateOptObj = validateOpt != null && typeof validateOpt === "object" && !Array.isArray(validateOpt) ? validateOpt : null;
748
- const throwOptObj = throwOpt != null && typeof throwOpt === "object" && !Array.isArray(throwOpt) ? throwOpt : null;
768
+ const sharedContractSuffix = getZodContractSuffix(zodContracts);
769
+ const endpointContractSuffix = getEndpointZodContractSuffix(zodContracts);
749
770
  const { _ } = utils;
750
771
  const positiveResponseTypes = route.raw.responsesTypes?.filter(
751
772
  (it) => +it.status >= 200 && +it.status < 300 && (!it.typeData || filterTypes(it.typeData))
@@ -859,7 +880,24 @@ const newEndpointTmpl = ({
859
880
  });
860
881
  const isAllowedInputType = filterTypes(requestInputTypeDc);
861
882
  const defaultOkResponseType = positiveResponseTypes?.[0]?.type ?? "unknown";
862
- const contractsVarName = hasZodContracts ? `${_.camelCase(route.routeName.usage)}Contracts` : null;
883
+ const contractVarName = hasZodContracts ? `${_.camelCase(route.routeName.usage)}${endpointContractSuffix}` : null;
884
+ const routeInfoForContracts = contractVarName != null ? {
885
+ operationId: raw.operationId ?? "",
886
+ path: path2,
887
+ method,
888
+ contractName: contractVarName
889
+ } : null;
890
+ const resolveZodContractsMaybeFn = (value) => {
891
+ if (typeof value === "function" && routeInfoForContracts != null) {
892
+ return value(routeInfoForContracts.contractName, routeInfoForContracts);
893
+ }
894
+ return value;
895
+ };
896
+ const validateOpt = zodContractsIsObject ? resolveZodContractsMaybeFn(zodContracts.validate) : zodContracts === true ? true : void 0;
897
+ const throwOpt = zodContractsIsObject ? resolveZodContractsMaybeFn(zodContracts.throw) : void 0;
898
+ const isRuntimeContractsRuleObject = (value) => value != null && typeof value === "object" && !Array.isArray(value);
899
+ const validateOptObj = isRuntimeContractsRuleObject(validateOpt) ? validateOpt : null;
900
+ const throwOptObj = isRuntimeContractsRuleObject(throwOpt) ? throwOpt : null;
863
901
  const swaggerSchema = configuration.config?.swaggerSchema ?? configuration?.swaggerSchema;
864
902
  const componentsSchemas = swaggerSchema?.components?.schemas;
865
903
  let operationFromSpec = null;
@@ -885,7 +923,10 @@ const newEndpointTmpl = ({
885
923
  (m) => m.name === defaultOkResponseType
886
924
  );
887
925
  if (aliasType?.typeIdentifier === "type" && typeof aliasType.content === "string" && /^[A-Za-z0-9_]+$/.test(aliasType.content.trim())) {
888
- const resolved = typeNameToSchemaKey(aliasType.content.trim(), "DC");
926
+ const resolved = typeNameToSchemaKey(
927
+ aliasType.content.trim(),
928
+ DEFAULT_DATA_CONTRACT_TYPE_SUFFIX
929
+ );
889
930
  if (resolved in componentsSchemas) responseSchemaKey = resolved;
890
931
  }
891
932
  }
@@ -896,46 +937,36 @@ const newEndpointTmpl = ({
896
937
  if (candidate in componentsSchemas) responseSchemaKey = candidate;
897
938
  }
898
939
  }
899
- const contractsCode = hasZodContracts && contractsVarName ? buildEndpointZodContractsCode({
940
+ const contractsCode = hasZodContracts && contractVarName ? buildEndpointZodContractsCode({
900
941
  routeNameUsage: route.routeName.usage,
901
942
  inputParams,
902
943
  responseDataTypeName: defaultOkResponseType,
903
- contractsVarName,
944
+ contractVarName,
904
945
  utils,
905
946
  componentsSchemas: componentsSchemas ?? void 0,
906
- typeSuffix: "DC",
947
+ typeSuffix: DEFAULT_DATA_CONTRACT_TYPE_SUFFIX,
907
948
  responseSchemaKey: responseSchemaKey ?? void 0,
908
949
  useExternalZodSchemas: Boolean(relativePathZodSchemas),
950
+ contractSuffix: sharedContractSuffix,
909
951
  openApiOperation: operationFromSpec ?? void 0,
910
952
  openApiComponentsParameters: swaggerSchema?.components?.parameters ?? void 0,
911
953
  queryParamName: queryName
912
954
  }) : null;
913
- const appendRuleOpt = zodContractsIsObject && zodContracts.appendRule != null ? zodContracts.appendRule : null;
914
- const routeInfoForAppend = contractsVarName != null ? {
915
- operationId: raw.operationId ?? "",
916
- path: path2,
917
- method,
918
- contractName: contractsVarName
919
- } : null;
920
- const contractsLine = (() => {
921
- if (contractsVarName == null) return "";
955
+ const appendRuleOpt = zodContractsIsObject && zodContracts.appendRule != null ? resolveZodContractsMaybeFn(zodContracts.appendRule) : null;
956
+ const contractLine = (() => {
957
+ if (contractVarName == null) return "";
922
958
  if (typeof appendRuleOpt === "string")
923
- return `contracts: ${appendRuleOpt} ? ${contractsVarName} : undefined,`;
924
- if (typeof appendRuleOpt === "function" && routeInfoForAppend) {
925
- const include = appendRuleOpt(
926
- routeInfoForAppend.contractName,
927
- routeInfoForAppend
928
- );
929
- return include ? `contracts: ${contractsVarName},` : "contracts: undefined,";
930
- }
931
- return `contracts: ${contractsVarName},`;
959
+ return `contract: ${appendRuleOpt} ? ${contractVarName} : undefined,`;
960
+ if (appendRuleOpt === false) return "contract: undefined,";
961
+ if (appendRuleOpt === true) return `contract: ${contractVarName},`;
962
+ return `contract: ${contractVarName},`;
932
963
  })();
933
- const validateContractsLine = (() => {
964
+ const validateContractLine = (() => {
934
965
  if (validateOpt === void 0) return "";
935
966
  if (typeof validateOpt === "string")
936
- return `validateContracts: ${validateOpt},`;
967
+ return `validateContract: ${validateOpt},`;
937
968
  if (typeof validateOpt === "boolean")
938
- return `validateContracts: ${validateOpt},`;
969
+ return `validateContract: ${validateOpt},`;
939
970
  if (validateOptObj !== null) {
940
971
  const parts = [];
941
972
  if (validateOptObj.params !== void 0)
@@ -946,7 +977,7 @@ const newEndpointTmpl = ({
946
977
  parts.push(
947
978
  `data: ${typeof validateOptObj.data === "string" ? validateOptObj.data : validateOptObj.data}`
948
979
  );
949
- return parts.length > 0 ? `validateContracts: { ${parts.join(", ")} },` : "";
980
+ return parts.length > 0 ? `validateContract: { ${parts.join(", ")} },` : "";
950
981
  }
951
982
  return "";
952
983
  })();
@@ -968,7 +999,7 @@ const newEndpointTmpl = ({
968
999
  reservedDataContractNames,
969
1000
  localModelTypes: isAllowedInputType ? [requestInputTypeDc] : [],
970
1001
  contractsCode: contractsCode ?? void 0,
971
- contractsVarName: contractsVarName ?? void 0,
1002
+ contractVarName: contractVarName ?? void 0,
972
1003
  content: `
973
1004
  new ${importFileParams.endpoint.exportName}<
974
1005
  ${getHttpRequestGenerics()},
@@ -1001,8 +1032,8 @@ new ${importFileParams.endpoint.exportName}<
1001
1032
  ${groupName ? `group: ${metaInfo ? `Group.${formatGroupNameEnumKey(groupName, utils)}` : `"${groupName}"`},` : ""}
1002
1033
  ${metaInfo?.namespace ? `namespace,` : ""}
1003
1034
  meta: ${requestInfoMeta?.tmplData ?? "{} as any"},
1004
- ${contractsLine}
1005
- ${validateContractsLine}
1035
+ ${contractLine}
1036
+ ${validateContractLine}
1006
1037
  ${throwContractsLine}
1007
1038
  },
1008
1039
  ${importFileParams.queryClient.exportName},
@@ -1052,17 +1083,17 @@ const allEndpointPerFileTmpl = async (params) => {
1052
1083
  const hasAnyZodContracts = newEndpointTemplates.some(
1053
1084
  (t) => t.contractsCode != null
1054
1085
  );
1055
- const allZodSchemaImportNames = /* @__PURE__ */ new Set();
1086
+ const allZodContractImportNames = /* @__PURE__ */ new Set();
1056
1087
  newEndpointTemplates.forEach((t) => {
1057
1088
  const c = t.contractsCode;
1058
- if (c != null && typeof c === "object" && c.zodSchemaImportNames?.length) {
1059
- for (const n of c.zodSchemaImportNames) {
1060
- allZodSchemaImportNames.add(n);
1089
+ if (c != null && typeof c === "object" && c.zodContractImportNames?.length) {
1090
+ for (const n of c.zodContractImportNames) {
1091
+ allZodContractImportNames.add(n);
1061
1092
  }
1062
1093
  }
1063
1094
  });
1064
1095
  const zodImportLine = hasAnyZodContracts ? 'import * as z from "zod";' : "";
1065
- const zodSchemasImportLine = allZodSchemaImportNames.size && relativePathZodSchemas ? `import { ${[...allZodSchemaImportNames].sort().join(", ")} } from "${relativePathZodSchemas}";` : "";
1096
+ const zodSchemasImportLine = allZodContractImportNames.size && relativePathZodSchemas ? `import { ${[...allZodContractImportNames].sort().join(", ")} } from "${relativePathZodSchemas}";` : "";
1066
1097
  const endpointTemplates = await Promise.all(
1067
1098
  newEndpointTemplates.map(
1068
1099
  async ({
@@ -1166,7 +1197,7 @@ const allExportsTmpl = async ({
1166
1197
  }) => {
1167
1198
  return await formatTSContent(`${LINTERS_IGNORE}
1168
1199
  export * from './data-contracts';
1169
- ${exportSchemas ? " export * from './schemas';\n " : ""}${collectedExportFiles.map((fileName) => `export * from './${fileName}';`).join("\n")}
1200
+ ${exportSchemas ? " export * from './contracts';\n " : ""}${collectedExportFiles.map((fileName) => `export * from './${fileName}';`).join("\n")}
1170
1201
  ${metaInfo ? 'export * from "./meta-info";' : ""}
1171
1202
  `);
1172
1203
  };
@@ -1248,7 +1279,7 @@ const endpointPerFileTmpl = async (params) => {
1248
1279
  const dataContractImportToken = "/*__DATA_CONTRACT_IMPORTS__*/";
1249
1280
  const contractsResult = contractsCode != null && typeof contractsCode === "object" ? contractsCode : null;
1250
1281
  const zodImportLine = contractsResult != null ? 'import * as z from "zod";' : "";
1251
- const zodSchemasImportLine = contractsResult?.zodSchemaImportNames?.length && relativePathZodSchemas ? `import { ${contractsResult.zodSchemaImportNames.join(", ")} } from "${relativePathZodSchemas}";` : "";
1282
+ const zodSchemasImportLine = contractsResult?.zodContractImportNames?.length && relativePathZodSchemas ? `import { ${contractsResult.zodContractImportNames.join(", ")} } from "${relativePathZodSchemas}";` : "";
1252
1283
  const contractsBlock = contractsResult != null ? `
1253
1284
 
1254
1285
  ${contractsResult.content}
@@ -1493,7 +1524,7 @@ const generateApi = async (params) => {
1493
1524
  cleanOutput: params.cleanOutput ?? true,
1494
1525
  modular: true,
1495
1526
  patch: true,
1496
- typeSuffix: "DC",
1527
+ typeSuffix: DEFAULT_DATA_CONTRACT_TYPE_SUFFIX,
1497
1528
  disableStrictSSL: false,
1498
1529
  singleHttpClient: true,
1499
1530
  extractRequestBody: true,
@@ -1658,7 +1689,8 @@ const generateApi = async (params) => {
1658
1689
  };
1659
1690
  const reservedDataContractNamesMap = /* @__PURE__ */ new Map();
1660
1691
  const componentsSchemasForZod = generated.configuration.config?.swaggerSchema?.components?.schemas ?? generated.configuration.swaggerSchema?.components?.schemas;
1661
- const hasZodSchemasFile = (params.zodContracts === true || typeof params.zodContracts === "object" && params.zodContracts != null) && componentsSchemasForZod && typeof componentsSchemasForZod === "object" && Object.keys(componentsSchemasForZod).length > 0;
1692
+ const zodContractSuffix = getZodContractSuffix(params.zodContracts);
1693
+ const hasZodContractsFile = (params.zodContracts === true || typeof params.zodContracts === "object" && params.zodContracts != null) && componentsSchemasForZod && typeof componentsSchemasForZod === "object" && Object.keys(componentsSchemasForZod).length > 0;
1662
1694
  const collectedExportFilesFromIndexFile = [];
1663
1695
  const groupsMap = /* @__PURE__ */ new Map();
1664
1696
  const nonEmptyGroups = /* @__PURE__ */ new Set();
@@ -1681,7 +1713,7 @@ const generateApi = async (params) => {
1681
1713
  groupNames: [],
1682
1714
  namespace
1683
1715
  },
1684
- relativePathZodSchemas: hasZodSchemasFile ? "../schemas" : null
1716
+ relativePathZodSchemas: hasZodContractsFile ? "../contracts" : null
1685
1717
  });
1686
1718
  if (Array.isArray(route.raw.tags)) {
1687
1719
  route.raw.tags.forEach((tag) => {
@@ -1726,7 +1758,7 @@ const generateApi = async (params) => {
1726
1758
  namespace,
1727
1759
  groupNames: []
1728
1760
  },
1729
- relativePathZodSchemas: hasZodSchemasFile ? "./schemas" : null
1761
+ relativePathZodSchemas: hasZodContractsFile ? "./contracts" : null
1730
1762
  });
1731
1763
  reservedDataContractNames.forEach((name) => {
1732
1764
  reservedDataContractNamesMap.set(
@@ -1799,6 +1831,7 @@ const generateApi = async (params) => {
1799
1831
  ...baseTmplParams,
1800
1832
  route,
1801
1833
  relativePathDataContracts: "../../data-contracts",
1834
+ relativePathZodSchemas: hasZodContractsFile ? "../../contracts" : null,
1802
1835
  groupName,
1803
1836
  metaInfo: params.noMetaInfo ? null : {
1804
1837
  namespace,
@@ -1841,6 +1874,7 @@ const generateApi = async (params) => {
1841
1874
  ...baseTmplParams,
1842
1875
  routes,
1843
1876
  relativePathDataContracts: "../data-contracts",
1877
+ relativePathZodSchemas: hasZodContractsFile ? "../contracts" : null,
1844
1878
  groupName,
1845
1879
  metaInfo: params.noMetaInfo ? null : {
1846
1880
  namespace,
@@ -1922,20 +1956,21 @@ export * as ${exportGroupName} from './endpoints';
1922
1956
  withPrefix: false,
1923
1957
  content: dataContractsContent
1924
1958
  });
1925
- if (hasZodSchemasFile && componentsSchemasForZod) {
1926
- const schemasTsContent = buildCentralZodSchemasFile({
1959
+ if (hasZodContractsFile && componentsSchemasForZod) {
1960
+ const contractsTsContent = buildCentralZodContractsFile({
1927
1961
  componentsSchemas: componentsSchemasForZod,
1928
- utils
1962
+ utils,
1963
+ contractSuffix: zodContractSuffix
1929
1964
  });
1930
- const formattedSchemasContent = await generated.formatTSContent(
1965
+ const formattedContractsContent = await generated.formatTSContent(
1931
1966
  `${LINTERS_IGNORE}
1932
- ${schemasTsContent}`
1967
+ ${contractsTsContent}`
1933
1968
  );
1934
1969
  codegenFs.createFile({
1935
1970
  path: paths.outputDir,
1936
- fileName: "schemas.ts",
1971
+ fileName: "contracts.ts",
1937
1972
  withPrefix: false,
1938
- content: formattedSchemasContent
1973
+ content: formattedContractsContent
1939
1974
  });
1940
1975
  }
1941
1976
  if (metaInfo) {
@@ -1958,7 +1993,7 @@ ${schemasTsContent}`
1958
1993
  ...baseTmplParams,
1959
1994
  collectedExportFiles: collectedExportFilesFromIndexFile,
1960
1995
  metaInfo,
1961
- exportSchemas: hasZodSchemasFile
1996
+ exportSchemas: hasZodContractsFile
1962
1997
  })
1963
1998
  });
1964
1999
  if (shouldGenerateBarrelFiles) {
@@ -1981,7 +2016,7 @@ export * as ${namespace} from './__exports';
1981
2016
  ...baseTmplParams,
1982
2017
  collectedExportFiles: collectedExportFilesFromIndexFile,
1983
2018
  metaInfo,
1984
- exportSchemas: hasZodSchemasFile
2019
+ exportSchemas: hasZodContractsFile
1985
2020
  })
1986
2021
  });
1987
2022
  }