Skip to content

Commit 9243927

Browse files
cataggarctaggart
andauthored
use Basic Information tag for default version (#675)
Co-authored-by: Cameron Taggart <cameron.taggart@gmail.com>
1 parent f105544 commit 9243927

File tree

70 files changed

+287
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+287
-205
lines changed

services/autorust/codegen/examples/gen_mgmt.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
// cargo run --example gen_mgmt --release
22
// https://github.com/Azure/azure-rest-api-specs/blob/master/specification/compute/resource-manager
3-
use autorust_codegen::{
4-
self, cargo_toml,
5-
config_parser::{to_mod_name, to_tag_name},
6-
get_mgmt_readmes, lib_rs, path, Config, PropertyName, SpecReadme,
7-
};
3+
use autorust_codegen::{self, cargo_toml, get_mgmt_readmes, lib_rs, path, Config, PropertyName, SpecReadme};
84
use std::{collections::HashSet, fs, path::PathBuf};
95

106
const OUTPUT_FOLDER: &str = "../mgmt";
@@ -195,6 +191,7 @@ const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
195191
("../../../azure-rest-api-specs/specification/dataprotection/resource-manager/Microsoft.DataProtection/stable/2022-01-01/dataprotection.json", "InnerError", "embeddedInnerError"),
196192
// hardwaresecuritymodels
197193
("../../../azure-rest-api-specs/specification/hardwaresecuritymodules/resource-manager/Microsoft.HardwareSecurityModules/preview/2018-10-31-preview/dedicatedhsm.json", "Error", "innererror"),
194+
("../../../azure-rest-api-specs/specification/hardwaresecuritymodules/resource-manager/Microsoft.HardwareSecurityModules/stable/2021-11-30/dedicatedhsm.json", "Error", "innererror"),
198195
// logic
199196
("../../../azure-rest-api-specs/specification/logic/resource-manager/Microsoft.Logic/stable/2019-05-01/logic.json", "SwaggerSchema", "items"),
200197
// migrateprojects
@@ -339,7 +336,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
339336
fs::remove_dir_all(&src_folder).map_err(|source| Error::IoError { source })?;
340337
}
341338

342-
let mut feature_mod_names = Vec::new();
339+
let mut tags = Vec::new();
343340
let skip_service_tags: HashSet<&(&str, &str)> = SKIP_SERVICE_TAGS.iter().collect();
344341

345342
let mut box_properties = HashSet::new();
@@ -360,31 +357,22 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
360357
});
361358
}
362359

363-
for config in spec.configs()? {
364-
let tag = to_tag_name(&config.tag);
365-
if skip_service_tags.contains(&(spec.spec(), tag.as_ref())) {
366-
println!(" skipping {}", tag);
360+
let config = spec.config()?;
361+
for tag in config.tags() {
362+
let tag_name = tag.name();
363+
if skip_service_tags.contains(&(spec.spec(), tag_name.as_ref())) {
364+
// println!(" skipping {}", tag_name);
367365
continue;
368366
}
369-
println!(" {}", tag);
370-
// println!(" {}", api_version);
371-
let mod_name = to_mod_name(&tag);
372-
let mod_output_folder = path::join(&src_folder, &mod_name).map_err(|source| Error::PathError { source })?;
373-
feature_mod_names.push((tag, mod_name));
374-
// println!(" {}", mod_name);
375-
// println!(" {:?}", mod_output_folder);
376-
// for input_file in &config.input_files {
377-
// println!(" {}", input_file);
378-
// }
379-
let input_files: Result<Vec<_>> = config
380-
.input_files
367+
println!(" {}", tag_name);
368+
let mod_output_folder = path::join(&src_folder, &tag.rust_mod_name()).map_err(|source| Error::PathError { source })?;
369+
tags.push(tag);
370+
let input_files: Result<Vec<_>> = tag
371+
.input_files()
381372
.iter()
382373
.map(|input_file| path::join(spec.readme(), input_file).map_err(|source| Error::PathError { source }))
383374
.collect();
384375
let input_files = input_files?;
385-
// for input_file in &input_files {
386-
// println!(" {:?}", input_file);
387-
// }
388376
autorust_codegen::run(Config {
389377
output_folder: mod_output_folder,
390378
input_files,
@@ -394,17 +382,18 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
394382
..Config::default()
395383
})?;
396384
}
397-
if feature_mod_names.is_empty() {
385+
if tags.is_empty() {
398386
return Ok(());
399387
}
400388
cargo_toml::create(
401389
crate_name,
402-
&feature_mod_names,
390+
&tags,
391+
config.tag(),
403392
&path::join(output_folder, "Cargo.toml").map_err(|source| Error::PathError { source })?,
404393
)
405394
.map_err(|source| Error::CargoTomlError { source })?;
406395
lib_rs::create(
407-
&feature_mod_names,
396+
&tags,
408397
&path::join(src_folder, "lib.rs").map_err(|source| Error::PathError { source })?,
409398
false,
410399
)

services/autorust/codegen/examples/gen_svc.rs

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
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};
84
use std::{collections::HashSet, fs, path::PathBuf};
95

106
const OUTPUT_FOLDER: &str = "../svc";
@@ -22,11 +18,11 @@ const SKIP_SERVICES: &[&str] = &[
2218
const 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

202198
fn 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
)

services/autorust/codegen/examples/mgmt_tags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ fn main() -> Result<()> {
88
let mut tag_count = 0;
99
for (i, spec) in get_mgmt_readmes()?.iter().enumerate() {
1010
println!("{} {}", i + 1, spec.spec());
11-
for config in spec.configs()? {
12-
println!(" {}", &config.tag);
13-
for input_file in &config.input_files {
11+
for tag in spec.config()?.tags() {
12+
println!(" {}", &tag.tag);
13+
for input_file in &tag.input_files {
1414
println!(" {}", input_file);
1515
}
1616
tag_count += 1;

services/autorust/codegen/examples/multiple_versions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ fn check(readmes: &[SpecReadme]) -> Result<()> {
2222
let mut tags = 0;
2323
for readme in readmes {
2424
let readme_path = readme.readme();
25-
for config in readme.configs()? {
26-
let input_files = path::join_several(readme_path, &config.input_files())?;
25+
for tag in readme.config()?.tags() {
26+
let input_files = path::join_several(readme_path, &tag.input_files())?;
2727
match Spec::read_files(&input_files) {
2828
Ok(spec) => {
2929
let versions = spec.api_versions();
3030
if versions.len() > 1 {
31-
println!("{} {}", readme.spec(), &config.tag);
31+
println!("{} {}", readme.spec(), &tag.name());
3232
for version in versions {
3333
println!(" {}", version);
3434
}

services/autorust/codegen/examples/svc_tags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ fn main() -> Result<()> {
88
let mut tag_count = 0;
99
for (i, spec) in get_svc_readmes()?.iter().enumerate() {
1010
println!("{} {}", i + 1, spec.spec());
11-
for config in spec.configs()? {
12-
println!(" {}", &config.tag);
13-
for input_file in &config.input_files {
11+
for tag in spec.config()?.tags() {
12+
println!(" {}", &tag.tag);
13+
for input_file in &tag.input_files {
1414
println!(" {}", input_file);
1515
}
1616
tag_count += 1;

services/autorust/codegen/src/cargo_toml.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::config_parser::Tag;
12
use std::{
23
fs::File,
34
io::{prelude::*, LineWriter},
@@ -11,10 +12,10 @@ pub enum Error {
1112
IoError { source: std::io::Error },
1213
}
1314

14-
pub fn create(crate_name: &str, feature_mod_names: &[(String, String)], path: &Path) -> Result<()> {
15+
pub fn create(crate_name: &str, tags: &[&Tag], default_tag: Option<&str>, path: &Path) -> Result<()> {
1516
let file = File::create(path).map_err(|source| Error::IoError { source })?;
1617
let mut file = LineWriter::new(file);
17-
let default = get_default_feature(feature_mod_names);
18+
let default = get_default_feature(tags, default_tag);
1819
file.write_all(
1920
format!(
2021
r#"# generated by AutoRust
@@ -54,20 +55,25 @@ no-default-version = []
5455
)
5556
.map_err(|source| Error::IoError { source })?;
5657

57-
for (feature_name, _mod_name) in feature_mod_names {
58-
file.write_all(format!("\"{}\" = []\n", feature_name).as_bytes())
58+
for tag in tags {
59+
file.write_all(format!("\"{}\" = []\n", tag.rust_feature_name()).as_bytes())
5960
.map_err(|source| Error::IoError { source })?;
6061
}
6162
Ok(())
6263
}
6364

64-
fn get_default_feature(feature_mod_names: &[(String, String)]) -> String {
65-
let default = feature_mod_names
65+
fn get_default_feature(tags: &[&Tag], default_tag: Option<&str>) -> String {
66+
if let Some(default_tag) = default_tag {
67+
if let Some(tag) = tags.iter().find(|tag| tag.name() == default_tag) {
68+
return tag.rust_feature_name();
69+
}
70+
}
71+
let feature = tags
6672
.iter()
67-
.map(|(feature, _)| feature)
73+
.map(|tag| tag.rust_feature_name())
6874
.find(|feature| !feature.contains("preview"));
69-
match default {
70-
Some(default) => default.clone(),
71-
None => feature_mod_names[0].0.clone(),
75+
match feature {
76+
Some(feature) => feature,
77+
None => tags[0].rust_feature_name(),
7278
}
7379
}

0 commit comments

Comments
 (0)