-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Support arktype to zod function #769
Comments
@sinclairzx81 was actually working on something like this recently! I could definitely see the value in having something like this available in the ecosystem, although it would never be a part of the core package itself. That said, we do eventually plan to allow direct compilation to/from JSON schema so hopefully that will be a big help in terms of standardization. @sinclairzx81 let me know if the work you're doing in TypeBox would support go-between mappings to Zod and JSON schema, otherwise we'll try and whip something up to cover the straightforward conversions after the beta release. |
@ssalbdivad Heya, Currently the Workbench project only supports TypeScript to TypeBox transformation (via compiler transform). Once the TypeScript types are encoded as TypeBox types (with the encoding referred to as the TypeBoxModel), I apply a secondary transform from the Model out to other formats (JSONSchema (naturally), JavaScript (validation, value generation), Zod, etc). In this regard, the TypeBoxModel is a pivot point for transformation.
To support something like Zod to JSON Schema, I'd need to write something to evaluate the Zod types into the TypeBox Model (or use the compiler to map Zod into the TypeBoxModel). This is somewhat out of scope for the Workbench (or Codegen backend, i guess???), but I agree there would be value in having such transformations. I'm open to hearing ideas on providing a more generalized transformation tool for community runtime type systems. And would be more than happy to contribute a TB to such a effort (I'm getting asked about code generation more and more these days, so it's worth exploring) |
@sinclairzx81 Ahh okay got it, it looked from some of the code you sent for the workbench that it was potentially reusable for these kind of transformations, but maybe there is a part of it I'm missing that would require its own effort. Happy to coordinate on this as soon as we wrap up the beta release! |
iiuc @sinclairzx81 correctly, it sounds like plugging into the TypeBox ecosystem entails exporting a This would open up JSON Schema creation, as well as transpilation to Zod, JSON Schema, raw JS/TS, etc @ssalbdivad any thought on what would be entailed in making this happen? |
Compiling to JSON schema is a top priority! It seems like from there we will have lots of options to leverage that as an intermediate layer to other validators. It is currently our most upvoted open issue: #776 |
Yes, to be clear, I'm wondering if an easier (and more flexible) path forward might be to generate a |
@gabrielgrant The first priority would be to generate outputs that conform to an industry standard like JSON-schema, as @sinclairzx81 would advocate for. Those integrations can be built into the core package itself. TypeBox may be useful as an intermediate layer to Zod, but that would be a utility package rather than part of the core functionality. |
Yes, that makes sense that you wouldn't want to pull TypeBox in to the core for a long-term solution Mostly was wondering if you have any pointers for where to start poking around the arktype internals to see if this translation (to either TypeBox or JSONSchema directly) is something I might be able to undertake (or just if you'd put any thought to how you'd implement it yet) |
Ahh. It is probably best to hold off on this until I wrap up the beta work I am doing as that node structure will be critical to the compilation process and has changed drastically since alpha. I should at least have a prerelease finished in the next few days that would be stable enough to start working on a TypeBox translation layer if you're interested in working on that then. |
Request a feature
being able to output zod schema will help arktype bootstrap into existing zod ecosystem.
🤷 Motivation
while i love how concise arktype is, i am unable to use it as there is currently no way to generate JSON schema.
💡 Solution
provide
arktypeToZod
function which will convert a arktypetype
into zod schema. This will help arktype's adoptation as now types made from arktype can utilize existing zod to X ecosystem.The text was updated successfully, but these errors were encountered: