Skip to content

Commit 5ab0f69

Browse files
chore(deps): update dependency zod to v4.3.2 (#3156)
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [zod](https://zod.dev) ([source](https://redirect.github.com/colinhacks/zod)) | [`4.2.1` → `4.3.2`](https://renovatebot.com/diffs/npm/zod/4.2.1/4.3.2) | ![age](https://developer.mend.io/api/mc/badges/age/npm/zod/4.3.2?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/zod/4.2.1/4.3.2?slim=true) | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.3.2`](https://redirect.github.com/colinhacks/zod/compare/v4.3.1...0f41e5a12a43e6913c9dcb501b2b5136ea86500d) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.3.1...v4.3.2) ### [`v4.3.1`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.3.1) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.3.0...v4.3.1) #### Commits: - [`0fe8840`](https://redirect.github.com/colinhacks/zod/commit/0fe88407a4149c907929b757dc6618d8afe998fc) allow non-overwriting extends with refinements. 4.3.1 ### [`v4.3.0`](https://redirect.github.com/colinhacks/zod/releases/tag/v4.3.0) [Compare Source](https://redirect.github.com/colinhacks/zod/compare/v4.2.1...v4.3.0) This is Zod's biggest release since 4.0. It addresses several of Zod's longest-standing feature requests. #### `z.fromJSONSchema()` Convert JSON Schema to Zod ([#&#8203;5534](https://redirect.github.com/colinhacks/zod/pull/5534), [#&#8203;5586](https://redirect.github.com/colinhacks/zod/pull/5586)) You can now convert JSON Schema definitions directly into Zod schemas. This function supports JSON Schema `"draft-2020-12"`, `"draft-7"`, `"draft-4"`, and OpenAPI 3.0. ```typescript import * as z from "zod"; const schema = z.fromJSONSchema({ type: "object", properties: { name: { type: "string", minLength: 1 }, age: { type: "integer", minimum: 0 }, }, required: ["name"], }); schema.parse({ name: "Alice", age: 30 }); // ✅ ``` The API should be considered experimental. There are no guarantees of 1:1 "round-trip soundness": `MySchema` > `z.toJSONSchema()` > `z.fromJSONSchema()`. There are several features of Zod that don't exist in JSON Schema and vice versa, which makes this virtually impossible. Features supported: - All primitive types (`string`, `number`, `integer`, `boolean`, `null`, `object`, `array`) - String formats (`email`, `uri`, `uuid`, `date-time`, `date`, `time`, `ipv4`, `ipv6`, and more) - Composition (`anyOf`, `oneOf`, `allOf`) - Object constraints (`additionalProperties`, `patternProperties`, `propertyNames`) - Array constraints (`prefixItems`, `items`, `minItems`, `maxItems`) - `$ref` for local references and circular schemas - Custom metadata is preserved #### `z.xor()` — exclusive union ([#&#8203;5534](https://redirect.github.com/colinhacks/zod/pull/5534)) A new exclusive union type that requires **exactly one** option to match. Unlike `z.union()` which passes if *any* option matches, `z.xor()` fails if zero or more than one option matches. ```typescript const schema = z.xor([z.string(), z.number()]); schema.parse("hello"); // ✅ schema.parse(42); // ✅ schema.parse(true); // ❌ zero matches ``` When converted to JSON Schema, `z.xor()` produces `oneOf` instead of `anyOf`. #### `z.looseRecord()` — partial record validation ([#&#8203;5534](https://redirect.github.com/colinhacks/zod/pull/5534)) A new record variant that only validates keys matching the key schema, passing through non-matching keys unchanged. This is used to represent `patternProperties` in JSON Schema. ```typescript const schema = z.looseRecord(z.string().regex(/^S_/), z.string()); schema.parse({ S_name: "John", other: 123 }); // ✅ { S_name: "John", other: 123 } // only S_name is validated, "other" passes through ``` #### `.exactOptional()` — strict optional properties ([#&#8203;5589](https://redirect.github.com/colinhacks/zod/pull/5589)) A new wrapper that makes a property *key-optional* (can be omitted) but does **not** accept `undefined` as an explicit value. ```typescript const schema = z.object({ a: z.string().optional(), // accepts `undefined` b: z.string().exactOptional(), // does not accept `undefined` }); schema.parse({}); // ✅ schema.parse({ a: undefined }); // ✅ schema.parse({ b: undefined }); // ❌ ``` This makes it possible to accurately represent the full spectrum of optionality expressible using [`exactOptionalPropertyTypes`](https://www.typescriptlang.org/tsconfig/exactOptionalPropertyTypes.html). #### `.apply()` A utility method for applying arbitrary transformations to a schema, enabling cleaner schema composition. ([#&#8203;5463](https://redirect.github.com/colinhacks/zod/pull/5463)) ```typescript const setCommonChecks = <T extends z.ZodNumber>(schema: T) => { return schema.min(0).max(100); }; const schema = z.number().apply(setCommonChecks).nullable(); ``` #### `.brand()` cardinality The `.brand()` method now accepts a second argument to control whether the brand applies to input, output, or both. Closes [#&#8203;4764](https://redirect.github.com/colinhacks/zod/issues/4764), [#&#8203;4836](https://redirect.github.com/colinhacks/zod/issues/4836). ```typescript // output only (default) z.string().brand<"UserId">(); // output is branded (default) z.string().brand<"UserId", "out">(); // output is branded z.string().brand<"UserId", "in">(); // input is branded z.string().brand<"UserId", "inout">(); // both are branded ``` #### Type predicates on `.refine()` ([#&#8203;5575](https://redirect.github.com/colinhacks/zod/pull/5575)) The `.refine()` method now supports type predicates to narrow the output type: ```typescript const schema = z.string().refine((s): s is "a" => s === "a"); type Input = z.input<typeof schema>; // string type Output = z.output<typeof schema>; // "a" ``` #### `ZodMap` methods: `min`, `max`, `nonempty`, `size` ([#&#8203;5316](https://redirect.github.com/colinhacks/zod/pull/5316)) `ZodMap` now has parity with `ZodSet` and `ZodArray`: ```typescript const schema = z.map(z.string(), z.number()) .min(1) .max(10) .nonempty(); schema.size; // access the size constraint ``` #### `.with()` alias for `.check()` ([359c0db](https://redirect.github.com/colinhacks/zod/commit/359c0db6)) A new `.with()` method has been added as a more readable alias for `.check()`. Over time, more APIs have been added that don't qualify as "checks". The new method provides a readable alternative that doesn't muddy semantics. ```typescript z.string().with( z.minLength(5), z.toLowerCase() ); // equivalent to: z.string().check( z.minLength(5), z.trim(), z.toLowerCase() ); ``` ##### `z.slugify()` transform Transform strings into URL-friendly slugs. Works great with `.with()`: ```typescript // Zod z.string().slugify().parse("Hello World"); // "hello-world" // Zod Mini // using .with() for explicit check composition z.string().with(z.slugify()).parse("Hello World"); // "hello-world" ``` #### `z.meta()` and `z.describe()` in Zod Mini ([947b4eb](https://redirect.github.com/colinhacks/zod/commit/947b4eb2)) Zod Mini now exports `z.meta()` and `z.describe()` as top-level functions for adding metadata to schemas: ```typescript import * as z from "zod/mini"; // add description const schema = z.string().with( z.describe("A user's name"), ); // add arbitrary metadata const schema2 = z.number().with( z.meta({ deprecated: true }) ); ``` #### New locales - Armenian (`am`) ([#&#8203;5531](https://redirect.github.com/colinhacks/zod/pull/5531)) - Uzbek (`uz`) ([#&#8203;5519](https://redirect.github.com/colinhacks/zod/pull/5519)) ```ts import * as z from "zod"; import { uz } from "zod/locales"; z.config(uz()); ``` <br/><br/> *** <br/><br/> #### Bug fixes All of these changes fix soundness issues in Zod. As with any bug fix there's some chance of breakage if you were intentionally or unintentionally relying on this unsound behavior. ##### ⚠️ `.pick()` and `.omit()` disallowed on object schemas containing refinements ([#&#8203;5317](https://redirect.github.com/colinhacks/zod/pull/5317)) Using `.pick()` or `.omit()` on object schemas with refinements now throws an error. Previously, this would silently drop the refinements, leading to unexpected behavior. ```typescript const schema = z.object({ password: z.string(), confirmPassword: z.string(), }).refine(data => data.password === data.confirmPassword); schema.pick({ password: true }); // 4.2: refinement silently dropped ⚠️ // 4.3: throws error ❌ ``` **Migration**: The easiest way to migrate is to create a new schema using the `shape` of the old one. ```ts const newSchema = z.object(schema.shape).pick({ ... }) ``` ##### ⚠️ `.extend()` disallowed on refined schemas ([#&#8203;5317](https://redirect.github.com/colinhacks/zod/pull/5317)) Similarly, `.extend()` now throws on schemas with refinements. Use `.safeExtend()` if you need to extend refined schemas. ```typescript const schema = z.object({ a: z.string() }).refine(/* ... */); // 4.2: refinement silently dropped ⚠️ // 4.3: throws error ✅ schema.extend({ b: z.number() }); // error: object schemas containing refinements cannot be extended. use `.safeExtend()` instead. ``` ##### ⚠️ Stricter object masking methods ([#&#8203;5581](https://redirect.github.com/colinhacks/zod/pull/5581)) Object masking methods (`.pick()`, `.omit()`) now validate that the keys provided actually exist in the schema: ```typescript const schema = z.object({ a: z.string() }); // 4.3: throws error for unrecognized keys schema.pick({ nonexistent: true }); // error: unrecognized key: "nonexistent" ``` #### Additional changes - Fixed JSON Schema generation for `z.iso.time` with minute precision ([#&#8203;5557](https://redirect.github.com/colinhacks/zod/pull/5557)) - Fixed error details for tuples with extraneous elements ([#&#8203;5555](https://redirect.github.com/colinhacks/zod/pull/5555)) - Fixed `includes` method params typing to accept `string | $ZodCheckIncludesParams` ([#&#8203;5556](https://redirect.github.com/colinhacks/zod/pull/5556)) - Fixed numeric formats error messages to be inclusive ([#&#8203;5485](https://redirect.github.com/colinhacks/zod/pull/5485)) - Fixed `implementAsync` inferred type to always be a promise ([#&#8203;5476](https://redirect.github.com/colinhacks/zod/pull/5476)) - Tightened E.164 regex to require a non-zero leading digit and 7–15 digits total ([#&#8203;5524](https://redirect.github.com/colinhacks/zod/pull/5524)) - Fixed Dutch (nl) error strings ([#&#8203;5529](https://redirect.github.com/colinhacks/zod/pull/5529)) - Convert `Date` instances to numbers in `minimum`/`maximum` checks ([#&#8203;5351](https://redirect.github.com/colinhacks/zod/pull/5351)) - Improved numeric keys handling in `z.record()` ([#&#8203;5585](https://redirect.github.com/colinhacks/zod/pull/5585)) - Lazy initialization of `~standard` schema property ([#&#8203;5363](https://redirect.github.com/colinhacks/zod/pull/5363)) - Functions marked as `@__NO_SIDE_EFFECTS__` for better tree-shaking ([#&#8203;5475](https://redirect.github.com/colinhacks/zod/pull/5475)) - Improved metadata tracking across child-parent relationships ([#&#8203;5578](https://redirect.github.com/colinhacks/zod/pull/5578)) - Improved locale translation approach ([#&#8203;5584](https://redirect.github.com/colinhacks/zod/pull/5584)) - Dropped id uniqueness enforcement at registry level ([#&#8203;5574](https://redirect.github.com/colinhacks/zod/pull/5574)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/RobinTail/express-zod-api). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi42Ni4xNCIsInVwZGF0ZWRJblZlciI6IjQyLjY2LjE0IiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Robin Tail <[email protected]>
1 parent 1115157 commit 5ab0f69

File tree

6 files changed

+121
-61
lines changed

6 files changed

+121
-61
lines changed

example/example.documentation.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ paths:
132132
required: true
133133
description: PATCH /v1/user/:id Parameter
134134
schema:
135-
examples:
136-
- "1234567890"
137135
type: string
138136
minLength: 1
137+
examples:
138+
- "1234567890"
139139
examples:
140140
example1:
141141
value: "1234567890"
@@ -144,9 +144,9 @@ paths:
144144
required: true
145145
description: PATCH /v1/user/:id Parameter
146146
schema:
147+
type: string
147148
examples:
148149
- "12"
149-
type: string
150150
examples:
151151
example1:
152152
value: "12"
@@ -158,15 +158,15 @@ paths:
158158
type: object
159159
properties:
160160
key:
161+
type: string
162+
minLength: 1
161163
examples:
162164
- 1234-5678-90
165+
name:
163166
type: string
164167
minLength: 1
165-
name:
166168
examples:
167169
- John Doe
168-
type: string
169-
minLength: 1
170170
birthday:
171171
description: the day of birth
172172
type: string
@@ -205,9 +205,9 @@ paths:
205205
type: object
206206
properties:
207207
name:
208+
type: string
208209
examples:
209210
- John Doe
210-
type: string
211211
createdAt:
212212
description: account creation date
213213
type: string
@@ -275,11 +275,11 @@ paths:
275275
type: object
276276
properties:
277277
name:
278+
type: string
279+
pattern: ^\w+ \w+$
278280
description: first name and last name
279281
examples:
280282
- John Doe
281-
type: string
282-
pattern: ^\w+ \w+$
283283
required:
284284
- name
285285
examples:
@@ -868,7 +868,6 @@ paths:
868868
components:
869869
schemas:
870870
Feature:
871-
id: Feature
872871
type: object
873872
properties:
874873
title:
@@ -880,6 +879,7 @@ components:
880879
required:
881880
- title
882881
additionalProperties: false
882+
id: Feature
883883
responses: {}
884884
parameters: {}
885885
examples: {}

express-zod-api/tests/__snapshots__/documentation.spec.ts.snap

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,9 @@ paths:
20912091
- option2
20922092
additionalProperties:
20932093
type: boolean
2094+
required:
2095+
- option1
2096+
- option2
20942097
required:
20952098
- simple
20962099
- stringy
@@ -3594,8 +3597,8 @@ paths:
35943597
required: true
35953598
description: GET /v1/getSomething Parameter
35963599
schema:
3597-
deprecated: true
35983600
type: string
3601+
deprecated: true
35993602
responses:
36003603
"200":
36013604
description: GET /v1/getSomething Positive response
@@ -3653,8 +3656,8 @@ paths:
36533656
required: true
36543657
description: HEAD /v1/getSomething Parameter
36553658
schema:
3656-
deprecated: true
36573659
type: string
3660+
deprecated: true
36583661
responses:
36593662
"200":
36603663
description: HEAD /v1/getSomething Positive response
@@ -3713,11 +3716,6 @@ paths:
37133716
type: string
37143717
const: success
37153718
data:
3716-
examples:
3717-
- a: first
3718-
b: prefix_first
3719-
- a: second
3720-
b: prefix_second
37213719
type: object
37223720
properties:
37233721
a:
@@ -3728,6 +3726,11 @@ paths:
37283726
- a
37293727
- b
37303728
additionalProperties: false
3729+
examples:
3730+
- a: first
3731+
b: prefix_first
3732+
- a: second
3733+
b: prefix_second
37313734
required:
37323735
- status
37333736
- data
@@ -3933,15 +3936,15 @@ paths:
39333936
type: string
39343937
const: success
39353938
data:
3936-
examples:
3937-
- num: 123
39383939
type: object
39393940
properties:
39403941
num:
39413942
type: number
39423943
required:
39433944
- num
39443945
additionalProperties: false
3946+
examples:
3947+
- num: 123
39453948
required:
39463949
- status
39473950
- data
@@ -4013,13 +4016,13 @@ paths:
40134016
type: object
40144017
properties:
40154018
key:
4019+
type: string
40164020
examples:
40174021
- 1234-56789-01
4018-
type: string
40194022
str:
4023+
type: string
40204024
examples:
40214025
- test
4022-
type: string
40234026
required:
40244027
- key
40254028
- str
@@ -4044,9 +4047,9 @@ paths:
40444047
type: object
40454048
properties:
40464049
num:
4050+
type: number
40474051
examples:
40484052
- 123
4049-
type: number
40504053
required:
40514054
- num
40524055
additionalProperties: false
@@ -4137,15 +4140,15 @@ paths:
41374140
type: string
41384141
const: success
41394142
data:
4140-
examples:
4141-
- numericStr: "123"
41424143
type: object
41434144
properties:
41444145
numericStr:
41454146
type: string
41464147
required:
41474148
- numericStr
41484149
additionalProperties: false
4150+
examples:
4151+
- numericStr: "123"
41494152
required:
41504153
- status
41514154
- data
@@ -4254,15 +4257,15 @@ paths:
42544257
type: string
42554258
const: success
42564259
data:
4257-
examples:
4258-
- numericStr: "123"
42594260
type: object
42604261
properties:
42614262
numericStr:
42624263
type: string
42634264
required:
42644265
- numericStr
42654266
additionalProperties: false
4267+
examples:
4268+
- numericStr: "123"
42664269
required:
42674270
- status
42684271
- data
@@ -4332,9 +4335,9 @@ paths:
43324335
required: true
43334336
description: GET /v1/getSomething Parameter
43344337
schema:
4338+
type: string
43354339
examples:
43364340
- "123"
4337-
type: string
43384341
examples:
43394342
example1:
43404343
value: "123"
@@ -4407,9 +4410,9 @@ paths:
44074410
required: true
44084411
description: HEAD /v1/getSomething Parameter
44094412
schema:
4413+
type: string
44104414
examples:
44114415
- "123"
4412-
type: string
44134416
examples:
44144417
example1:
44154418
value: "123"
@@ -4451,9 +4454,9 @@ paths:
44514454
type: object
44524455
properties:
44534456
strNum:
4457+
type: string
44544458
examples:
44554459
- "123"
4456-
type: string
44574460
required:
44584461
- strNum
44594462
examples:
@@ -4553,8 +4556,8 @@ paths:
45534556
required: true
45544557
description: here is the test
45554558
schema:
4556-
description: here is the test
45574559
type: string
4560+
description: here is the test
45584561
responses:
45594562
"200":
45604563
description: GET /v1/getSomething Positive response
@@ -4570,10 +4573,10 @@ paths:
45704573
type: object
45714574
properties:
45724575
result:
4573-
description: some positive integer
45744576
type: integer
45754577
exclusiveMinimum: 0
45764578
maximum: 9007199254740991
4579+
description: some positive integer
45774580
required:
45784581
- result
45794582
additionalProperties: false
@@ -4617,8 +4620,8 @@ paths:
46174620
required: true
46184621
description: here is the test
46194622
schema:
4620-
description: here is the test
46214623
type: string
4624+
description: here is the test
46224625
responses:
46234626
"200":
46244627
description: HEAD /v1/getSomething Positive response
@@ -5029,12 +5032,12 @@ paths:
50295032
components:
50305033
schemas:
50315034
NameParam:
5032-
id: NameParam
50335035
anyOf:
50345036
- type: string
50355037
const: John
50365038
- type: string
50375039
const: Jane
5040+
id: NameParam
50385041
responses: {}
50395042
parameters: {}
50405043
examples: {}

express-zod-api/tests/__snapshots__/env.spec.ts.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ exports[`Environment checks > Zod checks/refinements > Snapshot control 'ZodNumb
6161
"type": "number",
6262
},
6363
"deferred": [],
64+
"parent": {
65+
"$schema": "https://json-schema.org/draft/2020-12/schema",
66+
"type": "number",
67+
},
6468
"parse": [Function],
6569
"pattern": /\\^-\\?\\\\d\\+\\$/,
6670
"processJSONSchema": [Function],
@@ -171,6 +175,12 @@ exports[`Environment checks > Zod checks/refinements > Snapshot control 'ZodNumb
171175
"onattach": [
172176
[Function],
173177
],
178+
"parent": {
179+
"$schema": "https://json-schema.org/draft/2020-12/schema",
180+
"maximum": 9007199254740991,
181+
"minimum": -9007199254740991,
182+
"type": "integer",
183+
},
174184
"parse": [Function],
175185
"pattern": /\\^-\\?\\\\d\\+\\$/,
176186
"processJSONSchema": [Function],
@@ -209,6 +219,10 @@ exports[`Environment checks > Zod checks/refinements > Snapshot control 'ZodStri
209219
"type": "string",
210220
},
211221
"deferred": [],
222+
"parent": {
223+
"$schema": "https://json-schema.org/draft/2020-12/schema",
224+
"type": "string",
225+
},
212226
"parse": [Function],
213227
"pattern": /\\^\\(\\?!\\\\\\.\\)\\(\\?!\\.\\*\\\\\\.\\\\\\.\\)\\(\\[A-Za-z0-9_'\\+\\\\-\\\\\\.\\]\\*\\)\\[A-Za-z0-9_\\+-\\]@\\(\\[A-Za-z0-9\\]\\[A-Za-z0-9\\\\-\\]\\*\\\\\\.\\)\\+\\[A-Za-z\\]\\{2,\\}\\$/,
214228
"processJSONSchema": [Function],

express-zod-api/tests/__snapshots__/json-schema-helpers.spec.ts.snap

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`JSON Schema helpers > flattenIO() > should handle records 1`] = `
3+
exports[`JSON Schema helpers > flattenIO() > should handle records > in intersection 1`] = `
4+
{
5+
"examples": [
6+
{
7+
"four": 456,
8+
"one": "test",
9+
"three": 123,
10+
"two": "jest",
11+
},
12+
{
13+
"four": 456,
14+
"one": "some",
15+
"three": 123,
16+
"two": "another",
17+
},
18+
],
19+
"properties": {
20+
"four": {
21+
"type": "number",
22+
},
23+
"one": {
24+
"type": "string",
25+
},
26+
"three": {
27+
"type": "number",
28+
},
29+
"two": {
30+
"type": "string",
31+
},
32+
},
33+
"required": [
34+
"one",
35+
"two",
36+
"three",
37+
"four",
38+
],
39+
"type": "object",
40+
}
41+
`;
42+
43+
exports[`JSON Schema helpers > flattenIO() > should handle records > in union 1`] = `
444
{
545
"examples": [
646
{

0 commit comments

Comments
 (0)