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(clients): add zod #785

Merged
merged 5 commits into from
Mar 27, 2023
Merged

feat(clients): add zod #785

merged 5 commits into from
Mar 27, 2023

Conversation

anymaniax
Copy link
Collaborator

Due to the demand, I add the new client zod 🎉.

Thanks to @stijnvanhulle, who previously did the implementation. I hope it's ok for you I took what you did as a starting point.

@vercel
Copy link

vercel bot commented Mar 2, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
orval ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 27, 2023 at 5:50PM (UTC)

@aodinok
Copy link

aodinok commented Mar 2, 2023

Thanks @anymaniax ! I think this will be a nice addition to orval. I wonder if it would be possible to import consts or the whole zod schemas only? Since we are not using zod for example and writing client for every validation lib out there may be a lot of effort plus you need a way to combine/extend validation rules probably?

@anymaniax
Copy link
Collaborator Author

@aodinok you have custom validation or using something like yup?

@aodinok
Copy link

aodinok commented Mar 2, 2023

We are using yup at the moment

@anymaniax
Copy link
Collaborator Author

anymaniax commented Mar 2, 2023

If I do the same for yup would it work for you? example

@aodinok
Copy link

aodinok commented Mar 2, 2023

I think the problem with this schemas would be that it is hard to modify/extend them.
In most of the cases you probably will want to make validation more strict in some places or add different custom messages to the schemas (e.g. intl) but if we export the schema per model without exporting basics (e.g. minLength value or even schema per prop) it will be pretty hard to extend the schemas.

@anymaniax
Copy link
Collaborator Author

Probably a mix of both would be great

@aodinok
Copy link

aodinok commented Mar 2, 2023

Yeah exactly. Basics plus model schemas - and then you can use whole model schema when needed or basics with custom schema.

No need to build yup specifically for us. I'm happy to contribute using your example for zod when I will have some spare time. Thanks a lot for adding this 👍

@stijnvanhulle
Copy link

@anymaniax Sure, no problem. Started with this a couple of months ago but that only included Zod schemas for component.schemas and not for the different API calls. Thanks for finishing this :)

@anymaniax
Copy link
Collaborator Author

@stijnvanhulle from what I saw it's based on pathItem. Which is great for a first version. I would like to split by schema but before the v7 it's not possible I need to refactor the config and the output system by package first.

@anymaniax
Copy link
Collaborator Author

@aodinok I have something like this right now

@aodinok
Copy link

aodinok commented Mar 3, 2023

This is cool! Thanks for letting me know. I think we will be able to use this for our use case.

aodinok
aodinok previously approved these changes Mar 3, 2023

export const getZodDependencies = () => ZOD_DEPENDENCIES;

const resolveZodType = (schemaTypeValue: SchemaObject['type']) => {
Copy link

Choose a reason for hiding this comment

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

type can be array in OpenAPI, e.g. type: ["string", null] is this being handled in some internal lib?

packages/zod/src/index.ts Show resolved Hide resolved
packages/zod/src/index.ts Outdated Show resolved Hide resolved
@anymaniax
Copy link
Collaborator Author

I think we have a good enough first version I will merge this

@anymaniax anymaniax merged commit cebdb2e into master Mar 27, 2023
@anymaniax anymaniax deleted the feature/client-zod branch March 27, 2023 17:56
@stijnvanhulle
Copy link

@anymaniax Is it possible to create a new version so we can start playing around with the Zod integration?

@sirtimbly
Copy link
Contributor

just git clone the branch from github directly, good idea to check it out. I ran it and had a few issues, I'll try to open an issue.

@anymaniax
Copy link
Collaborator Author

Hello guys, @stijnvanhulle I did an alpha version you can try it with @orval/alpha. @sirtimbly I did a lot of fixes for the zod client yesterday and will try to release a patch version today

@anymaniax
Copy link
Collaborator Author

@stijnvanhulle @sirtimbly just published Orval 6.13.1

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.

4 participants