fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6.33k stars 204 forks source link

Error: The "nanoid" action cannot be converted to JSON Schema. #847

Open MentalGear opened 1 month ago

MentalGear commented 1 month ago
Error: The "nanoid" action cannot be converted to JSON Schema.
id: v.pipe(v.string(), v.nanoid('Wrong Nano ID format'))

Is my valibot schema wrong? Otherwise I would expect this to pass since nanoid should be a constraint to string, the actual type is string. So JSONschema conversion should coarse it into a string.

MentalGear commented 1 month ago

Update with Error code. Context: Converting to JSONSchema.

fabian-hiller commented 1 month ago

I suspect that Nano ID is not yet supported by the JSON Schema .format property. Or am I wrong? We could theoretically support it by adding it's regex to the JSON Schema .pattern property, but since Valibot is focused on bundle size, some of our regex use flags. So we can't just copy the regex used in all cases, as regex flags are not supported in JSON Schema as far as I know.

So far we only support common actions, but I plan to support more in the future. Are you interested in helping us implement them? As a workaround, you could force the conversion to ignore the nanoid action.

toJsonSchema(v.pipe(v.string(), v.nanoid()), { force: true });