@@ -67,7 +67,9 @@ function generateMockValue(type: string, _description?: string, fieldName?: stri
6767}
6868
6969/**
70- * Recursively processes nested output structures
70+ * Recursively processes nested output structures, expanding JSON-Schema-style
71+ * objects/arrays that define `properties` or `items` instead of returning
72+ * a generic placeholder.
7173 */
7274function processOutputField ( key : string , field : unknown , depth = 0 , maxDepth = 10 ) : unknown {
7375 if ( depth > maxDepth ) {
@@ -80,7 +82,30 @@ function processOutputField(key: string, field: unknown, depth = 0, maxDepth = 1
8082 'type' in field &&
8183 typeof ( field as Record < string , unknown > ) . type === 'string'
8284 ) {
83- const typedField = field as { type : string ; description ?: string }
85+ const typedField = field as {
86+ type : string
87+ description ?: string
88+ properties ?: Record < string , unknown >
89+ items ?: unknown
90+ }
91+
92+ if (
93+ ( typedField . type === 'object' || typedField . type === 'json' ) &&
94+ typedField . properties &&
95+ typeof typedField . properties === 'object'
96+ ) {
97+ const nestedObject : Record < string , unknown > = { }
98+ for ( const [ nestedKey , nestedField ] of Object . entries ( typedField . properties ) ) {
99+ nestedObject [ nestedKey ] = processOutputField ( nestedKey , nestedField , depth + 1 , maxDepth )
100+ }
101+ return nestedObject
102+ }
103+
104+ if ( typedField . type === 'array' && typedField . items && typeof typedField . items === 'object' ) {
105+ const itemValue = processOutputField ( `${ key } _item` , typedField . items , depth + 1 , maxDepth )
106+ return [ itemValue ]
107+ }
108+
84109 return generateMockValue ( typedField . type , typedField . description , key )
85110 }
86111
0 commit comments