You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One thing I'm gonna miss once I migrate to Arktype with Zodios is the capability of converting the contract schema to JSON Schema for Swagger and automatically generate an OpenAPI endpoint.
Reacted by David Blass, sam, arjunyel, Nakano as a Service, James, Stephen Haberman, Spence, Nicolas Leal, Gabriel Grant, floratmin and 16 more
👍 ; I need a json schema for a configuration file that I want to have checked/auto-completed in vscode/IDEs, and don't want to write the json schema by hand.
I'd love to use Arktype b/c your schemas are so amazing/succinct, but am currently using zod solely b/c of the zod-to-json-schema capability.
Reacted by rectangulr, Joshua Hernandez and Shane Brinkman-Davis Delamore
Reacted by David Blass, rectangulr and Shane Brinkman-Davis Delamore
@thetayloredman After I finish the props compilation stuff I'm working on this would be doable, which ideally would approximately line up with your work on #802
Curious for an update on this -- iiuc the plan had originally been to do this post 1.0 beta, right? But imagine it got pushed back to accommodate the changes in 2.0 ?
Where do we stand, with that now ready to go? Any thoughts about how to best move forward with this?
FWIW, I love the work you've been doing on AT overall, it looks amazing and I'm super excited to start using it, but some path to getting JSON Schema out is a hard requirement for me (whether that's a native export functionality or via zod or TypeBox (as discussed in #769 ))
Finish remaining 2.0 announced features, generics and matching (mostly done)
Announce 2.0 and spend a bit of time on marketing
Then I'd prioritize the most requested issues which are this and OpenAPI integration. I'd guess maybe in a month or so I might start on this?
If you're interested, this may be fairly tractable for an external contributor now that the internal type system has stabilized and has a clear structure for compilation.
I think the hardest part would be determining which types aren't supported by JSON schema and handling those cases appropriately.
Reacted by Matti Dupre and Shane Brinkman-Davis Delamore
Would love to dive a bit more into what would be needed to add JSON schema support to see if that might be something I could undertake
It seems like the most straightforward way to do this is to just walk a type's AST (myType.flat) and transpile each node to its JSON Schema equivalent (if one exists). For type constraints that aren't perfectly representable, I'm thinking the two options are to either:
output the closest approximation
to just fail loudly.
Probably the 2. should be the default (as it is safer), with the 1. as an opt-in option? (but thinking it would be reasonable to only do 2. for an initial implementation?)
@gabrielgrant Yes I agree it should just fail for now on anything JSON schema doesn't represent.
That said, it should definitely be built on top of 2.0, and there have been huge changes to the type system since then (which I think should make stuff like this much easier).
Probably the easiest way to go over context would be to hop on a call for 15-30 minutes so I can go over the structure of the type system and we can talk about approaches for integrating it.
It may be beneficial for popularity now: openai uses json schema for defining structured output, starting today. They used Zod and zod-to-json-schema by default for their JS api.
Reacted by Luca Schultz and Shane Brinkman-Davis Delamore
Reacted by Marvin ROGER, Stephen Haberman, Luca Schultz, Atul R, Zisu Zhang, Shane Brinkman-Davis Delamore, B. Cedric Cogell, Aiden Liu, Husky and Merlin
Reacted by Marvin ROGER, Igor Loskutov, Luca Schultz, Atul R, Shane Brinkman-Davis Delamore, Gary Becks, Andreas Söderlund, B. Cedric Cogell and Merlin
As I'm using the JSON Schema to generate default values, it would be great if you could supply some options to the toJsonSchema method, for example a callback that can manage unsupported types.
Activity
stephenh commentedon Nov 11, 2023
👍 ; I need a json schema for a configuration file that I want to have checked/auto-completed in vscode/IDEs, and don't want to write the json schema by hand.
I'd love to use Arktype b/c your schemas are so amazing/succinct, but am currently using zod solely b/c of the zod-to-json-schema capability.
ssalbdivad commentedon Nov 11, 2023
Thanks for the feedback. This will definitely be one of the first things we prioritize in beta given how much interest there is.
floratmin commentedon Dec 12, 2023
This would also allow to use something like
fast-json-stringifyfor fast serialization.thetayloredman commentedon Jan 21, 2024
@ssalbdivad I would be interested in taking a stab at this when you believe it's ready to approach—along with its inverse (JSON Schema to AT)
ssalbdivad commentedon Jan 21, 2024
@thetayloredman After I finish the props compilation stuff I'm working on this would be doable, which ideally would approximately line up with your work on #802
gabrielgrant commentedon May 17, 2024
Curious for an update on this -- iiuc the plan had originally been to do this post 1.0 beta, right? But imagine it got pushed back to accommodate the changes in 2.0 ?
Where do we stand, with that now ready to go? Any thoughts about how to best move forward with this?
FWIW, I love the work you've been doing on AT overall, it looks amazing and I'm super excited to start using it, but some path to getting JSON Schema out is a hard requirement for me (whether that's a native export functionality or via zod or TypeBox (as discussed in #769 ))
ssalbdivad commentedon May 17, 2024
@gabrielgrant My current priorities are:
Then I'd prioritize the most requested issues which are this and OpenAPI integration. I'd guess maybe in a month or so I might start on this?
If you're interested, this may be fairly tractable for an external contributor now that the internal type system has stabilized and has a clear structure for compilation.
I think the hardest part would be determining which types aren't supported by JSON schema and handling those cases appropriately.
gabrielgrant commentedon May 22, 2024
Moving from discord...
Would love to dive a bit more into what would be needed to add JSON schema support to see if that might be something I could undertake
It seems like the most straightforward way to do this is to just walk a type's AST (
myType.flat) and transpile each node to its JSON Schema equivalent (if one exists). For type constraints that aren't perfectly representable, I'm thinking the two options are to either:Probably the 2. should be the default (as it is safer), with the 1. as an opt-in option? (but thinking it would be reasonable to only do 2. for an initial implementation?)
ssalbdivad commentedon May 22, 2024
@gabrielgrant Yes I agree it should just fail for now on anything JSON schema doesn't represent.
That said, it should definitely be built on top of 2.0, and there have been huge changes to the type system since then (which I think should make stuff like this much easier).
Probably the easiest way to go over context would be to hop on a call for 15-30 minutes so I can go over the structure of the type system and we can talk about approaches for integrating it.
ssalbdivad commentedon Jun 4, 2024
@gabrielgrant Just wanted to check in if you're still working on this?
No pressure, if not I may have someone else interested in tackling it.
dearlordylord commentedon Aug 7, 2024
It may be beneficial for popularity now: openai uses json schema for defining structured output, starting today. They used Zod and zod-to-json-schema by default for their JS api.
ssalbdivad commentedon Aug 19, 2024
This feature was added in
2.0.0-beta.6From the release notes:
Convert a Type instance to an equivalent JSON Schema. Will throw a ParseError if the Type contains constraints not supported by JSON Schema or morphs.
{ "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "number" } }, "required": ["name"] }ciscoheat commentedon Dec 15, 2024
As I'm using the JSON Schema to generate default values, it would be great if you could supply some options to the
toJsonSchemamethod, for example a callback that can manage unsupported types.ssalbdivad commentedon Dec 16, 2024
@ciscoheat Yeah this would definitely be useful. If you're able to create a separate issue, that would be a big help for tracking!