@@ -19,6 +19,44 @@ interface JsDocSchema extends Record<string, unknown> {
1919 maxItems ?: number ;
2020 type ?: string | string [ ] ;
2121 pattern ?: string ;
22+ items ?: JsDocSchema ;
23+ }
24+
25+ interface JsDocEntry {
26+ key : string ;
27+ value : boolean | number | string ;
28+ }
29+
30+ const itemValidationKeys = [
31+ 'minLength' ,
32+ 'maxLength' ,
33+ 'minimum' ,
34+ 'maximum' ,
35+ 'exclusiveMinimum' ,
36+ 'exclusiveMaximum' ,
37+ 'minItems' ,
38+ 'maxItems' ,
39+ 'pattern' ,
40+ ] as const satisfies readonly ( keyof JsDocSchema ) [ ] ;
41+
42+ function getItemValidationDocEntries (
43+ schema ?: JsDocSchema ,
44+ prefix = 'items' ,
45+ ) : JsDocEntry [ ] {
46+ if ( ! schema ) {
47+ return [ ] ;
48+ }
49+
50+ const entries = itemValidationKeys . flatMap ( ( key ) => {
51+ const value = schema [ key ] ;
52+
53+ return value === undefined ? [ ] : [ { key : `${ prefix } .${ key } ` , value } ] ;
54+ } ) ;
55+
56+ return [
57+ ...entries ,
58+ ...getItemValidationDocEntries ( schema . items , `${ prefix } .items` ) ,
59+ ] ;
2260}
2361
2462export function jsDoc (
@@ -49,6 +87,7 @@ export function jsDoc(
4987 const isNullable =
5088 schema . type === 'null' ||
5189 ( Array . isArray ( schema . type ) && schema . type . includes ( 'null' ) ) ;
90+ const itemValidationDocEntries = getItemValidationDocEntries ( schema . items ) ;
5291 // Ensure there aren't any comment terminations in doc
5392 const lines = (
5493 Array . isArray ( description )
@@ -70,6 +109,7 @@ export function jsDoc(
70109 maxItems ?. toString ( ) ,
71110 isNullable ? 'null' : '' ,
72111 pattern ,
112+ ...itemValidationDocEntries . map ( ( { value } ) => value . toString ( ) ) ,
73113 ] . filter ( Boolean ) . length ;
74114
75115 if ( ! count ) {
@@ -131,6 +171,18 @@ export function jsDoc(
131171 tryAppendBooleanDocLine ( 'nullable' , isNullable ) ;
132172 tryAppendStringDocLine ( 'pattern' , pattern ) ;
133173
174+ for ( const { key, value } of itemValidationDocEntries ) {
175+ if ( typeof value === 'string' ) {
176+ tryAppendStringDocLine ( key , value ) ;
177+ continue ;
178+ }
179+ if ( typeof value === 'number' ) {
180+ tryAppendNumberDocLine ( key , value ) ;
181+ continue ;
182+ }
183+ tryAppendBooleanDocLine ( key , value ) ;
184+ }
185+
134186 doc += oneLine ? ' ' : `\n ${ tryOneLine ? ' ' : '' } ` ;
135187
136188 doc += '*/\n' ;
0 commit comments