@@ -4,6 +4,7 @@ use std::path::PathBuf;
44use anyhow:: { Context , Result } ;
55use clap:: Parser ;
66use schemars:: schema_for;
7+ use vespertide_config:: VespertideConfig ;
78use vespertide_core:: { MigrationPlan , TableDef } ;
89
910#[ derive( Debug , Parser ) ]
@@ -29,9 +30,11 @@ fn run(out: PathBuf) -> Result<()> {
2930
3031 let model_schema = schema_for ! ( TableDef ) ;
3132 let migration_schema = schema_for ! ( MigrationPlan ) ;
33+ let config_schema = schema_for ! ( VespertideConfig ) ;
3234
3335 let model_path = out. join ( "model.schema.json" ) ;
3436 let migration_path = out. join ( "migration.schema.json" ) ;
37+ let config_path = out. join ( "config.schema.json" ) ;
3538
3639 fs:: write (
3740 & model_path,
@@ -45,9 +48,16 @@ fn run(out: PathBuf) -> Result<()> {
4548 )
4649 . with_context ( || format ! ( "write {}" , migration_path. display( ) ) ) ?;
4750
51+ fs:: write (
52+ & config_path,
53+ serde_json:: to_string_pretty ( & config_schema) . context ( "serialize config schema" ) ?,
54+ )
55+ . with_context ( || format ! ( "write {}" , config_path. display( ) ) ) ?;
56+
4857 println ! ( "Wrote schemas:" ) ;
4958 println ! ( " {}" , model_path. display( ) ) ;
5059 println ! ( " {}" , migration_path. display( ) ) ;
60+ println ! ( " {}" , config_path. display( ) ) ;
5161 Ok ( ( ) )
5262}
5363
@@ -98,24 +108,28 @@ mod tests {
98108 }
99109
100110 #[ test]
101- fn run_generates_both_schema_files ( ) {
111+ fn run_generates_all_schema_files ( ) {
102112 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
103113 let out = temp_dir. path ( ) ;
104114
105115 run ( out. to_path_buf ( ) ) . unwrap ( ) ;
106116
107117 let model_path = out. join ( "model.schema.json" ) ;
108118 let migration_path = out. join ( "migration.schema.json" ) ;
119+ let config_path = out. join ( "config.schema.json" ) ;
109120
110121 assert ! ( model_path. exists( ) ) ;
111122 assert ! ( migration_path. exists( ) ) ;
123+ assert ! ( config_path. exists( ) ) ;
112124
113125 // Verify files are valid JSON
114126 let model_content = fs:: read_to_string ( & model_path) . unwrap ( ) ;
115127 let migration_content = fs:: read_to_string ( & migration_path) . unwrap ( ) ;
128+ let config_content = fs:: read_to_string ( & config_path) . unwrap ( ) ;
116129
117130 serde_json:: from_str :: < serde_json:: Value > ( & model_content) . unwrap ( ) ;
118131 serde_json:: from_str :: < serde_json:: Value > ( & migration_content) . unwrap ( ) ;
132+ serde_json:: from_str :: < serde_json:: Value > ( & config_content) . unwrap ( ) ;
119133 }
120134
121135 #[ test]
@@ -132,7 +146,25 @@ mod tests {
132146
133147 let model_path = out. join ( "model.schema.json" ) ;
134148 let migration_path = out. join ( "migration.schema.json" ) ;
149+ let config_path = out. join ( "config.schema.json" ) ;
135150 assert ! ( model_path. exists( ) ) ;
136151 assert ! ( migration_path. exists( ) ) ;
152+ assert ! ( config_path. exists( ) ) ;
153+ }
154+
155+ #[ test]
156+ fn run_generates_config_schema_file ( ) {
157+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
158+ let out = temp_dir. path ( ) ;
159+
160+ run ( out. to_path_buf ( ) ) . unwrap ( ) ;
161+
162+ let config_path = out. join ( "config.schema.json" ) ;
163+ assert ! ( config_path. exists( ) ) ;
164+
165+ let content = fs:: read_to_string ( & config_path) . unwrap ( ) ;
166+ assert ! ( content. contains( "VespertideConfig" ) ) ;
167+ assert ! ( content. contains( "modelsDir" ) ) ;
168+ assert ! ( content. contains( "migrationsDir" ) ) ;
137169 }
138170}
0 commit comments