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

[question] 100% compatibility with zod API? #32

Closed
miguelrk opened this issue Jan 22, 2024 · 3 comments
Closed

[question] 100% compatibility with zod API? #32

miguelrk opened this issue Jan 22, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request zod
Milestone

Comments

@miguelrk
Copy link

miguelrk commented Jan 22, 2024

I understand that the ajv-ts API is a subset of the larger zod API by design, since ajv-ts should only support what is defined in JSON schema, and not the extra stuff zod adds. However, it would be great for this library to achieve 100% compatibility with the zod API in what they do have in common. This would allow using ajv-ts as a drop-in replacement for zod for the vast ecosystem of zod packages. For example, auto-form should ideally simply work:

import AutoForm, { AutoFormSubmit } from "./components/ui/auto-form";
import s from "ajv-ts";

const formSchema = s.object({ name: s.string(), age: s.number().optional() });

function App() {
  return <AutoForm formSchema={formSchema} />;
}

Expected Result:

image

However, this is throwing errors since the ajv-ts schema does not match the same zod schema (the s.object() has another form than z.object()).

Would this compatibility desired? This could be a good design decision (to align 100% with zod) in order to benefit from its vast ecosystem.

@miguelrk miguelrk added the enhancement New feature or request label Jan 22, 2024
@vitalics
Copy link
Owner

HI, @miguelrk I'm working on the zod compatibility API. Unfortunately, not everything can be 1-1 matched. I suppose the 1.0.0 version will satisfy Zod portability API

@vitalics vitalics added this to the Zod milestone Jan 23, 2024
@vitalics vitalics mentioned this issue Jan 23, 2024
25 tasks
@vitalics vitalics added the zod label Jan 23, 2024
@miguelrk
Copy link
Author

First of all thanks for the quick answer! That's great to hear! Looking forward to 1.0.0.. I understand not everything can be 1-1 matched (by design) since this library should adhere to the JSON schema spec first and foremost, but aligning to the zod API I think would indeed allow integrating with the zod ecosystem, right? Not sure if it will work in practice, but at least conceptually I wouldn't see why it wouldn't...

@vitalics
Copy link
Owner

conceptually it can work, will see in practice, right? I'll close the issue now since #35 has already been created to track the progress of API compatibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request zod
Projects
None yet
Development

No branches or pull requests

2 participants