@@ -100,6 +100,7 @@ export class PrismaSchemaGenerator {
100100` ;
101101
102102 private mode : 'logical' | 'physical' = 'physical' ;
103+ private customAttributesAsComments = false ;
103104
104105 // a mapping from full names to shortened names
105106 private shortNameMap = new Map < string , string > ( ) ;
@@ -117,6 +118,14 @@ export class PrismaSchemaGenerator {
117118 this . mode = options . mode as 'logical' | 'physical' ;
118119 }
119120
121+ if (
122+ options . customAttributesAsComments !== undefined &&
123+ typeof options . customAttributesAsComments !== 'boolean'
124+ ) {
125+ throw new PluginError ( name , 'option "customAttributesAsComments" must be a boolean' ) ;
126+ }
127+ this . customAttributesAsComments = options . customAttributesAsComments === true ;
128+
120129 const prismaVersion = getPrismaVersion ( ) ;
121130 if ( prismaVersion && semver . lt ( prismaVersion , PRISMA_MINIMUM_VERSION ) ) {
122131 warnings . push (
@@ -284,10 +293,7 @@ export class PrismaSchemaGenerator {
284293
285294 // user defined comments pass-through
286295 decl . comments . forEach ( ( c ) => model . addComment ( c ) ) ;
287-
288- decl . attributes
289- . filter ( ( attr ) => attr . decl . ref && ! this . isPrismaAttribute ( attr ) )
290- . forEach ( ( attr ) => model . addComment ( '/// - _' + this . zModelGenerator . generate ( attr ) + '_' ) ) ;
296+ this . getCustomAttributesAsComments ( decl ) . forEach ( ( c ) => model . addComment ( c ) ) ;
291297
292298 // generate relation fields on base models linking to concrete models
293299 this . generateDelegateRelationForBase ( model , decl ) ;
@@ -763,12 +769,8 @@ export class PrismaSchemaGenerator {
763769 )
764770 . map ( ( attr ) => this . makeFieldAttribute ( attr ) ) ;
765771
766- const nonPrismaAttributes = field . attributes . filter ( ( attr ) => attr . decl . ref && ! this . isPrismaAttribute ( attr ) ) ;
767-
768772 // user defined comments pass-through
769- const docs : string [ ] = [ ...field . comments ] ;
770- docs . push ( ...nonPrismaAttributes . map ( ( attr ) => '/// - _' + this . zModelGenerator . generate ( attr ) + '_' ) ) ;
771-
773+ const docs = [ ...field . comments , ...this . getCustomAttributesAsComments ( field ) ] ;
772774 const result = model . addField ( field . name , type , attributes , docs , addToFront ) ;
773775
774776 if ( this . mode === 'logical' ) {
@@ -900,23 +902,27 @@ export class PrismaSchemaGenerator {
900902
901903 // user defined comments pass-through
902904 decl . comments . forEach ( ( c ) => _enum . addComment ( c ) ) ;
903-
904- decl . attributes
905- . filter ( ( attr ) => attr . decl . ref && ! this . isPrismaAttribute ( attr ) )
906- . forEach ( ( attr ) => _enum . addComment ( '/// - _' + this . zModelGenerator . generate ( attr ) + '_' ) ) ;
905+ this . getCustomAttributesAsComments ( decl ) . forEach ( ( c ) => _enum . addComment ( c ) ) ;
907906 }
908907
909908 private generateEnumField ( _enum : PrismaEnum , field : EnumField ) {
910909 const attributes = field . attributes
911910 . filter ( ( attr ) => this . isPrismaAttribute ( attr ) )
912911 . map ( ( attr ) => this . makeFieldAttribute ( attr ) ) ;
913912
914- const nonPrismaAttributes = field . attributes . filter ( ( attr ) => attr . decl . ref && ! this . isPrismaAttribute ( attr ) ) ;
915-
916- const docs = [ ...field . comments ] ;
917- docs . push ( ...nonPrismaAttributes . map ( ( attr ) => '/// - _' + this . zModelGenerator . generate ( attr ) + '_' ) ) ;
913+ const docs = [ ...field . comments , ...this . getCustomAttributesAsComments ( field ) ] ;
918914 _enum . addField ( field . name , attributes , docs ) ;
919915 }
916+
917+ private getCustomAttributesAsComments ( decl : DataModel | DataModelField | Enum | EnumField ) {
918+ if ( ! this . customAttributesAsComments ) {
919+ return [ ] ;
920+ } else {
921+ return decl . attributes
922+ . filter ( ( attr ) => attr . decl . ref && ! this . isPrismaAttribute ( attr ) )
923+ . map ( ( attr ) => `/// ${ this . zModelGenerator . generate ( attr ) } ` ) ;
924+ }
925+ }
920926}
921927
922928function isDescendantOf ( model : DataModel , superModel : DataModel ) : boolean {
0 commit comments