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

feat: initial zod support #3171

Merged
merged 8 commits into from Feb 14, 2021
Merged

feat: initial zod support #3171

merged 8 commits into from Feb 14, 2021

Conversation

logaretm
Copy link
Owner

πŸ”Ž Overview

Add support for zod schemas by adding a new "resolver" package that converts them to yup-like schemas.

πŸ€“ Code snippets/examples (if applicable)

import { toFormValidator } from '@vee-validate/zod';
import * as zod from 'zod';
import { toFieldValidator } from '@vee-validate/zod';

// Field schema to be used with `Field.rules` prop or `useField`
const fieldSchema = toFieldValidator(zod.string().nonempty(REQUIRED_MSG).min(8, MIN_MSG));

// Field schema to be used with as form validation schema
const schema = toFormValidator(
  zod
    .object({
      password: zod.string(),
      confirmation: zod.string(),
    })
    .refine(data => data.confirmation === data.password, {
      message: CONFIRM_MSG,
      path: ['confirmation'],
    })
);

βœ” Issues affected

closes #3160

@soerenmartius
Copy link

Looks great πŸš€

@codecov-io
Copy link

codecov-io commented Feb 13, 2021

Codecov Report

Merging #3171 (95ee6f1) into main (94a4552) will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3171      +/-   ##
==========================================
+ Coverage   97.12%   97.17%   +0.05%     
==========================================
  Files          63       64       +1     
  Lines        1392     1418      +26     
  Branches      342      344       +2     
==========================================
+ Hits         1352     1378      +26     
  Misses         39       39              
  Partials        1        1              
Impacted Files Coverage Ξ”
packages/zod/src/index.ts 100.00% <100.00%> (ΓΈ)

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update 94a4552...95ee6f1. Read the comment docs.

@logaretm
Copy link
Owner Author

@soerenmartius This took longer because I wanted to match yup type inference with Zods, meaning I wanted to get initialValues and other generic functions picking up the correct types from Zod's schemas just like Yup. It seems to be working for me although I'm not a heavy user of Zod's

Feel free to play around with it more as I still have to write the docs for this.

Copy link

@soerenmartius soerenmartius left a comment

Choose a reason for hiding this comment

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

looks great!

@soerenmartius
Copy link

@soerenmartius This took longer because I wanted to match yup type inference with Zods, meaning I wanted to get initialValues and other generic functions picking up the correct types from Zod's schemas just like Yup. It seems to be working for me although I'm not a heavy user of Zod's

Feel free to play around with it more as I still have to write the docs for this.

thanks a lot! works great.. just tested it using the composition api

@logaretm logaretm merged commit 3778373 into main Feb 14, 2021
@logaretm logaretm deleted the feat/zod-support branch February 14, 2021 22:54
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.

Support for colinhacks/zod
3 participants