Skip to content

[Snyk] Upgrade zod from 3.25.56 to 4.3.6 - #9

Open
pinkycollie wants to merge 1 commit into
mainfrom
snyk-upgrade-6299d2706515fd24cd423c03513eff14
Open

[Snyk] Upgrade zod from 3.25.56 to 4.3.6#9
pinkycollie wants to merge 1 commit into
mainfrom
snyk-upgrade-6299d2706515fd24cd423c03513eff14

Conversation

@pinkycollie

Copy link
Copy Markdown
Owner

snyk-top-banner

Snyk has created this PR to upgrade zod from 3.25.56 to 4.3.6.

ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.


  • The recommended version is 327 versions ahead of your current version.

  • The recommended version was released 23 days ago.

Breaking Change Risk

Merge Risk: High

Notice: This assessment is enhanced by AI.

Release notes
Package name: zod
  • 4.3.6 - 2026-01-22

    Commits:

  • 4.3.5 - 2026-01-04

    Commits:

  • 4.3.4 - 2025-12-31

    Commits:

  • 4.3.3 - 2025-12-31

    Commits:

  • 4.3.2 - 2025-12-31

    Commits:

  • 4.3.1 - 2025-12-31

    Commits:

    • 0fe8840 allow non-overwriting extends with refinements. 4.3.1
  • 4.3.0 - 2025-12-31

    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 (#5534, #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.

    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 (#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.

    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 (#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.

    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 (#5589)

    A new wrapper that makes a property key-optional (can be omitted) but does not accept undefined as an explicit value.

    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.

    .apply()

    A utility method for applying arbitrary transformations to a schema, enabling cleaner schema composition. (#5463)

    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 #4764, #4836.

    // 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() (#5575)

    The .refine() method now supports type predicates to narrow the output type:

    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 (#5316)

    ZodMap now has parity with ZodSet and ZodArray:

    const schema = z.map(z.string(), z.number())
    .min(1)
    .max(10)
    .nonempty();

    schema.size; // access the size constraint

    .with() alias for .check() (359c0db)

    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.

    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():

    // 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)

    Zod Mini now exports z.meta() and z.describe() as top-level functions for adding metadata to schemas:

    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 })
    );

    More ergonomic intersections #5587

    When intersecting schemas that include z.strictObject(), Zod 4 now only rejects keys that are unrecognized by both sides of the intersection. Previously, any unrecognized key from either side would cause an error.

    This means keys that are recognized by at least one side of the intersection will now pass validation:

    const A = z.strictObject({ a: z.string() });
    const B = z.object({ b: z.string() });

    const C = z.intersection(A, B);

    // Keys recognized by either side now work
    C.parse({ a: "foo", b: "bar" }); // ✅ { a: "foo", b: "bar" }

    // Extra keys are stripped (follows strip behavior from B)
    C.parse({ a: "foo", b: "bar", c: "extra" }); // ✅ { a: "foo", b: "bar" }

    When both sides are strict, only keys unrecognized by both sides will error:

    const A = z.strictObject({ a: z.string() });
    const B = z.strictObject({ b: z.string() });

    const C = z.intersection(A, B);

    // Keys recognized by either side work
    C.parse({ a: "foo", b: "bar" }); // ✅

    // Keys unrecognized by BOTH sides error
    C.parse({ a: "foo", b: "bar", c: "extra" });
    // ❌ ZodError: Unrecognized key: "c"

    New locales

    import * as z from "zod";
    import { uz } from "zod/locales";

    z.config(uz());




    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 (#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.

    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.

    const newSchema = z.object(schema.shape).pick({ ... })

    ⚠️ overwriting properties with.extend() disallowed on object schemas with refinements (#5317)

    Similarly, .extend() will throws on schemas with refinements if you are overwriting existing properties.

    const schema = z.object({
    a: z.string()
    }).refine(/* ... */);

    schema.extend({ a: z.number() }); // 4.3: throws error ❌

    Instead you can use .safeExtend(), which statically ensures that you aren't changing the type signature of any pre-existing properties.

    const schema = z.object({
    a: z.string(),
    }).refine(/* ... */);

    schema.safeExtend({
    a: z.string().min(5).max(10)
    }); // ✅ allows overwrite, preserves refinement

    ⚠️ Stricter object masking methods (#5581)

    Object masking methods (.pick(), .omit()) now validate that the keys provided actually exist in the schema:

    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 (#5557)
    • Fixed error details for tuples with extraneous elements (#5555)
    • Fixed includes method params typing to accept string | $ZodCheckIncludesParams (#5556)
    • Fixed numeric formats error messages to be inclusive (#5485)
    • Fixed implementAsync inferred type to always be a promise (#5476)
    • Tightened E.164 regex to require a non-zero leading digit and 7–15 digits total (#5524)
    • Fixed Dutch (nl) error strings (#5529)
    • Convert Date instances to numbers in minimum/maximum checks (#5351)
    • Improved numeric keys handling in z.record() (#5585)
    • Lazy initialization of ~standard schema property (#5363)
    • Functions marked as @ __NO_SIDE_EFFECTS__ for better tree-shaking (#5475)
    • Improved metadata tracking across child-parent relationships (#5578)
    • Improved locale translation approach (#5584)
    • Dropped id uniqueness enforcement at registry level (#5574)
  • 4.3.0-canary.20251231T042704 - 2025-12-31
  • 4.3.0-canary.20251231T025730 - 2025-12-31
  • 4.3.0-canary.20251231T012420 - 2025-12-31
  • 4.3.0-canary.20251231T004216 - 2025-12-31
  • 4.3.0-canary.20251231T000036 - 2025-12-31
  • 4.3.0-canary.20251230T223005 - 2025-12-30
  • 4.3.0-canary.20251230T222919 - 2025-12-30
  • 4.3.0-canary.20251230T222623 - 2025-12-30
  • 4.3.0-canary.20251230T221222 - 2025-12-30
  • 4.3.0-canary.20251230T220815 - 2025-12-30
  • 4.3.0-canary.20251230T180715 - 2025-12-30
  • 4.3.0-canary.20251230T173842 - 2025-12-30
  • 4.3.0-canary.20251230T173255 - 2025-12-30
  • 4.3.0-canary.20251230T171456 - 2025-12-30
  • 4.3.0-canary.20251230T021842 - 2025-12-30
  • 4.3.0-canary.20251229T223913 - 2025-12-29
  • 4.3.0-canary.20251229T203155 - 2025-12-29
  • 4.3.0-canary.20251229T201908 - 2025-12-29
  • 4.3.0-canary.20251229T201822 - 2025-12-29
  • 4.3.0-canary.20251229T200951 - 2025-12-29
  • 4.3.0-canary.20251229T193724 - 2025-12-29
  • 4.3.0-canary.20251229T193106 - 2025-12-29
  • 4.3.0-canary.20251229T192655 - 2025-12-29
  • 4.3.0-canary.20251223T202943 - 2025-12-23
  • 4.3.0-canary.20251223T032816 - 2025-12-23
  • 4.3.0-canary.20251223T023855 - 2025-12-23
  • 4.3.0-canary.20251222T205904 - 2025-12-22
  • 4.3.0-canary.20251222T195342 - 2025-12-22
  • 4.3.0-canary.20251222T061611 - 2025-12-22
  • 4.3.0-canary.20251216T172808 - 2025-12-16
  • 4.3.0-canary.20251216T031837 - 2025-12-16
  • 4.3.0-canary.20251216T031750 - 2025-12-16
  • 4.3.0-canary.20251216T030621 - 2025-12-16
  • 4.2.1 - 2025-12-16

    Commits:

  • 4.2.0 - 2025-12-15

    Features

    Implement Standard JSON Schema

    standard-schema/standard-schema#134

    Implement z.fromJSONSchema()

    const jsonSchema = {
    type: "object",
    ...

Snyk has created this PR to upgrade zod from 3.25.56 to 4.3.6.

See this package in npm:
zod

See this project in Snyk:
https://app.snyk.io/org/pinkycollie/project/19394bc5-5ee2-4bfe-8a0b-7dfa3f7b57e0?utm_source=github&utm_medium=referral&page=upgrade-pr
@pinkycollie

Copy link
Copy Markdown
Owner Author

Merge Risk: High

The upgrade from zod v3 to v4 is a major version jump with significant breaking changes that require code modifications. While offering major performance improvements, several core APIs have been refactored.

Key Breaking Changes:

  • Unified Error Handling: The most impactful change is the consolidation of error customization. The previous parameters message, invalid_type_error, and required_error are deprecated and replaced by a single error parameter. All custom error logic must be migrated to this new API. [1]
  • Object Strictness: The chainable methods .strict() and .passthrough() are deprecated. You must now use the top-level functions z.strictObject() and z.looseObject() to define object behavior. [1]
  • z.function() Redesign: The API for z.function() has been completely changed. It is no longer a chainable schema but a factory function where input and output schemas are defined upfront. [1]
  • .default() Behavior Change: The behavior of .default() now short-circuits and applies the default value if the input is undefined, whereas v3 would parse the default value itself. A new .prefault() method is available to replicate the old behavior. [1]

Recommendation: Developers must review their schema definitions and update them to conform to the new v4 APIs, especially for error handling and object creation. A community-maintained codemod, zod-v3-to-v4, is available to help automate parts of this migration. [2, 4]

Source: Zod v4 Migration Guide

Notice 🤖: This content was augmented using artificial intelligence. AI-generated content may contain errors and should be reviewed for accuracy before use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants