zod 4.2.0-canary.20251207T223211 → 4.2.0-canary.20251213T203150

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.
Files changed (39) hide show
  1. package/package.json +1 -1
  2. package/src/v4/classic/schemas.ts +97 -5
  3. package/src/v4/classic/tests/json.test.ts +4 -3
  4. package/src/v4/classic/tests/standard-schema.test.ts +77 -0
  5. package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  6. package/src/v4/classic/tests/to-json-schema.test.ts +66 -30
  7. package/src/v4/core/index.ts +2 -0
  8. package/src/v4/core/json-schema-generator.ts +124 -0
  9. package/src/v4/core/json-schema-processors.ts +630 -0
  10. package/src/v4/core/schemas.ts +8 -13
  11. package/src/v4/core/standard-schema.ts +114 -19
  12. package/src/v4/core/to-json-schema.ts +373 -827
  13. package/src/v4/mini/tests/standard-schema.test.ts +17 -0
  14. package/v4/classic/schemas.cjs +48 -0
  15. package/v4/classic/schemas.d.cts +35 -0
  16. package/v4/classic/schemas.d.ts +35 -0
  17. package/v4/classic/schemas.js +48 -0
  18. package/v4/core/index.cjs +5 -1
  19. package/v4/core/index.d.cts +2 -0
  20. package/v4/core/index.d.ts +2 -0
  21. package/v4/core/index.js +2 -0
  22. package/v4/core/json-schema-generator.cjs +99 -0
  23. package/v4/core/json-schema-generator.d.cts +64 -0
  24. package/v4/core/json-schema-generator.d.ts +64 -0
  25. package/v4/core/json-schema-generator.js +95 -0
  26. package/v4/core/json-schema-processors.cjs +617 -0
  27. package/v4/core/json-schema-processors.d.cts +49 -0
  28. package/v4/core/json-schema-processors.d.ts +49 -0
  29. package/v4/core/json-schema-processors.js +574 -0
  30. package/v4/core/schemas.cjs +0 -10
  31. package/v4/core/schemas.d.cts +4 -1
  32. package/v4/core/schemas.d.ts +4 -1
  33. package/v4/core/schemas.js +0 -10
  34. package/v4/core/standard-schema.d.cts +90 -19
  35. package/v4/core/standard-schema.d.ts +90 -19
  36. package/v4/core/to-json-schema.cjs +302 -793
  37. package/v4/core/to-json-schema.d.cts +56 -33
  38. package/v4/core/to-json-schema.d.ts +56 -33
  39. package/v4/core/to-json-schema.js +296 -791
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.2.0-canary.20251207T223211",
3
+ "version": "4.2.0-canary.20251213T203150",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -1,5 +1,8 @@
1
1
  import * as core from "../core/index.js";
2
2
  import { util } from "../core/index.js";
3
+ import * as processors from "../core/json-schema-processors.js";
4
+ import type { StandardSchemaWithJSONProps } from "../core/standard-schema.js";
5
+ import { createStandardJSONSchemaMethod, createToJSONSchemaMethod } from "../core/to-json-schema.js";
3
6
 
4
7
  import * as checks from "./checks.js";
5
8
  import * as iso from "./iso.js";
@@ -13,6 +16,7 @@ import * as parse from "./parse.js";
13
16
  ///////////////////////////////////////////
14
17
  ///////////////////////////////////////////
15
18
 
19
+ export type ZodStandardSchemaWithJSON<T> = StandardSchemaWithJSONProps<core.input<T>, core.output<T>>;
16
20
  export interface ZodType<
17
21
  out Output = unknown,
18
22
  out Input = unknown,
@@ -28,6 +32,10 @@ export interface ZodType<
28
32
  /** @deprecated Use `z.input<typeof schema>` instead. */
29
33
  _input: Internals["input"];
30
34
 
35
+ "~standard": ZodStandardSchemaWithJSON<this>;
36
+ /** Converts this schema to a JSON Schema representation. */
37
+ toJSONSchema(params?: core.ToJSONSchemaParams): core.ZodStandardJSONSchemaPayload<this>;
38
+
31
39
  // base methods
32
40
  check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this;
33
41
  clone(def?: Internals["def"], params?: { parent: boolean }): this;
@@ -139,6 +147,14 @@ export interface _ZodType<out Internals extends core.$ZodTypeInternals = core.$Z
139
147
 
140
148
  export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
141
149
  core.$ZodType.init(inst, def);
150
+ Object.assign(inst["~standard"], {
151
+ jsonSchema: {
152
+ input: createStandardJSONSchemaMethod(inst, "input"),
153
+ output: createStandardJSONSchemaMethod(inst, "output"),
154
+ },
155
+ });
156
+ inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
157
+
142
158
  inst.def = def;
143
159
  inst.type = def.type;
144
160
  Object.defineProperty(inst, "_def", { value: def });
@@ -260,6 +276,8 @@ export const _ZodString: core.$constructor<_ZodString> = /*@__PURE__*/ core.$con
260
276
  core.$ZodString.init(inst, def);
261
277
  ZodType.init(inst, def);
262
278
 
279
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.stringProcessor(inst, ctx, json, params);
280
+
263
281
  const bag = inst._zod.bag;
264
282
  inst.format = bag.format ?? null;
265
283
  inst.minLength = bag.minimum ?? null;
@@ -730,6 +748,7 @@ export interface ZodCustomStringFormat<Format extends string = string>
730
748
  extends ZodStringFormat<Format>,
731
749
  core.$ZodCustomStringFormat<Format> {
732
750
  _zod: core.$ZodCustomStringFormatInternals<Format>;
751
+ "~standard": ZodStandardSchemaWithJSON<this>;
733
752
  }
734
753
  export const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat> = /*@__PURE__*/ core.$constructor(
735
754
  "ZodCustomStringFormat",
@@ -810,6 +829,8 @@ export const ZodNumber: core.$constructor<ZodNumber> = /*@__PURE__*/ core.$const
810
829
 
811
830
  ZodType.init(inst, def);
812
831
 
832
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.numberProcessor(inst, ctx, json, params);
833
+
813
834
  inst.gt = (value, params) => inst.check(checks.gt(value, params));
814
835
  inst.gte = (value, params) => inst.check(checks.gte(value, params));
815
836
  inst.min = (value, params) => inst.check(checks.gte(value, params));
@@ -890,6 +911,7 @@ export interface ZodBoolean extends _ZodBoolean<core.$ZodBooleanInternals<boolea
890
911
  export const ZodBoolean: core.$constructor<ZodBoolean> = /*@__PURE__*/ core.$constructor("ZodBoolean", (inst, def) => {
891
912
  core.$ZodBoolean.init(inst, def);
892
913
  ZodType.init(inst, def);
914
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.booleanProcessor(inst, ctx, json, params);
893
915
  });
894
916
 
895
917
  export function boolean(params?: string | core.$ZodBooleanParams): ZodBoolean {
@@ -921,6 +943,7 @@ export interface ZodBigInt extends _ZodBigInt<core.$ZodBigIntInternals<bigint>>
921
943
  export const ZodBigInt: core.$constructor<ZodBigInt> = /*@__PURE__*/ core.$constructor("ZodBigInt", (inst, def) => {
922
944
  core.$ZodBigInt.init(inst, def);
923
945
  ZodType.init(inst, def);
946
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.bigintProcessor(inst, ctx, json, params);
924
947
 
925
948
  inst.gte = (value, params) => inst.check(checks.gte(value, params));
926
949
  inst.min = (value, params) => inst.check(checks.gte(value, params));
@@ -974,6 +997,7 @@ export interface ZodSymbol extends _ZodType<core.$ZodSymbolInternals> {}
974
997
  export const ZodSymbol: core.$constructor<ZodSymbol> = /*@__PURE__*/ core.$constructor("ZodSymbol", (inst, def) => {
975
998
  core.$ZodSymbol.init(inst, def);
976
999
  ZodType.init(inst, def);
1000
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.symbolProcessor(inst, ctx, json, params);
977
1001
  });
978
1002
 
979
1003
  export function symbol(params?: string | core.$ZodSymbolParams): ZodSymbol {
@@ -987,6 +1011,7 @@ export const ZodUndefined: core.$constructor<ZodUndefined> = /*@__PURE__*/ core.
987
1011
  (inst, def) => {
988
1012
  core.$ZodUndefined.init(inst, def);
989
1013
  ZodType.init(inst, def);
1014
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.undefinedProcessor(inst, ctx, json, params);
990
1015
  }
991
1016
  );
992
1017
 
@@ -1000,6 +1025,7 @@ export interface ZodNull extends _ZodType<core.$ZodNullInternals> {}
1000
1025
  export const ZodNull: core.$constructor<ZodNull> = /*@__PURE__*/ core.$constructor("ZodNull", (inst, def) => {
1001
1026
  core.$ZodNull.init(inst, def);
1002
1027
  ZodType.init(inst, def);
1028
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.nullProcessor(inst, ctx, json, params);
1003
1029
  });
1004
1030
 
1005
1031
  function _null(params?: string | core.$ZodNullParams): ZodNull {
@@ -1012,6 +1038,7 @@ export interface ZodAny extends _ZodType<core.$ZodAnyInternals> {}
1012
1038
  export const ZodAny: core.$constructor<ZodAny> = /*@__PURE__*/ core.$constructor("ZodAny", (inst, def) => {
1013
1039
  core.$ZodAny.init(inst, def);
1014
1040
  ZodType.init(inst, def);
1041
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.anyProcessor(inst, ctx, json, params);
1015
1042
  });
1016
1043
 
1017
1044
  export function any(): ZodAny {
@@ -1023,6 +1050,7 @@ export interface ZodUnknown extends _ZodType<core.$ZodUnknownInternals> {}
1023
1050
  export const ZodUnknown: core.$constructor<ZodUnknown> = /*@__PURE__*/ core.$constructor("ZodUnknown", (inst, def) => {
1024
1051
  core.$ZodUnknown.init(inst, def);
1025
1052
  ZodType.init(inst, def);
1053
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.unknownProcessor(inst, ctx, json, params);
1026
1054
  });
1027
1055
 
1028
1056
  export function unknown(): ZodUnknown {
@@ -1034,6 +1062,7 @@ export interface ZodNever extends _ZodType<core.$ZodNeverInternals> {}
1034
1062
  export const ZodNever: core.$constructor<ZodNever> = /*@__PURE__*/ core.$constructor("ZodNever", (inst, def) => {
1035
1063
  core.$ZodNever.init(inst, def);
1036
1064
  ZodType.init(inst, def);
1065
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.neverProcessor(inst, ctx, json, params);
1037
1066
  });
1038
1067
 
1039
1068
  export function never(params?: string | core.$ZodNeverParams): ZodNever {
@@ -1045,6 +1074,7 @@ export interface ZodVoid extends _ZodType<core.$ZodVoidInternals> {}
1045
1074
  export const ZodVoid: core.$constructor<ZodVoid> = /*@__PURE__*/ core.$constructor("ZodVoid", (inst, def) => {
1046
1075
  core.$ZodVoid.init(inst, def);
1047
1076
  ZodType.init(inst, def);
1077
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.voidProcessor(inst, ctx, json, params);
1048
1078
  });
1049
1079
 
1050
1080
  function _void(params?: string | core.$ZodVoidParams): ZodVoid {
@@ -1067,6 +1097,7 @@ export interface ZodDate extends _ZodDate<core.$ZodDateInternals<Date>> {}
1067
1097
  export const ZodDate: core.$constructor<ZodDate> = /*@__PURE__*/ core.$constructor("ZodDate", (inst, def) => {
1068
1098
  core.$ZodDate.init(inst, def);
1069
1099
  ZodType.init(inst, def);
1100
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.dateProcessor(inst, ctx, json, params);
1070
1101
 
1071
1102
  inst.min = (value, params) => inst.check(checks.gte(value, params));
1072
1103
  inst.max = (value, params) => inst.check(checks.lte(value, params));
@@ -1091,10 +1122,12 @@ export interface ZodArray<T extends core.SomeType = core.$ZodType>
1091
1122
  length(len: number, params?: string | core.$ZodCheckLengthEqualsParams): this;
1092
1123
 
1093
1124
  unwrap(): T;
1125
+ "~standard": ZodStandardSchemaWithJSON<this>;
1094
1126
  }
1095
1127
  export const ZodArray: core.$constructor<ZodArray> = /*@__PURE__*/ core.$constructor("ZodArray", (inst, def) => {
1096
1128
  core.$ZodArray.init(inst, def);
1097
1129
  ZodType.init(inst, def);
1130
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.arrayProcessor(inst, ctx, json, params);
1098
1131
 
1099
1132
  inst.element = def.element as any;
1100
1133
  inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params));
@@ -1133,6 +1166,7 @@ export interface ZodObject<
1133
1166
  out Config extends core.$ZodObjectConfig = core.$strip,
1134
1167
  > extends _ZodType<core.$ZodObjectInternals<Shape, Config>>,
1135
1168
  core.$ZodObject<Shape, Config> {
1169
+ "~standard": ZodStandardSchemaWithJSON<this>;
1136
1170
  shape: Shape;
1137
1171
 
1138
1172
  keyof(): ZodEnum<util.ToEnum<keyof Shape & string>>;
@@ -1209,6 +1243,7 @@ export interface ZodObject<
1209
1243
  export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
1210
1244
  core.$ZodObjectJIT.init(inst, def);
1211
1245
  ZodType.init(inst, def);
1246
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.objectProcessor(inst, ctx, json, params);
1212
1247
 
1213
1248
  util.defineLazy(inst, "shape", () => {
1214
1249
  return def.shape;
@@ -1278,11 +1313,13 @@ export function looseObject<T extends core.$ZodLooseShape>(
1278
1313
  export interface ZodUnion<T extends readonly core.SomeType[] = readonly core.$ZodType[]>
1279
1314
  extends _ZodType<core.$ZodUnionInternals<T>>,
1280
1315
  core.$ZodUnion<T> {
1316
+ "~standard": ZodStandardSchemaWithJSON<this>;
1281
1317
  options: T;
1282
1318
  }
1283
1319
  export const ZodUnion: core.$constructor<ZodUnion> = /*@__PURE__*/ core.$constructor("ZodUnion", (inst, def) => {
1284
1320
  core.$ZodUnion.init(inst, def);
1285
1321
  ZodType.init(inst, def);
1322
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.unionProcessor(inst, ctx, json, params);
1286
1323
  inst.options = def.options;
1287
1324
  });
1288
1325
 
@@ -1303,6 +1340,7 @@ export interface ZodDiscriminatedUnion<
1303
1340
  Disc extends string = string,
1304
1341
  > extends ZodUnion<Options>,
1305
1342
  core.$ZodDiscriminatedUnion<Options, Disc> {
1343
+ "~standard": ZodStandardSchemaWithJSON<this>;
1306
1344
  _zod: core.$ZodDiscriminatedUnionInternals<Options, Disc>;
1307
1345
  def: core.$ZodDiscriminatedUnionDef<Options, Disc>;
1308
1346
  }
@@ -1334,12 +1372,15 @@ export function discriminatedUnion<
1334
1372
  // ZodIntersection
1335
1373
  export interface ZodIntersection<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType>
1336
1374
  extends _ZodType<core.$ZodIntersectionInternals<A, B>>,
1337
- core.$ZodIntersection<A, B> {}
1375
+ core.$ZodIntersection<A, B> {
1376
+ "~standard": ZodStandardSchemaWithJSON<this>;
1377
+ }
1338
1378
  export const ZodIntersection: core.$constructor<ZodIntersection> = /*@__PURE__*/ core.$constructor(
1339
1379
  "ZodIntersection",
1340
1380
  (inst, def) => {
1341
1381
  core.$ZodIntersection.init(inst, def);
1342
1382
  ZodType.init(inst, def);
1383
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.intersectionProcessor(inst, ctx, json, params);
1343
1384
  }
1344
1385
  );
1345
1386
 
@@ -1360,11 +1401,13 @@ export interface ZodTuple<
1360
1401
  Rest extends core.SomeType | null = core.$ZodType | null,
1361
1402
  > extends _ZodType<core.$ZodTupleInternals<T, Rest>>,
1362
1403
  core.$ZodTuple<T, Rest> {
1404
+ "~standard": ZodStandardSchemaWithJSON<this>;
1363
1405
  rest<Rest extends core.SomeType = core.$ZodType>(rest: Rest): ZodTuple<T, Rest>;
1364
1406
  }
1365
1407
  export const ZodTuple: core.$constructor<ZodTuple> = /*@__PURE__*/ core.$constructor("ZodTuple", (inst, def) => {
1366
1408
  core.$ZodTuple.init(inst, def);
1367
1409
  ZodType.init(inst, def);
1410
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.tupleProcessor(inst, ctx, json, params);
1368
1411
  inst.rest = (rest) =>
1369
1412
  inst.clone({
1370
1413
  ...inst._zod.def,
@@ -1404,12 +1447,14 @@ export interface ZodRecord<
1404
1447
  Value extends core.SomeType = core.$ZodType,
1405
1448
  > extends _ZodType<core.$ZodRecordInternals<Key, Value>>,
1406
1449
  core.$ZodRecord<Key, Value> {
1450
+ "~standard": ZodStandardSchemaWithJSON<this>;
1407
1451
  keyType: Key;
1408
1452
  valueType: Value;
1409
1453
  }
1410
1454
  export const ZodRecord: core.$constructor<ZodRecord> = /*@__PURE__*/ core.$constructor("ZodRecord", (inst, def) => {
1411
1455
  core.$ZodRecord.init(inst, def);
1412
1456
  ZodType.init(inst, def);
1457
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.recordProcessor(inst, ctx, json, params);
1413
1458
 
1414
1459
  inst.keyType = def.keyType;
1415
1460
  inst.valueType = def.valueType;
@@ -1447,12 +1492,14 @@ export function partialRecord<Key extends core.$ZodRecordKey, Value extends core
1447
1492
  export interface ZodMap<Key extends core.SomeType = core.$ZodType, Value extends core.SomeType = core.$ZodType>
1448
1493
  extends _ZodType<core.$ZodMapInternals<Key, Value>>,
1449
1494
  core.$ZodMap<Key, Value> {
1495
+ "~standard": ZodStandardSchemaWithJSON<this>;
1450
1496
  keyType: Key;
1451
1497
  valueType: Value;
1452
1498
  }
1453
1499
  export const ZodMap: core.$constructor<ZodMap> = /*@__PURE__*/ core.$constructor("ZodMap", (inst, def) => {
1454
1500
  core.$ZodMap.init(inst, def);
1455
1501
  ZodType.init(inst, def);
1502
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.mapProcessor(inst, ctx, json, params);
1456
1503
  inst.keyType = def.keyType;
1457
1504
  inst.valueType = def.valueType;
1458
1505
  });
@@ -1474,6 +1521,7 @@ export function map<Key extends core.SomeType, Value extends core.SomeType>(
1474
1521
  export interface ZodSet<T extends core.SomeType = core.$ZodType>
1475
1522
  extends _ZodType<core.$ZodSetInternals<T>>,
1476
1523
  core.$ZodSet<T> {
1524
+ "~standard": ZodStandardSchemaWithJSON<this>;
1477
1525
  min(minSize: number, params?: string | core.$ZodCheckMinSizeParams): this;
1478
1526
  nonempty(params?: string | core.$ZodCheckMinSizeParams): this;
1479
1527
  max(maxSize: number, params?: string | core.$ZodCheckMaxSizeParams): this;
@@ -1482,6 +1530,7 @@ export interface ZodSet<T extends core.SomeType = core.$ZodType>
1482
1530
  export const ZodSet: core.$constructor<ZodSet> = /*@__PURE__*/ core.$constructor("ZodSet", (inst, def) => {
1483
1531
  core.$ZodSet.init(inst, def);
1484
1532
  ZodType.init(inst, def);
1533
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.setProcessor(inst, ctx, json, params);
1485
1534
 
1486
1535
  inst.min = (...args) => inst.check(core._minSize(...args));
1487
1536
  inst.nonempty = (params) => inst.check(core._minSize(1, params));
@@ -1506,6 +1555,7 @@ export interface ZodEnum<
1506
1555
  out T extends util.EnumLike = util.EnumLike,
1507
1556
  > extends _ZodType<core.$ZodEnumInternals<T>>,
1508
1557
  core.$ZodEnum<T> {
1558
+ "~standard": ZodStandardSchemaWithJSON<this>;
1509
1559
  enum: T;
1510
1560
  options: Array<T[keyof T]>;
1511
1561
 
@@ -1521,6 +1571,7 @@ export interface ZodEnum<
1521
1571
  export const ZodEnum: core.$constructor<ZodEnum> = /*@__PURE__*/ core.$constructor("ZodEnum", (inst, def) => {
1522
1572
  core.$ZodEnum.init(inst, def);
1523
1573
  ZodType.init(inst, def);
1574
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.enumProcessor(inst, ctx, json, params);
1524
1575
 
1525
1576
  inst.enum = def.entries;
1526
1577
  inst.options = Object.values(def.entries);
@@ -1593,6 +1644,7 @@ export function nativeEnum<T extends util.EnumLike>(entries: T, params?: string
1593
1644
  export interface ZodLiteral<T extends util.Literal = util.Literal>
1594
1645
  extends _ZodType<core.$ZodLiteralInternals<T>>,
1595
1646
  core.$ZodLiteral<T> {
1647
+ "~standard": ZodStandardSchemaWithJSON<this>;
1596
1648
  values: Set<T>;
1597
1649
  /** @legacy Use `.values` instead. Accessing this property will throw an error if the literal accepts multiple values. */
1598
1650
  value: T;
@@ -1600,6 +1652,7 @@ export interface ZodLiteral<T extends util.Literal = util.Literal>
1600
1652
  export const ZodLiteral: core.$constructor<ZodLiteral> = /*@__PURE__*/ core.$constructor("ZodLiteral", (inst, def) => {
1601
1653
  core.$ZodLiteral.init(inst, def);
1602
1654
  ZodType.init(inst, def);
1655
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.literalProcessor(inst, ctx, json, params);
1603
1656
  inst.values = new Set(def.values);
1604
1657
  Object.defineProperty(inst, "value", {
1605
1658
  get() {
@@ -1629,6 +1682,7 @@ export function literal(value: any, params: any) {
1629
1682
 
1630
1683
  // ZodFile
1631
1684
  export interface ZodFile extends _ZodType<core.$ZodFileInternals>, core.$ZodFile {
1685
+ "~standard": ZodStandardSchemaWithJSON<this>;
1632
1686
  min(size: number, params?: string | core.$ZodCheckMinSizeParams): this;
1633
1687
  max(size: number, params?: string | core.$ZodCheckMaxSizeParams): this;
1634
1688
  mime(types: util.MimeTypes | Array<util.MimeTypes>, params?: string | core.$ZodCheckMimeTypeParams): this;
@@ -1636,6 +1690,7 @@ export interface ZodFile extends _ZodType<core.$ZodFileInternals>, core.$ZodFile
1636
1690
  export const ZodFile: core.$constructor<ZodFile> = /*@__PURE__*/ core.$constructor("ZodFile", (inst, def) => {
1637
1691
  core.$ZodFile.init(inst, def);
1638
1692
  ZodType.init(inst, def);
1693
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.fileProcessor(inst, ctx, json, params);
1639
1694
 
1640
1695
  inst.min = (size, params) => inst.check(core._minSize(size, params));
1641
1696
  inst.max = (size, params) => inst.check(core._maxSize(size, params));
@@ -1649,12 +1704,15 @@ export function file(params?: string | core.$ZodFileParams): ZodFile {
1649
1704
  // ZodTransform
1650
1705
  export interface ZodTransform<O = unknown, I = unknown>
1651
1706
  extends _ZodType<core.$ZodTransformInternals<O, I>>,
1652
- core.$ZodTransform<O, I> {}
1707
+ core.$ZodTransform<O, I> {
1708
+ "~standard": ZodStandardSchemaWithJSON<this>;
1709
+ }
1653
1710
  export const ZodTransform: core.$constructor<ZodTransform> = /*@__PURE__*/ core.$constructor(
1654
1711
  "ZodTransform",
1655
1712
  (inst, def) => {
1656
1713
  core.$ZodTransform.init(inst, def);
1657
1714
  ZodType.init(inst, def);
1715
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.transformProcessor(inst, ctx, json, params);
1658
1716
 
1659
1717
  inst._zod.parse = (payload, _ctx) => {
1660
1718
  if (_ctx.direction === "backward") {
@@ -1703,6 +1761,7 @@ export function transform<I = unknown, O = I>(
1703
1761
  export interface ZodOptional<T extends core.SomeType = core.$ZodType>
1704
1762
  extends _ZodType<core.$ZodOptionalInternals<T>>,
1705
1763
  core.$ZodOptional<T> {
1764
+ "~standard": ZodStandardSchemaWithJSON<this>;
1706
1765
  unwrap(): T;
1707
1766
  }
1708
1767
  export const ZodOptional: core.$constructor<ZodOptional> = /*@__PURE__*/ core.$constructor(
@@ -1710,6 +1769,7 @@ export const ZodOptional: core.$constructor<ZodOptional> = /*@__PURE__*/ core.$c
1710
1769
  (inst, def) => {
1711
1770
  core.$ZodOptional.init(inst, def);
1712
1771
  ZodType.init(inst, def);
1772
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.optionalProcessor(inst, ctx, json, params);
1713
1773
 
1714
1774
  inst.unwrap = () => inst._zod.def.innerType;
1715
1775
  }
@@ -1726,6 +1786,7 @@ export function optional<T extends core.SomeType>(innerType: T): ZodOptional<T>
1726
1786
  export interface ZodNullable<T extends core.SomeType = core.$ZodType>
1727
1787
  extends _ZodType<core.$ZodNullableInternals<T>>,
1728
1788
  core.$ZodNullable<T> {
1789
+ "~standard": ZodStandardSchemaWithJSON<this>;
1729
1790
  unwrap(): T;
1730
1791
  }
1731
1792
  export const ZodNullable: core.$constructor<ZodNullable> = /*@__PURE__*/ core.$constructor(
@@ -1733,6 +1794,7 @@ export const ZodNullable: core.$constructor<ZodNullable> = /*@__PURE__*/ core.$c
1733
1794
  (inst, def) => {
1734
1795
  core.$ZodNullable.init(inst, def);
1735
1796
  ZodType.init(inst, def);
1797
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.nullableProcessor(inst, ctx, json, params);
1736
1798
 
1737
1799
  inst.unwrap = () => inst._zod.def.innerType;
1738
1800
  }
@@ -1754,6 +1816,7 @@ export function nullish<T extends core.SomeType>(innerType: T): ZodOptional<ZodN
1754
1816
  export interface ZodDefault<T extends core.SomeType = core.$ZodType>
1755
1817
  extends _ZodType<core.$ZodDefaultInternals<T>>,
1756
1818
  core.$ZodDefault<T> {
1819
+ "~standard": ZodStandardSchemaWithJSON<this>;
1757
1820
  unwrap(): T;
1758
1821
  /** @deprecated Use `.unwrap()` instead. */
1759
1822
  removeDefault(): T;
@@ -1761,6 +1824,7 @@ export interface ZodDefault<T extends core.SomeType = core.$ZodType>
1761
1824
  export const ZodDefault: core.$constructor<ZodDefault> = /*@__PURE__*/ core.$constructor("ZodDefault", (inst, def) => {
1762
1825
  core.$ZodDefault.init(inst, def);
1763
1826
  ZodType.init(inst, def);
1827
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.defaultProcessor(inst, ctx, json, params);
1764
1828
 
1765
1829
  inst.unwrap = () => inst._zod.def.innerType;
1766
1830
  inst.removeDefault = inst.unwrap;
@@ -1783,6 +1847,7 @@ export function _default<T extends core.SomeType>(
1783
1847
  export interface ZodPrefault<T extends core.SomeType = core.$ZodType>
1784
1848
  extends _ZodType<core.$ZodPrefaultInternals<T>>,
1785
1849
  core.$ZodPrefault<T> {
1850
+ "~standard": ZodStandardSchemaWithJSON<this>;
1786
1851
  unwrap(): T;
1787
1852
  }
1788
1853
  export const ZodPrefault: core.$constructor<ZodPrefault> = /*@__PURE__*/ core.$constructor(
@@ -1790,6 +1855,7 @@ export const ZodPrefault: core.$constructor<ZodPrefault> = /*@__PURE__*/ core.$c
1790
1855
  (inst, def) => {
1791
1856
  core.$ZodPrefault.init(inst, def);
1792
1857
  ZodType.init(inst, def);
1858
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.prefaultProcessor(inst, ctx, json, params);
1793
1859
  inst.unwrap = () => inst._zod.def.innerType;
1794
1860
  }
1795
1861
  );
@@ -1811,6 +1877,7 @@ export function prefault<T extends core.SomeType>(
1811
1877
  export interface ZodNonOptional<T extends core.SomeType = core.$ZodType>
1812
1878
  extends _ZodType<core.$ZodNonOptionalInternals<T>>,
1813
1879
  core.$ZodNonOptional<T> {
1880
+ "~standard": ZodStandardSchemaWithJSON<this>;
1814
1881
  unwrap(): T;
1815
1882
  }
1816
1883
  export const ZodNonOptional: core.$constructor<ZodNonOptional> = /*@__PURE__*/ core.$constructor(
@@ -1818,6 +1885,7 @@ export const ZodNonOptional: core.$constructor<ZodNonOptional> = /*@__PURE__*/ c
1818
1885
  (inst, def) => {
1819
1886
  core.$ZodNonOptional.init(inst, def);
1820
1887
  ZodType.init(inst, def);
1888
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.nonoptionalProcessor(inst, ctx, json, params);
1821
1889
 
1822
1890
  inst.unwrap = () => inst._zod.def.innerType;
1823
1891
  }
@@ -1838,11 +1906,13 @@ export function nonoptional<T extends core.SomeType>(
1838
1906
  export interface ZodSuccess<T extends core.SomeType = core.$ZodType>
1839
1907
  extends _ZodType<core.$ZodSuccessInternals<T>>,
1840
1908
  core.$ZodSuccess<T> {
1909
+ "~standard": ZodStandardSchemaWithJSON<this>;
1841
1910
  unwrap(): T;
1842
1911
  }
1843
1912
  export const ZodSuccess: core.$constructor<ZodSuccess> = /*@__PURE__*/ core.$constructor("ZodSuccess", (inst, def) => {
1844
1913
  core.$ZodSuccess.init(inst, def);
1845
1914
  ZodType.init(inst, def);
1915
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.successProcessor(inst, ctx, json, params);
1846
1916
 
1847
1917
  inst.unwrap = () => inst._zod.def.innerType;
1848
1918
  });
@@ -1858,6 +1928,7 @@ export function success<T extends core.SomeType>(innerType: T): ZodSuccess<T> {
1858
1928
  export interface ZodCatch<T extends core.SomeType = core.$ZodType>
1859
1929
  extends _ZodType<core.$ZodCatchInternals<T>>,
1860
1930
  core.$ZodCatch<T> {
1931
+ "~standard": ZodStandardSchemaWithJSON<this>;
1861
1932
  unwrap(): T;
1862
1933
  /** @deprecated Use `.unwrap()` instead. */
1863
1934
  removeCatch(): T;
@@ -1865,6 +1936,7 @@ export interface ZodCatch<T extends core.SomeType = core.$ZodType>
1865
1936
  export const ZodCatch: core.$constructor<ZodCatch> = /*@__PURE__*/ core.$constructor("ZodCatch", (inst, def) => {
1866
1937
  core.$ZodCatch.init(inst, def);
1867
1938
  ZodType.init(inst, def);
1939
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.catchProcessor(inst, ctx, json, params);
1868
1940
 
1869
1941
  inst.unwrap = () => inst._zod.def.innerType;
1870
1942
  inst.removeCatch = inst.unwrap;
@@ -1885,10 +1957,13 @@ function _catch<T extends core.SomeType>(
1885
1957
  export { _catch as catch };
1886
1958
 
1887
1959
  // ZodNaN
1888
- export interface ZodNaN extends _ZodType<core.$ZodNaNInternals>, core.$ZodNaN {}
1960
+ export interface ZodNaN extends _ZodType<core.$ZodNaNInternals>, core.$ZodNaN {
1961
+ "~standard": ZodStandardSchemaWithJSON<this>;
1962
+ }
1889
1963
  export const ZodNaN: core.$constructor<ZodNaN> = /*@__PURE__*/ core.$constructor("ZodNaN", (inst, def) => {
1890
1964
  core.$ZodNaN.init(inst, def);
1891
1965
  ZodType.init(inst, def);
1966
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.nanProcessor(inst, ctx, json, params);
1892
1967
  });
1893
1968
 
1894
1969
  export function nan(params?: string | core.$ZodNaNParams): ZodNaN {
@@ -1899,12 +1974,14 @@ export function nan(params?: string | core.$ZodNaNParams): ZodNaN {
1899
1974
  export interface ZodPipe<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType>
1900
1975
  extends _ZodType<core.$ZodPipeInternals<A, B>>,
1901
1976
  core.$ZodPipe<A, B> {
1977
+ "~standard": ZodStandardSchemaWithJSON<this>;
1902
1978
  in: A;
1903
1979
  out: B;
1904
1980
  }
1905
1981
  export const ZodPipe: core.$constructor<ZodPipe> = /*@__PURE__*/ core.$constructor("ZodPipe", (inst, def) => {
1906
1982
  core.$ZodPipe.init(inst, def);
1907
1983
  ZodType.init(inst, def);
1984
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.pipeProcessor(inst, ctx, json, params);
1908
1985
 
1909
1986
  inst.in = def.in;
1910
1987
  inst.out = def.out;
@@ -1927,6 +2004,7 @@ export function pipe(in_: core.SomeType, out: core.SomeType) {
1927
2004
  export interface ZodCodec<A extends core.SomeType = core.$ZodType, B extends core.SomeType = core.$ZodType>
1928
2005
  extends ZodPipe<A, B>,
1929
2006
  core.$ZodCodec<A, B> {
2007
+ "~standard": ZodStandardSchemaWithJSON<this>;
1930
2008
  _zod: core.$ZodCodecInternals<A, B>;
1931
2009
  def: core.$ZodCodecDef<A, B>;
1932
2010
  }
@@ -1956,6 +2034,7 @@ export function codec<const A extends core.SomeType, B extends core.SomeType = c
1956
2034
  export interface ZodReadonly<T extends core.SomeType = core.$ZodType>
1957
2035
  extends _ZodType<core.$ZodReadonlyInternals<T>>,
1958
2036
  core.$ZodReadonly<T> {
2037
+ "~standard": ZodStandardSchemaWithJSON<this>;
1959
2038
  unwrap(): T;
1960
2039
  }
1961
2040
  export const ZodReadonly: core.$constructor<ZodReadonly> = /*@__PURE__*/ core.$constructor(
@@ -1963,6 +2042,7 @@ export const ZodReadonly: core.$constructor<ZodReadonly> = /*@__PURE__*/ core.$c
1963
2042
  (inst, def) => {
1964
2043
  core.$ZodReadonly.init(inst, def);
1965
2044
  ZodType.init(inst, def);
2045
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.readonlyProcessor(inst, ctx, json, params);
1966
2046
 
1967
2047
  inst.unwrap = () => inst._zod.def.innerType;
1968
2048
  }
@@ -1978,12 +2058,15 @@ export function readonly<T extends core.SomeType>(innerType: T): ZodReadonly<T>
1978
2058
  // ZodTemplateLiteral
1979
2059
  export interface ZodTemplateLiteral<Template extends string = string>
1980
2060
  extends _ZodType<core.$ZodTemplateLiteralInternals<Template>>,
1981
- core.$ZodTemplateLiteral<Template> {}
2061
+ core.$ZodTemplateLiteral<Template> {
2062
+ "~standard": ZodStandardSchemaWithJSON<this>;
2063
+ }
1982
2064
  export const ZodTemplateLiteral: core.$constructor<ZodTemplateLiteral> = /*@__PURE__*/ core.$constructor(
1983
2065
  "ZodTemplateLiteral",
1984
2066
  (inst, def) => {
1985
2067
  core.$ZodTemplateLiteral.init(inst, def);
1986
2068
  ZodType.init(inst, def);
2069
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.templateLiteralProcessor(inst, ctx, json, params);
1987
2070
  }
1988
2071
  );
1989
2072
 
@@ -2002,11 +2085,13 @@ export function templateLiteral<const Parts extends core.$ZodTemplateLiteralPart
2002
2085
  export interface ZodLazy<T extends core.SomeType = core.$ZodType>
2003
2086
  extends _ZodType<core.$ZodLazyInternals<T>>,
2004
2087
  core.$ZodLazy<T> {
2088
+ "~standard": ZodStandardSchemaWithJSON<this>;
2005
2089
  unwrap(): T;
2006
2090
  }
2007
2091
  export const ZodLazy: core.$constructor<ZodLazy> = /*@__PURE__*/ core.$constructor("ZodLazy", (inst, def) => {
2008
2092
  core.$ZodLazy.init(inst, def);
2009
2093
  ZodType.init(inst, def);
2094
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.lazyProcessor(inst, ctx, json, params);
2010
2095
 
2011
2096
  inst.unwrap = () => inst._zod.def.getter();
2012
2097
  });
@@ -2022,11 +2107,13 @@ export function lazy<T extends core.SomeType>(getter: () => T): ZodLazy<T> {
2022
2107
  export interface ZodPromise<T extends core.SomeType = core.$ZodType>
2023
2108
  extends _ZodType<core.$ZodPromiseInternals<T>>,
2024
2109
  core.$ZodPromise<T> {
2110
+ "~standard": ZodStandardSchemaWithJSON<this>;
2025
2111
  unwrap(): T;
2026
2112
  }
2027
2113
  export const ZodPromise: core.$constructor<ZodPromise> = /*@__PURE__*/ core.$constructor("ZodPromise", (inst, def) => {
2028
2114
  core.$ZodPromise.init(inst, def);
2029
2115
  ZodType.init(inst, def);
2116
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.promiseProcessor(inst, ctx, json, params);
2030
2117
 
2031
2118
  inst.unwrap = () => inst._zod.def.innerType;
2032
2119
  });
@@ -2044,6 +2131,7 @@ export interface ZodFunction<
2044
2131
  Returns extends core.$ZodFunctionOut = core.$ZodFunctionOut,
2045
2132
  > extends _ZodType<core.$ZodFunctionInternals<Args, Returns>>,
2046
2133
  core.$ZodFunction<Args, Returns> {
2134
+ "~standard": ZodStandardSchemaWithJSON<this>;
2047
2135
  _def: core.$ZodFunctionDef<Args, Returns>;
2048
2136
  _input: core.$InferInnerFunctionType<Args, Returns>;
2049
2137
  _output: core.$InferOuterFunctionType<Args, Returns>;
@@ -2063,6 +2151,7 @@ export const ZodFunction: core.$constructor<ZodFunction> = /*@__PURE__*/ core.$c
2063
2151
  (inst, def) => {
2064
2152
  core.$ZodFunction.init(inst, def);
2065
2153
  ZodType.init(inst, def);
2154
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.functionProcessor(inst, ctx, json, params);
2066
2155
  }
2067
2156
  );
2068
2157
 
@@ -2106,10 +2195,13 @@ export { _function as function };
2106
2195
  // ZodCustom
2107
2196
  export interface ZodCustom<O = unknown, I = unknown>
2108
2197
  extends _ZodType<core.$ZodCustomInternals<O, I>>,
2109
- core.$ZodCustom<O, I> {}
2198
+ core.$ZodCustom<O, I> {
2199
+ "~standard": ZodStandardSchemaWithJSON<this>;
2200
+ }
2110
2201
  export const ZodCustom: core.$constructor<ZodCustom> = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def) => {
2111
2202
  core.$ZodCustom.init(inst, def);
2112
2203
  ZodType.init(inst, def);
2204
+ inst._zod.processJSONSchema = (ctx, json, params) => processors.customProcessor(inst, ctx, json, params);
2113
2205
  });
2114
2206
 
2115
2207
  // custom checks
@@ -1,7 +1,8 @@
1
- import { test } from "vitest";
2
- // import * as z from "zod/v4";
1
+ import { expect, test } from "vitest";
3
2
 
4
- test(() => {});
3
+ test(() => {
4
+ expect(2).toBe(2);
5
+ });
5
6
  // test("overload types", () => {
6
7
  // const schema = z.string().json();
7
8
  // util.assertEqual<typeof schema, z.ZodString>(true);
@@ -55,3 +55,80 @@ test("length checks", async () => {
55
55
  }
56
56
  `);
57
57
  });
58
+
59
+ test("schemas conform to StandardJSONSchemaV1", async () => {
60
+ const schema = z.codec(z.string(), z.number(), {
61
+ decode: (str) => Number.parseFloat(str),
62
+ encode: (num) => num.toString(),
63
+ });
64
+ expect(schema["~standard"].validate).toBeTypeOf("function");
65
+ expect(await schema["~standard"].validate("42")).toMatchInlineSnapshot(`
66
+ {
67
+ "value": 42,
68
+ }
69
+ `);
70
+ expect(schema["~standard"].jsonSchema.input({ target: "draft-2020-12" })).toMatchInlineSnapshot(`
71
+ {
72
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
73
+ "type": "string",
74
+ }
75
+ `);
76
+ expect(schema["~standard"].jsonSchema.output({ target: "draft-2020-12" })).toMatchInlineSnapshot(`
77
+ {
78
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
79
+ "type": "number",
80
+ }
81
+ `);
82
+ });
83
+
84
+ test(".toJSONSchema() returns StandardJSONSchemaV1", async () => {
85
+ const codec = z.codec(z.string(), z.number(), {
86
+ decode: (str) => Number.parseFloat(str),
87
+ encode: (num) => num.toString(),
88
+ });
89
+ const result = codec.toJSONSchema();
90
+ expect(result["~standard"].validate).toBeTypeOf("function");
91
+ expect(await result["~standard"].validate("42")).toMatchInlineSnapshot(`
92
+ {
93
+ "value": 42,
94
+ }
95
+ `);
96
+ expect(result["~standard"].jsonSchema.input({ target: "draft-2020-12" })).toMatchInlineSnapshot(`
97
+ {
98
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
99
+ "type": "string",
100
+ }
101
+ `);
102
+ expect(result["~standard"].jsonSchema.output({ target: "draft-2020-12" })).toMatchInlineSnapshot(`
103
+ {
104
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
105
+ "type": "number",
106
+ }
107
+ `);
108
+ });
109
+
110
+ test("z.toJSONSchema() returns StandardJSONSchemaV1", async () => {
111
+ const codec = z.codec(z.string(), z.number(), {
112
+ decode: (str) => Number.parseFloat(str),
113
+ encode: (num) => num.toString(),
114
+ });
115
+ const result = z.toJSONSchema(codec);
116
+ expect(result["~standard"].validate).toBeTypeOf("function");
117
+ expect(await result["~standard"].validate("42")).toMatchInlineSnapshot(`
118
+ {
119
+ "value": 42,
120
+ }
121
+ `);
122
+ expect(result["~standard"].jsonSchema.input({ target: "draft-2020-12" })).toMatchInlineSnapshot(`
123
+ {
124
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
125
+ "type": "string",
126
+ }
127
+ `);
128
+ expect(result["~standard"].jsonSchema.output({ target: "draft-2020-12" })).toMatchInlineSnapshot(`
129
+ {
130
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
131
+ "type": "number",
132
+ }
133
+ `);
134
+ });