Is there an easy way to enforce the use of actions like title?
#1179
-
|
Ideally I could override/ But alternatively, I haven't found how to crawl the tree of schemas yet to manually validate all my schemas comply with whatever I want to enforce. Though I suppose if I know how the schema objects are structured, I can make a valibot schema for my valibot schemas... 😅 EDIT: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
You could use our new Here is how you can walk your schemas to check for import * as v from 'valibot';
type Schema =
| v.GenericSchema
| v.SchemaWithPipe<
[
v.GenericSchema,
...(v.GenericPipeItem | v.TitleAction<unknown, string>)[],
]
>;
function hasTitle(schema: Schema): boolean {
if ('pipe' in schema) {
for (const item of schema.pipe) {
if (v.isOfKind('schema', item) && 'pipe' in item) {
if (hasTitle(item)) {
return true;
}
} else if (v.isOfKind('metadata', item) && v.isOfType('title', item)) {
return true;
}
}
}
return false;
} |
Beta Was this translation helpful? Give feedback.
You could use our new
getTitlemethod to check if a schema has a title.Here is how you can walk your schemas to check for
title: