@@ -449,41 +449,42 @@ async function writeContentFiles({
449
449
for ( const entryKey of Object . keys ( collection . entries ) . sort ( ) ) {
450
450
const dataType = collectionConfig ?. schema ? `InferEntrySchema<${ collectionKey } >` : 'any' ;
451
451
dataTypesStr += `${ entryKey } : {\n id: ${ entryKey } ;\n collection: ${ collectionKey } ;\n data: ${ dataType } \n};\n` ;
452
- if (
453
- settings . config . experimental . contentCollectionJsonSchema &&
454
- collectionConfig ?. schema
455
- ) {
456
- let zodSchemaForJson =
457
- typeof collectionConfig . schema === 'function'
458
- ? collectionConfig . schema ( { image : ( ) => z . string ( ) } )
459
- : collectionConfig . schema ;
460
- if ( zodSchemaForJson instanceof z . ZodObject ) {
461
- zodSchemaForJson = zodSchemaForJson . extend ( {
462
- $schema : z . string ( ) . optional ( ) ,
463
- } ) ;
464
- }
465
- try {
466
- await fs . promises . writeFile (
467
- new URL ( `./${ collectionKey . replace ( / " / g, '' ) } .schema.json` , collectionSchemasDir ) ,
468
- JSON . stringify (
469
- zodToJsonSchema ( zodSchemaForJson , {
470
- name : collectionKey . replace ( / " / g, '' ) ,
471
- markdownDescription : true ,
472
- errorMessages : true ,
473
- } ) ,
474
- null ,
475
- 2
476
- )
477
- ) ;
478
- } catch ( err ) {
479
- logger . warn (
480
- 'content' ,
481
- `An error was encountered while creating the JSON schema for the ${ entryKey } entry in ${ collectionKey } collection. Proceeding without it. Error: ${ err } `
482
- ) ;
483
- }
452
+ dataTypesStr += `};\n` ;
453
+ }
454
+
455
+ if (
456
+ settings . config . experimental . contentCollectionJsonSchema &&
457
+ collectionConfig ?. schema
458
+ ) {
459
+ let zodSchemaForJson =
460
+ typeof collectionConfig . schema === 'function'
461
+ ? collectionConfig . schema ( { image : ( ) => z . string ( ) } )
462
+ : collectionConfig . schema ;
463
+ if ( zodSchemaForJson instanceof z . ZodObject ) {
464
+ zodSchemaForJson = zodSchemaForJson . extend ( {
465
+ $schema : z . string ( ) . optional ( ) ,
466
+ } ) ;
467
+ }
468
+ try {
469
+ await fs . promises . writeFile (
470
+ new URL ( `./${ collectionKey . replace ( / " / g, '' ) } .schema.json` , collectionSchemasDir ) ,
471
+ JSON . stringify (
472
+ zodToJsonSchema ( zodSchemaForJson , {
473
+ name : collectionKey . replace ( / " / g, '' ) ,
474
+ markdownDescription : true ,
475
+ errorMessages : true ,
476
+ } ) ,
477
+ null ,
478
+ 2
479
+ )
480
+ ) ;
481
+ } catch ( err ) {
482
+ logger . warn (
483
+ 'content' ,
484
+ `An error was encountered while creating the JSON schema for the ${ collectionKey } collection. Proceeding without it. Error: ${ err } `
485
+ ) ;
484
486
}
485
487
}
486
- dataTypesStr += `};\n` ;
487
488
break ;
488
489
}
489
490
}
0 commit comments