valibot icon indicating copy to clipboard operation
valibot copied to clipboard

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

Open MentalGear opened this issue 1 year ago • 2 comments

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 avatar Sep 23 '24 15:09 MentalGear

Update with Error code. Context: Converting to JSONSchema.

MentalGear avatar Sep 23 '24 15:09 MentalGear

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 });

fabian-hiller avatar Sep 23 '24 20:09 fabian-hiller

v1.0.0-beta.4 of @valibot/to-json-schema is available

fabian-hiller avatar Jan 08 '25 23:01 fabian-hiller

thx!

MentalGear avatar Jan 09 '25 07:01 MentalGear