zod 4.2.0-canary.20250826T000512 → 4.2.0-canary.20250826T001214

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.2.0-canary.20250826T000512",
3
+ "version": "4.2.0-canary.20250826T001214",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -571,6 +571,19 @@ describe("toJSONSchema", () => {
571
571
  `);
572
572
  });
573
573
 
574
+ test("number with exclusive min-max openapi", () => {
575
+ const schema = z.number().lt(100).gt(1);
576
+ expect(z.toJSONSchema(schema, { target: "openapi-3.0" })).toMatchInlineSnapshot(`
577
+ {
578
+ "exclusiveMaximum": true,
579
+ "exclusiveMinimum": true,
580
+ "maximum": 100,
581
+ "minimum": 1,
582
+ "type": "number",
583
+ }
584
+ `);
585
+ });
586
+
574
587
  test("arrays", () => {
575
588
  expect(z.toJSONSchema(z.array(z.string()))).toMatchInlineSnapshot(`
576
589
  {
@@ -652,6 +665,18 @@ describe("toJSONSchema", () => {
652
665
  `);
653
666
  });
654
667
 
668
+ test("record openapi", () => {
669
+ const schema = z.record(z.string(), z.boolean());
670
+ expect(z.toJSONSchema(schema, { target: "openapi-3.0" })).toMatchInlineSnapshot(`
671
+ {
672
+ "additionalProperties": {
673
+ "type": "boolean",
674
+ },
675
+ "type": "object",
676
+ }
677
+ `);
678
+ });
679
+
655
680
  test("tuple", () => {
656
681
  const schema = z.tuple([z.string(), z.number()]);
657
682
  expect(z.toJSONSchema(schema)).toMatchInlineSnapshot(`
@@ -183,7 +183,7 @@ export class JSONSchemaGenerator {
183
183
  else json.type = "number";
184
184
 
185
185
  if (typeof exclusiveMinimum === "number") {
186
- if (this.target === "draft-4") {
186
+ if (this.target === "draft-4" || this.target === "openapi-3.0") {
187
187
  json.minimum = exclusiveMinimum;
188
188
  json.exclusiveMinimum = true;
189
189
  } else {
@@ -199,7 +199,7 @@ export class JSONSchemaGenerator {
199
199
  }
200
200
 
201
201
  if (typeof exclusiveMaximum === "number") {
202
- if (this.target === "draft-4") {
202
+ if (this.target === "draft-4" || this.target === "openapi-3.0") {
203
203
  json.maximum = exclusiveMaximum;
204
204
  json.exclusiveMaximum = true;
205
205
  } else {
@@ -421,7 +421,7 @@ export class JSONSchemaGenerator {
421
421
  case "record": {
422
422
  const json: JSONSchema.ObjectSchema = _json as any;
423
423
  json.type = "object";
424
- if (this.target !== "draft-4") {
424
+ if (this.target === "draft-7" || this.target === "draft-2020-12") {
425
425
  json.propertyNames = this.process(def.keyType, {
426
426
  ...params,
427
427
  path: [...params.path, "propertyNames"],
@@ -101,7 +101,7 @@ class JSONSchemaGenerator {
101
101
  else
102
102
  json.type = "number";
103
103
  if (typeof exclusiveMinimum === "number") {
104
- if (this.target === "draft-4") {
104
+ if (this.target === "draft-4" || this.target === "openapi-3.0") {
105
105
  json.minimum = exclusiveMinimum;
106
106
  json.exclusiveMinimum = true;
107
107
  }
@@ -119,7 +119,7 @@ class JSONSchemaGenerator {
119
119
  }
120
120
  }
121
121
  if (typeof exclusiveMaximum === "number") {
122
- if (this.target === "draft-4") {
122
+ if (this.target === "draft-4" || this.target === "openapi-3.0") {
123
123
  json.maximum = exclusiveMaximum;
124
124
  json.exclusiveMaximum = true;
125
125
  }
@@ -335,7 +335,7 @@ class JSONSchemaGenerator {
335
335
  case "record": {
336
336
  const json = _json;
337
337
  json.type = "object";
338
- if (this.target !== "draft-4") {
338
+ if (this.target === "draft-7" || this.target === "draft-2020-12") {
339
339
  json.propertyNames = this.process(def.keyType, {
340
340
  ...params,
341
341
  path: [...params.path, "propertyNames"],
@@ -97,7 +97,7 @@ export class JSONSchemaGenerator {
97
97
  else
98
98
  json.type = "number";
99
99
  if (typeof exclusiveMinimum === "number") {
100
- if (this.target === "draft-4") {
100
+ if (this.target === "draft-4" || this.target === "openapi-3.0") {
101
101
  json.minimum = exclusiveMinimum;
102
102
  json.exclusiveMinimum = true;
103
103
  }
@@ -115,7 +115,7 @@ export class JSONSchemaGenerator {
115
115
  }
116
116
  }
117
117
  if (typeof exclusiveMaximum === "number") {
118
- if (this.target === "draft-4") {
118
+ if (this.target === "draft-4" || this.target === "openapi-3.0") {
119
119
  json.maximum = exclusiveMaximum;
120
120
  json.exclusiveMaximum = true;
121
121
  }
@@ -331,7 +331,7 @@ export class JSONSchemaGenerator {
331
331
  case "record": {
332
332
  const json = _json;
333
333
  json.type = "object";
334
- if (this.target !== "draft-4") {
334
+ if (this.target === "draft-7" || this.target === "draft-2020-12") {
335
335
  json.propertyNames = this.process(def.keyType, {
336
336
  ...params,
337
337
  path: [...params.path, "propertyNames"],