@@ -107,6 +107,13 @@ pub fn render_entity_with_config(
107107 . collect ( ) ;
108108 model_derives. extend ( extra_model_derives) ;
109109
110+ // Add table description as doc comment
111+ if let Some ( ref desc) = table. description {
112+ for line in desc. lines ( ) {
113+ lines. push ( format ! ( "/// {}" , line) ) ;
114+ }
115+ }
116+
110117 lines. push ( "#[sea_orm::model]" . into ( ) ) ;
111118 lines. push ( format ! ( "#[derive({})]" , model_derives. join( ", " ) ) ) ;
112119 lines. push ( format ! ( "#[sea_orm(table_name = \" {}\" )]" , table. name) ) ;
@@ -178,6 +185,13 @@ fn render_column(
178185 let is_indexed = indexed_columns. contains ( & column. name ) ;
179186 let has_default = column. default . is_some ( ) ;
180187
188+ // Add column comment as doc comment
189+ if let Some ( ref comment) = column. comment {
190+ for line in comment. lines ( ) {
191+ lines. push ( format ! ( " /// {}" , line) ) ;
192+ }
193+ }
194+
181195 // Build attribute parts
182196 let mut attrs: Vec < String > = Vec :: new ( ) ;
183197
@@ -2854,4 +2868,94 @@ mod tests {
28542868 // Should NOT contain vespera::Schema since we explicitly set empty
28552869 assert ! ( !result. contains( "vespera::Schema" ) ) ;
28562870 }
2871+
2872+ #[ test]
2873+ fn test_doc_comments_from_description_and_comment ( ) {
2874+ use vespertide_core:: schema:: primary_key:: PrimaryKeySyntax ;
2875+
2876+ let table = TableDef {
2877+ name : "users" . into ( ) ,
2878+ description : Some ( "User account information table" . into ( ) ) ,
2879+ columns : vec ! [
2880+ ColumnDef {
2881+ name: "id" . into( ) ,
2882+ r#type: ColumnType :: Simple ( SimpleColumnType :: Integer ) ,
2883+ nullable: false ,
2884+ default : None ,
2885+ comment: Some ( "Unique user identifier" . into( ) ) ,
2886+ primary_key: Some ( PrimaryKeySyntax :: Bool ( true ) ) ,
2887+ unique: None ,
2888+ index: None ,
2889+ foreign_key: None ,
2890+ } ,
2891+ ColumnDef {
2892+ name: "email" . into( ) ,
2893+ r#type: ColumnType :: Simple ( SimpleColumnType :: Text ) ,
2894+ nullable: false ,
2895+ default : None ,
2896+ comment: Some ( "User's email address for login" . into( ) ) ,
2897+ primary_key: None ,
2898+ unique: None ,
2899+ index: None ,
2900+ foreign_key: None ,
2901+ } ,
2902+ ColumnDef {
2903+ name: "name" . into( ) ,
2904+ r#type: ColumnType :: Simple ( SimpleColumnType :: Text ) ,
2905+ nullable: true ,
2906+ default : None ,
2907+ comment: None , // No comment
2908+ primary_key: None ,
2909+ unique: None ,
2910+ index: None ,
2911+ foreign_key: None ,
2912+ } ,
2913+ ] ,
2914+ constraints : vec ! [ ] ,
2915+ } ;
2916+
2917+ let rendered = render_entity ( & table) ;
2918+
2919+ // Check table description as doc comment
2920+ assert ! ( rendered. contains( "/// User account information table" ) ) ;
2921+
2922+ // Check column comments as doc comments
2923+ assert ! ( rendered. contains( "/// Unique user identifier" ) ) ;
2924+ assert ! ( rendered. contains( "/// User's email address for login" ) ) ;
2925+
2926+ // name column has no comment, so no doc comment for it
2927+ assert ! ( !rendered. contains( "/// name" ) ) ;
2928+ }
2929+
2930+ #[ test]
2931+ fn test_multiline_doc_comments ( ) {
2932+ use vespertide_core:: schema:: primary_key:: PrimaryKeySyntax ;
2933+
2934+ let table = TableDef {
2935+ name : "posts" . into ( ) ,
2936+ description : Some ( "Blog posts table\n Contains all user-submitted content" . into ( ) ) ,
2937+ columns : vec ! [ ColumnDef {
2938+ name: "content" . into( ) ,
2939+ r#type: ColumnType :: Simple ( SimpleColumnType :: Text ) ,
2940+ nullable: false ,
2941+ default : None ,
2942+ comment: Some ( "Post content body\n Supports markdown format" . into( ) ) ,
2943+ primary_key: Some ( PrimaryKeySyntax :: Bool ( true ) ) ,
2944+ unique: None ,
2945+ index: None ,
2946+ foreign_key: None ,
2947+ } ] ,
2948+ constraints : vec ! [ ] ,
2949+ } ;
2950+
2951+ let rendered = render_entity ( & table) ;
2952+
2953+ // Check multiline table description
2954+ assert ! ( rendered. contains( "/// Blog posts table" ) ) ;
2955+ assert ! ( rendered. contains( "/// Contains all user-submitted content" ) ) ;
2956+
2957+ // Check multiline column comment
2958+ assert ! ( rendered. contains( "/// Post content body" ) ) ;
2959+ assert ! ( rendered. contains( "/// Supports markdown format" ) ) ;
2960+ }
28572961}
0 commit comments