Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Zod .refine and .superRefine #1319

Merged
merged 4 commits into from
May 24, 2024
Merged

Conversation

piotrpospiech
Copy link
Collaborator

This allows to pass to the ZodBridge schema that has refine or superRefine.

Example:

const schema = z
  .object({
    username: z.string().min(4),
    password: z.string().min(8),
    confirmPassword: z.string().min(8),
  })
  .refine((form) => form.password === form.confirmPassword, {
    message: "Passwords don't match",
    path: ["confirmPassword"],
  });
const schema = z
  .object({
    username: z.string().min(4),
    password: z.string().min(8),
    confirmPassword: z.string().min(8),
  })
  .superRefine((val, ctx) => {
    if (val.password !== val.confirmPassword) {
      ctx.addIssue({
        code: z.ZodIssueCode.custom,
        message: "Passwords don't match",
        path: ["confirmPassword"],
      });
    }
  });
image

@piotrpospiech piotrpospiech added this to the v4.0 milestone Apr 20, 2024
@piotrpospiech piotrpospiech self-assigned this Apr 20, 2024
@github-actions github-actions bot added Area: Bridge Affects some of the bridge packages Bridge: Zod Affects the uniforms-bridge-zod package labels Apr 20, 2024
Copy link

codecov bot commented Apr 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.56%. Comparing base (4b3f109) to head (4bdd4a0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1319   +/-   ##
=======================================
  Coverage   94.55%   94.56%           
=======================================
  Files         231      231           
  Lines        3823     3825    +2     
  Branches     1030     1031    +1     
=======================================
+ Hits         3615     3617    +2     
  Misses         82       82           
  Partials      126      126           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@piotrpospiech piotrpospiech changed the title Added support for Zod .refine and .superRefine Add support for Zod .refine and .superRefine Apr 20, 2024
Copy link
Member

@kestarumper kestarumper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a simple test that creates the ZodBridge from a z.object(...).refine() and z.object(...).superRefine()?
Motivation: https://github.com/vazco/uniforms/pull/1319/files#annotation_20741969379

@piotrpospiech piotrpospiech merged commit 7d6db69 into master May 24, 2024
7 checks passed
@piotrpospiech piotrpospiech deleted the zod-refine branch May 24, 2024 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Bridge Affects some of the bridge packages Bridge: Zod Affects the uniforms-bridge-zod package
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants