-
-
Notifications
You must be signed in to change notification settings - Fork 29
Add json-schema support #118
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
base: 4.x
Are you sure you want to change the base?
Conversation
Hello @kerwanp The high-level approach looks fine to me. However, I will have a few changes.
Also, once we merge this PR, Vine will support JSON schema as a first-class citizen and all custom schema types must implement the |
Also, we should write some tests for the |
Thanks for the feedback! I added support for Concerning the I also started the implementation of integration tests that validate values against the generate json-schema using ajv. This can help use spot issues with the complexity of some generated schemas (tuples, records, etc). What do you think? I we are good with the implementation I will start expanding the test cases, cleaning up my work and add some comments |
Yeah, this seems like a great strategy.
I will be okay with a more generic approach. However, the issue is, how do we know which properties to merge with the JSON schema? |
LIbraries like Zod provide a |
Cool, let's go with that. Maybe people can rely on the JSONschema properties for their other needs as well. |
@kerwanp What are the next steps for this PR? Do you need any feedback from me? |
Hi, I am currently in vacations, will be back the 8th to finish this PR and I think I have all the information required |
π Linked issue
β Type of change
π Description
This feature adds the ability to transform validators to json-schema using the
toJSONSchema
method.This will open a lot of doors for libraries that can build around the json-schema standards (openapi generation, form builder, configuration files, etc).
Implementation
This is currently a draft and serves as an implementation proposal.
The json-schema is generated during the schema validation, allowing the user to retrieve it using
toJSONSchema
.All
ConstructableSchema[PARSE]
method must also return the aJSONSchemaV7
. This is used to build the root of the schema. (e.g https://github.com/kerwanp/vine/blob/4.x/src/schema/base/literal.ts#L583-L583)When creating rules, it is possible to pass an optional parameter for altering the json-schema.
The user is able to provide custom meta that will be merged with the schema to provide custom parameters.
π Checklist