11// cargo run --example gen_svc --release
22// https://github.com/Azure/azure-rest-api-specs/blob/master/specification/batch/data-plane
3- use autorust_codegen:: {
4- self , cargo_toml,
5- config_parser:: { to_mod_name, to_tag_name} ,
6- get_svc_readmes, lib_rs, path, Config , PropertyName , SpecReadme ,
7- } ;
3+ use autorust_codegen:: { self , cargo_toml, get_svc_readmes, lib_rs, path, Config , PropertyName , SpecReadme } ;
84use std:: { collections:: HashSet , fs, path:: PathBuf } ;
95
106const OUTPUT_FOLDER : & str = "../svc" ;
@@ -22,11 +18,11 @@ const SKIP_SERVICES: &[&str] = &[
2218const SKIP_SERVICE_TAGS : & [ ( & str , & str ) ] = & [
2319 ( "agrifood" , "package-2021-03-31-preview" ) , // duplicate params https://github.com/Azure/azure-sdk-for-rust/issues/501
2420 ( "purview" , "package-2021-05-01-preview" ) , // need to box types
25- ( "maps" , "package-preview-2_0 " ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
26- ( "maps" , "package-1_0 -preview" ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
27- ( "servicefabric" , "6_2 " ) , // invalid model TimeBasedBackupScheduleDescription
28- ( "servicefabric" , "6_3 " ) , // invalid model TimeBasedBackupScheduleDescription
29- ( "servicefabric" , "6_4 " ) , // invalid model TimeBasedBackupScheduleDescription
21+ ( "maps" , "package-preview-2.0 " ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
22+ ( "maps" , "package-1.0 -preview" ) , // global responses https://github.com/Azure/azure-sdk-for-rust/issues/502
23+ ( "servicefabric" , "6.2 " ) , // invalid model TimeBasedBackupScheduleDescription
24+ ( "servicefabric" , "6.3 " ) , // invalid model TimeBasedBackupScheduleDescription
25+ ( "servicefabric" , "6.4 " ) , // invalid model TimeBasedBackupScheduleDescription
3026 ( "storagedatalake" , "package-2018-11" ) , // "invalid value: string \"ErrorResponse\", expected length 3"
3127 ( "storagedatalake" , "package-2018-06-preview" ) ,
3228 ( "storagedatalake" , "package-2019-10" ) ,
@@ -201,11 +197,9 @@ fn main() -> Result<()> {
201197
202198fn gen_crate ( spec : & SpecReadme ) -> Result < ( ) > {
203199 let skip_service_tags: HashSet < & ( & str , & str ) > = SKIP_SERVICE_TAGS . iter ( ) . collect ( ) ;
204- let has_no_configs = spec
205- . configs ( ) ?
206- . iter ( )
207- . all ( |x| skip_service_tags. contains ( & ( spec. spec ( ) , x. tag . as_str ( ) ) ) ) ;
208- if has_no_configs {
200+ let config = spec. config ( ) ?;
201+ let has_no_tags = config. tags ( ) . iter ( ) . all ( |x| skip_service_tags. contains ( & ( spec. spec ( ) , x. name ( ) ) ) ) ;
202+ if has_no_tags {
209203 println ! ( "not generating {}" , spec. spec( ) ) ;
210204 return Ok ( ( ) ) ;
211205 }
@@ -219,7 +213,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
219213 fs:: remove_dir_all ( & src_folder) . map_err ( |source| Error :: IoError { source } ) ?;
220214 }
221215
222- let mut feature_mod_names = Vec :: new ( ) ;
216+ let mut tags = Vec :: new ( ) ;
223217
224218 let mut fix_case_properties = HashSet :: new ( ) ;
225219 for spec_title in FIX_CASE_PROPERTIES {
@@ -244,30 +238,22 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
244238 } ) ;
245239 }
246240
247- for config in spec . configs ( ) ? {
248- let tag = to_tag_name ( config . tag . as_str ( ) ) ;
249- if skip_service_tags. contains ( & ( spec. spec ( ) , tag . as_ref ( ) ) ) {
241+ for tag in config . tags ( ) {
242+ let tag_name = tag. name ( ) ;
243+ if skip_service_tags. contains ( & ( spec. spec ( ) , tag_name . as_ref ( ) ) ) {
250244 // println!(" skipping {}", tag);
251245 continue ;
252246 }
253- println ! ( " {}" , tag ) ;
254- let mod_name = to_mod_name ( & tag) ;
247+ println ! ( " {}" , tag_name ) ;
248+ let mod_name = tag. rust_mod_name ( ) ;
255249 let mod_output_folder = path:: join ( & src_folder, & mod_name) . map_err ( |source| Error :: PathError { source } ) ?;
256- feature_mod_names. push ( ( tag, mod_name) ) ;
257- // println!(" {}", mod_name);
258- // println!(" {:?}", mod_output_folder);
259- // for input_file in &config.input_files {
260- // println!(" {}", input_file);
261- // }
262- let input_files: Result < Vec < _ > > = config
263- . input_files
250+ tags. push ( tag) ;
251+ let input_files: Result < Vec < _ > > = tag
252+ . input_files ( )
264253 . iter ( )
265254 . map ( |input_file| path:: join ( spec. readme ( ) , input_file) . map_err ( |source| Error :: PathError { source } ) )
266255 . collect ( ) ;
267256 let input_files = input_files?;
268- // for input_file in &input_files {
269- // println!(" {:?}", input_file);
270- // }
271257 autorust_codegen:: run ( Config {
272258 output_folder : mod_output_folder,
273259 input_files,
@@ -278,17 +264,18 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
278264 ..Config :: default ( )
279265 } ) ?;
280266 }
281- if feature_mod_names . is_empty ( ) {
267+ if tags . is_empty ( ) {
282268 return Ok ( ( ) ) ;
283269 }
284270 cargo_toml:: create (
285271 crate_name,
286- & feature_mod_names,
272+ & tags,
273+ config. tag ( ) ,
287274 & path:: join ( output_folder, "Cargo.toml" ) . map_err ( |source| Error :: PathError { source } ) ?,
288275 )
289276 . map_err ( |source| Error :: CargoTomlError { source } ) ?;
290277 lib_rs:: create (
291- & feature_mod_names ,
278+ & tags ,
292279 & path:: join ( src_folder, "lib.rs" ) . map_err ( |source| Error :: PathError { source } ) ?,
293280 false ,
294281 )
0 commit comments