valibot
valibot copied to clipboard
[Feature Request] Generate Valibot Schema from JSON Schema
I didn't find similar topics, toJSON is more popular I see. But I have a very common use case: when we generated TS API services and models (including json schemas) from OpenAPI spec (using Hey Api for ex), it will be great to have Valibot schemas too.
Is it possible theoretically? Will be awesome to have CLI
Yes, this is possible, but I don't have the time to implement it right now. Are you interested in investigating the implementation of such a package?
I’m interested too, and would be willing to give a try.
Amazing! Do you want to start it as a community project or as an official package of this repo?
Was thinking maybe separate repo until it’s somewhat ready, but I would be more than fine to have it on official repo
You might find inspiration in json-schema-to-zod and other transform.tools.
Thanks, will take a look!
However, my current plan is to output those schemas as a code, so we can generate schemas code, so we don't have to fetch JSON Schema or OpenAPI Declarations to the client
Initial implementation is ready here: https://github.com/muningis/to-valibot. Need to do some more fine tuning, and then we can move it over.
Currently it supports OpenAPI yaml/json declarations and JSON Schema. Unsupported features of schemas:
anyOf/allOf/oneOf/not- discriminated union type arrays
- various formats for string type
Thank you so much! I added a comment to PR #1099
Hi, @mmospanenko. I'm Dosu, and I'm helping the Valibot team manage their backlog. I'm marking this issue as stale.
Issue Summary:
- You suggested adding a feature to generate Valibot schemas from JSON schemas.
- fabian-hiller acknowledged the idea but mentioned a lack of time to implement it.
- muningis expressed interest in developing the feature and started a project at
https://github.com/muningis/to-valibot. - The project supports OpenAPI yaml/json declarations and JSON Schema, with some limitations.
- fabian-hiller appreciated the effort and mentioned it in PR #1099.
Next Steps:
- Please let me know if this issue is still relevant to the latest version of the Valibot repository by commenting here.
- If there is no further activity, this issue will be automatically closed in 30 days.
Thank you for your understanding and contribution!
Sorry guys for long response, I appreciate your involving and quick implementation, and I believe that everything important were covered, I will plan migration and will add some feedback. Thank you so much!