Closed jhanstra closed 1 month ago
Thanks for your message! We added a v.metadata({ ... })
action in v0.42.0. Feel free to give me feedback about it. https://valibot.dev/api/metadata/
Oh shoot! Sorry for not checking the most recent docs! Wow y'all move fast, I was on 0.39.0. Thank you so much, this looks like what I want - I'll update to that 😄
@fabian-hiller it's not clear how to access the metadata on the schema
Here is an example. See this playground.
import * as v from 'valibot';
const Schema = v.pipe(v.string(), v.description('This is a test'));
const description = Schema.pipe.find(
(item): item is v.DescriptionAction<string, 'This is a test'> =>
item.type === 'description',
)?.description;
Hi there! I've been really loving Valibot but i can't figure out the best way to add unique metadata to a schema. I have at least one use case for this and there are probably many others - mine is that I would like to reuse the schema to determine which React component type to render for an input element, so I want to pass down a
component: 'textarea'
ormultiline: true
property. My understanding ofmetadata
in Valibot as far as I can tell is that the only use case that was imagined was adescription
for the field. And even the API is justv.description()
, notv.metadata()
or similar. I'm wondering if you've had other requests for a true metadata function that anything can be passed into?I did see that you can in fact pass an object into the
v.description()
and it tacks that whole object on, which is a workaround that works. BUT, when I try to use the JSON schema generator in the other package, that breaks since now I have an object as my description instead of just a string. Thoughts?Again thanks so much for all your work on this I'm a big fan!