@@ -68,25 +68,27 @@ export const descriptionSchema = z
6868export const urlSchema = z . string ( ) . url ( ) . meta ( { title : 'URL' } ) ;
6969
7070/** Schema for a docsUrl */
71- export const docsUrlSchema = urlSchema
71+ export const docsUrlSchema = z
72+ . union ( [
73+ z . literal ( '' ) ,
74+ // eslint-disable-next-line unicorn/prefer-top-level-await
75+ z
76+ . string ( )
77+ . url ( )
78+ . catch ( error => {
79+ // if only URL validation fails, supress error since this metadata is optional anyway
80+ if (
81+ error . issues . length === 1 &&
82+ error . issues [ 0 ] ?. code === 'invalid_format' &&
83+ ( error . issues [ 0 ] as ZodIssue & { format ?: string } ) . format === 'url'
84+ ) {
85+ console . warn ( `Ignoring invalid docsUrl: ${ error . value } ` ) ;
86+ return '' ;
87+ }
88+ throw new ZodError ( error . error . issues ) ;
89+ } ) ,
90+ ] )
7291 . optional ( )
73- . or ( z . literal ( '' ) ) // allow empty string (no URL validation)
74- // eslint-disable-next-line unicorn/prefer-top-level-await, unicorn/catch-error-name
75- . catch ( ctx => {
76- // if only URL validation fails, supress error since this metadata is optional anyway
77- if (
78- ctx . issues . length === 1 &&
79- ( ctx . issues [ 0 ] ?. errors as ZodIssue [ ] [ ] )
80- . flat ( )
81- . some (
82- error => error . code === 'invalid_format' && error . format === 'url' ,
83- )
84- ) {
85- console . warn ( `Ignoring invalid docsUrl: ${ ctx . value } ` ) ;
86- return '' ;
87- }
88- throw new ZodError ( ctx . error . issues ) ;
89- } )
9092 . meta ( { title : 'DocsUrl' , description : 'Documentation site' } ) ;
9193
9294/** Schema for a title of a plugin, category and audit */
0 commit comments