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

Can we dynamically generate verification rules in a way similar to json schema? #1050

Open
libondev opened this issue Feb 10, 2025 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@libondev
Copy link

I want to generate a verification object from a serialized object, for example, the following input (which may not be described completely or accurately):

{
  "name": {
    "type": "string",
    "minLength": 2
  },
  "age": {
    "type": "number",
    "minValue": 10
  },
  ...
}

generate a validator with the same effect as the following rules:

v.object({
  name: v.pipe(v.string(), v.minLength(2)),
  age: v.pipe(v.number(), v.minValue(10)),
  email: v.pipe(
    v.string(),
    v.minLength(5),
    v.email(),
    v.endsWith('@example.com')
  )
})
@fabian-hiller fabian-hiller self-assigned this Feb 11, 2025
@fabian-hiller fabian-hiller added the question Further information is requested label Feb 11, 2025
@fabian-hiller
Copy link
Owner

Yes, this is possible, but we haven't implemented it yet. If you are interested, feel free to start it as a community project. The implementation might be similar to our @valibot/to-json-schema package, but in the opposite direction.

You are basically looking for a serialization and deserialization solution for Valibot schemas, if I understand correctly.

@libondev
Copy link
Author

You are basically looking for a serialization and deserialization solution for Valibot schemas, if I understand correctly.

Yes, that's it.

@fabian-hiller
Copy link
Owner

Feel free to keep me posted here if you plan to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants