@@ -162,8 +162,7 @@ export default function (userOptions: TSGenOptions) {
162162 op = "[]" ;
163163
164164 if ( field . max_instance ) {
165- const elements = new Array ( field . max_instance ) . fill ( type as any ) ;
166- return [ "[" , elements . join ( ", " ) , "]" ] . join ( "" ) ;
165+ return [ "MaxTuple<" , type , ", " , field . max_instance , ">" ] . join ( "" ) ;
167166 }
168167 }
169168
@@ -215,35 +214,18 @@ export default function (userOptions: TSGenOptions) {
215214 return op_array ( type , field ) ;
216215 }
217216
217+ const handleGlobalField = ( field : ContentstackTypes . Field ) : string => {
218+ const referenceName = name_type ( field . reference_to ) ;
219+ // Return the reference name with array brackets if the field is multiple
220+ return `${ referenceName } ${ field . multiple ? "[]" : "" } ` ;
221+ } ;
222+
223+
218224 function visit_field ( field : ContentstackTypes . Field ) {
219225 let fieldType = "" ;
220226 // Check if the field is a global field
221227 if ( field . data_type === "global_field" ) {
222- // Check if the field is cached
223- const isCached = cachedGlobalFields [ name_type ( field . reference_to ) ] ;
224-
225- // Generate the referred_content_types array
226- const referredContentTypes = [
227- {
228- title : name_type ( field . reference_to ) ,
229- uid : field . reference_to ,
230- } ,
231- ] ;
232-
233- // Assign the new structure for the global field
234- fieldType = `referred_content_types: ${ JSON . stringify (
235- referredContentTypes
236- ) } `;
237-
238- // If it's a multiple field, append '[]' to the fieldType
239- if ( field . multiple ) {
240- fieldType += "[]" ;
241- }
242-
243- // If the field is not cached and there is a reference, update fieldType accordingly
244- if ( ! isCached && field . reference_to ) {
245- fieldType = type_reference ( field ) ;
246- }
228+ fieldType = handleGlobalField ( field ) ;
247229 } else if ( field . data_type === "blocks" ) {
248230 // Handle blocks type (unchanged)
249231 fieldType = type_modular_blocks ( field ) ;
@@ -264,18 +246,17 @@ export default function (userOptions: TSGenOptions) {
264246 : " | null"
265247 : "" ;
266248
267- if ( fieldType . startsWith ( "referred_content_types" ) ) {
268- // For global_field or referred_content_types, omit field.uid in output
269- return `${ fieldType } ` ;
270- }
271249 // Ensure the formatting is correct, and avoid concatenating field.uid directly to a string
272250 return `${ field . uid } ${ requiredFlag } : ${ fieldType } ${ typeModifier } ;` ;
273251 }
274252
275253 function visit_fields ( schema : ContentstackTypes . Schema ) {
276254 return schema
277255 . map ( ( v ) => {
278- return [ options . docgen . field ( v . display_name ) , visit_field ( v ) ]
256+ return [
257+ options . docgen . field ( v . display_name ) ,
258+ visit_field ( v ) ,
259+ ]
279260 . filter ( ( v ) => v )
280261 . join ( "\n" ) ;
281262 } )
0 commit comments