@@ -100,6 +100,7 @@ export class PrismaSchemaGenerator {
100
100
` ;
101
101
102
102
private mode : 'logical' | 'physical' = 'physical' ;
103
+ private customAttributesAsComments = false ;
103
104
104
105
// a mapping from full names to shortened names
105
106
private shortNameMap = new Map < string , string > ( ) ;
@@ -117,6 +118,14 @@ export class PrismaSchemaGenerator {
117
118
this . mode = options . mode as 'logical' | 'physical' ;
118
119
}
119
120
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
+
120
129
const prismaVersion = getPrismaVersion ( ) ;
121
130
if ( prismaVersion && semver . lt ( prismaVersion , PRISMA_MINIMUM_VERSION ) ) {
122
131
warnings . push (
@@ -284,10 +293,7 @@ export class PrismaSchemaGenerator {
284
293
285
294
// user defined comments pass-through
286
295
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 ) ) ;
291
297
292
298
// generate relation fields on base models linking to concrete models
293
299
this . generateDelegateRelationForBase ( model , decl ) ;
@@ -763,12 +769,8 @@ export class PrismaSchemaGenerator {
763
769
)
764
770
. map ( ( attr ) => this . makeFieldAttribute ( attr ) ) ;
765
771
766
- const nonPrismaAttributes = field . attributes . filter ( ( attr ) => attr . decl . ref && ! this . isPrismaAttribute ( attr ) ) ;
767
-
768
772
// 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 ) ] ;
772
774
const result = model . addField ( field . name , type , attributes , docs , addToFront ) ;
773
775
774
776
if ( this . mode === 'logical' ) {
@@ -900,23 +902,27 @@ export class PrismaSchemaGenerator {
900
902
901
903
// user defined comments pass-through
902
904
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 ) ) ;
907
906
}
908
907
909
908
private generateEnumField ( _enum : PrismaEnum , field : EnumField ) {
910
909
const attributes = field . attributes
911
910
. filter ( ( attr ) => this . isPrismaAttribute ( attr ) )
912
911
. map ( ( attr ) => this . makeFieldAttribute ( attr ) ) ;
913
912
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 ) ] ;
918
914
_enum . addField ( field . name , attributes , docs ) ;
919
915
}
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
+ }
920
926
}
921
927
922
928
function isDescendantOf ( model : DataModel , superModel : DataModel ) : boolean {
0 commit comments