Skip to content

Commit 967b9bd

Browse files
bmc-msftdemoray
andauthored
address feature name limits from crates.io (#645)
This ensures feature names are alpha-numeric, dashes, and underscores only. Co-authored-by: Brian Caswell <bcaswell@microsoft.com>
1 parent 3ca5610 commit 967b9bd

File tree

17 files changed

+150
-122
lines changed

17 files changed

+150
-122
lines changed

services/autorust/codegen/examples/gen_mgmt.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
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::{self, cargo_toml, config_parser::to_mod_name, get_mgmt_readmes, lib_rs, path, Config, PropertyName, SpecReadme};
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+
};
48
use std::{collections::HashSet, fs, path::PathBuf};
59

610
const OUTPUT_FOLDER: &str = "../mgmt";
@@ -28,6 +32,7 @@ const SKIP_SERVICE_TAGS: &[(&str, &str)] = &[
2832
("authorization", "package-2018-05-01-preview"),
2933
("authorization", "package-2021-03-01-preview-only"),
3034
("authorization", "package-2021-07-01-preview-only"),
35+
("authorization", "package-preview-2021-11"),
3136
("azureactivedirectory", "package-preview-2020-07"),
3237
("consumption", "package-2018-03"), // defines get_balances_by_billing_account twice
3338
("consumption", "package-2019-11"), // ReservationRecommendationDetails_Get has a path and query param both named "scope"
@@ -285,6 +290,8 @@ const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
285290
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/preview/2020-04-01-preview/managedHsm.json", "Error" , "innererror"),
286291
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/preview/2021-04-01-preview/managedHsm.json", "Error" , "innererror"),
287292
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/preview/2021-06-01-preview/managedHsm.json", "Error" , "innererror"),
293+
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/preview/2021-11-01-preview/managedHsm.json", "Error" , "innererror"),
294+
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/stable/2021-10-01/managedHsm.json", "Error", "innererror"),
288295
];
289296

290297
pub type Result<T, E = Error> = std::result::Result<T, E>;
@@ -352,17 +359,17 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
352359
}
353360

354361
for config in spec.configs()? {
355-
let tag = config.tag.as_str();
356-
if skip_service_tags.contains(&(spec.spec(), tag)) {
362+
let tag = to_tag_name(&config.tag);
363+
if skip_service_tags.contains(&(spec.spec(), tag.as_ref())) {
357364
println!(" skipping {}", tag);
358365
continue;
359366
}
360367
println!(" {}", tag);
361368
// println!(" {}", api_version);
362-
let mod_name = &to_mod_name(tag);
363-
feature_mod_names.push((tag.to_string(), mod_name.clone()));
369+
let mod_name = to_mod_name(&tag);
370+
let mod_output_folder = path::join(&src_folder, &mod_name).map_err(|source| Error::PathError { source })?;
371+
feature_mod_names.push((tag, mod_name));
364372
// println!(" {}", mod_name);
365-
let mod_output_folder = path::join(&src_folder, mod_name).map_err(|source| Error::PathError { source })?;
366373
// println!(" {:?}", mod_output_folder);
367374
// for input_file in &config.input_files {
368375
// println!(" {}", input_file);

services/autorust/codegen/examples/gen_svc.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
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::{self, cargo_toml, config_parser::to_mod_name, get_svc_readmes, lib_rs, path, Config, PropertyName, SpecReadme};
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+
};
48
use std::{collections::HashSet, fs, path::PathBuf};
59

610
const OUTPUT_FOLDER: &str = "../svc";
@@ -18,11 +22,11 @@ const SKIP_SERVICES: &[&str] = &[
1822
const SKIP_SERVICE_TAGS: &[(&str, &str)] = &[
1923
("agrifood", "package-2021-03-31-preview"), // duplicate params https://github.com/Azure/azure-sdk-for-rust/issues/501
2024
("purview", "package-2021-05-01-preview"), // need to box types
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
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
2630
("storagedatalake", "package-2018-11"), // "invalid value: string \"ErrorResponse\", expected length 3"
2731
("storagedatalake", "package-2018-06-preview"),
2832
("storagedatalake", "package-2019-10"),
@@ -241,16 +245,16 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
241245
}
242246

243247
for config in spec.configs()? {
244-
let tag = config.tag.as_str();
245-
if skip_service_tags.contains(&(spec.spec(), tag)) {
248+
let tag = to_tag_name(config.tag.as_str());
249+
if skip_service_tags.contains(&(spec.spec(), tag.as_ref())) {
246250
// println!(" skipping {}", tag);
247251
continue;
248252
}
249253
println!(" {}", tag);
250-
let mod_name = &to_mod_name(tag);
251-
feature_mod_names.push((tag.to_string(), mod_name.clone()));
254+
let mod_name = to_mod_name(&tag);
255+
let mod_output_folder = path::join(&src_folder, &mod_name).map_err(|source| Error::PathError { source })?;
256+
feature_mod_names.push((tag, mod_name));
252257
// println!(" {}", mod_name);
253-
let mod_output_folder = path::join(&src_folder, mod_name).map_err(|source| Error::PathError { source })?;
254258
// println!(" {:?}", mod_output_folder);
255259
// for input_file in &config.input_files {
256260
// println!(" {}", input_file);

services/autorust/codegen/src/config_parser.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,16 @@ pub fn get_input_file_api_version(input_file: &str) -> Option<String> {
194194
}
195195
}
196196

197+
/// Create a Rust tag name, based on the feature naem.
198+
pub fn to_tag_name(name: &str) -> String {
199+
name.chars()
200+
.map(|x| match x {
201+
'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' => x,
202+
_ => '_',
203+
})
204+
.collect()
205+
}
206+
197207
/// Create a Rust module name, based on the feature naem.
198208
pub fn to_mod_name(feature_name: &str) -> String {
199209
let mut name = feature_name.to_owned();
@@ -215,6 +225,13 @@ mod tests {
215225
);
216226
}
217227

228+
#[test]
229+
fn test_tag_name() {
230+
assert_eq!("2019-06", to_tag_name("2019-06"));
231+
assert_eq!("2019_06", to_tag_name("2019.06"));
232+
assert_eq!("2019_06", to_tag_name("2019!06"));
233+
}
234+
218235
#[test]
219236
fn test_mod_name() {
220237
assert_eq!("v2019_06", to_mod_name("2019-06"));

services/svc/batch/Cargo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ tokio = { version = "1.0", features = ["macros"] }
2424
all-features = true
2525

2626
[features]
27-
default = ["package-2022-01.15.0", "enable_reqwest"]
27+
default = ["package-2022-01_15_0", "enable_reqwest"]
2828
enable_reqwest = ["azure_core/enable_reqwest"]
2929
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls"]
3030
no-default-version = []
31-
"package-2022-01.15.0" = []
32-
"package-2021-06.14.0" = []
33-
"package-2020-09.12.0" = []
34-
"package-2020-03.11.0" = []
35-
"package-2019-08.10.0" = []
36-
"package-2019-06.9.0" = []
37-
"package-2018-12.8.0" = []
38-
"package-2018-08.7.0" = []
39-
"package-2018-03.6.1" = []
40-
"package-2017-09.6.0" = []
41-
"package-2017-06.5.1" = []
31+
"package-2022-01_15_0" = []
32+
"package-2021-06_14_0" = []
33+
"package-2020-09_12_0" = []
34+
"package-2020-03_11_0" = []
35+
"package-2019-08_10_0" = []
36+
"package-2019-06_9_0" = []
37+
"package-2018-12_8_0" = []
38+
"package-2018-08_7_0" = []
39+
"package-2018-03_6_1" = []
40+
"package-2017-09_6_0" = []
41+
"package-2017-06_5_1" = []

services/svc/batch/src/lib.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33
#![allow(clippy::ptr_arg)]
44
#![allow(clippy::large_enum_variant)]
55
#![doc = "generated by AutoRust"]
6-
#[cfg(feature = "package-2022-01.15.0")]
6+
#[cfg(feature = "package-2022-01_15_0")]
77
pub mod package_2022_01_15_0;
8-
#[cfg(all(feature = "package-2022-01.15.0", not(feature = "no-default-version")))]
8+
#[cfg(all(feature = "package-2022-01_15_0", not(feature = "no-default-version")))]
99
pub use package_2022_01_15_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
10-
#[cfg(feature = "package-2021-06.14.0")]
10+
#[cfg(feature = "package-2021-06_14_0")]
1111
pub mod package_2021_06_14_0;
12-
#[cfg(all(feature = "package-2021-06.14.0", not(feature = "no-default-version")))]
12+
#[cfg(all(feature = "package-2021-06_14_0", not(feature = "no-default-version")))]
1313
pub use package_2021_06_14_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
14-
#[cfg(feature = "package-2020-09.12.0")]
14+
#[cfg(feature = "package-2020-09_12_0")]
1515
pub mod package_2020_09_12_0;
16-
#[cfg(all(feature = "package-2020-09.12.0", not(feature = "no-default-version")))]
16+
#[cfg(all(feature = "package-2020-09_12_0", not(feature = "no-default-version")))]
1717
pub use package_2020_09_12_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
18-
#[cfg(feature = "package-2020-03.11.0")]
18+
#[cfg(feature = "package-2020-03_11_0")]
1919
pub mod package_2020_03_11_0;
20-
#[cfg(all(feature = "package-2020-03.11.0", not(feature = "no-default-version")))]
20+
#[cfg(all(feature = "package-2020-03_11_0", not(feature = "no-default-version")))]
2121
pub use package_2020_03_11_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
22-
#[cfg(feature = "package-2019-08.10.0")]
22+
#[cfg(feature = "package-2019-08_10_0")]
2323
pub mod package_2019_08_10_0;
24-
#[cfg(all(feature = "package-2019-08.10.0", not(feature = "no-default-version")))]
24+
#[cfg(all(feature = "package-2019-08_10_0", not(feature = "no-default-version")))]
2525
pub use package_2019_08_10_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
26-
#[cfg(feature = "package-2019-06.9.0")]
26+
#[cfg(feature = "package-2019-06_9_0")]
2727
pub mod package_2019_06_9_0;
28-
#[cfg(all(feature = "package-2019-06.9.0", not(feature = "no-default-version")))]
28+
#[cfg(all(feature = "package-2019-06_9_0", not(feature = "no-default-version")))]
2929
pub use package_2019_06_9_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
30-
#[cfg(feature = "package-2018-12.8.0")]
30+
#[cfg(feature = "package-2018-12_8_0")]
3131
pub mod package_2018_12_8_0;
32-
#[cfg(all(feature = "package-2018-12.8.0", not(feature = "no-default-version")))]
32+
#[cfg(all(feature = "package-2018-12_8_0", not(feature = "no-default-version")))]
3333
pub use package_2018_12_8_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
34-
#[cfg(feature = "package-2018-08.7.0")]
34+
#[cfg(feature = "package-2018-08_7_0")]
3535
pub mod package_2018_08_7_0;
36-
#[cfg(all(feature = "package-2018-08.7.0", not(feature = "no-default-version")))]
36+
#[cfg(all(feature = "package-2018-08_7_0", not(feature = "no-default-version")))]
3737
pub use package_2018_08_7_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
38-
#[cfg(feature = "package-2018-03.6.1")]
38+
#[cfg(feature = "package-2018-03_6_1")]
3939
pub mod package_2018_03_6_1;
40-
#[cfg(all(feature = "package-2018-03.6.1", not(feature = "no-default-version")))]
40+
#[cfg(all(feature = "package-2018-03_6_1", not(feature = "no-default-version")))]
4141
pub use package_2018_03_6_1::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
42-
#[cfg(feature = "package-2017-09.6.0")]
42+
#[cfg(feature = "package-2017-09_6_0")]
4343
pub mod package_2017_09_6_0;
44-
#[cfg(all(feature = "package-2017-09.6.0", not(feature = "no-default-version")))]
44+
#[cfg(all(feature = "package-2017-09_6_0", not(feature = "no-default-version")))]
4545
pub use package_2017_09_6_0::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
46-
#[cfg(feature = "package-2017-06.5.1")]
46+
#[cfg(feature = "package-2017-06_5_1")]
4747
pub mod package_2017_06_5_1;
48-
#[cfg(all(feature = "package-2017-06.5.1", not(feature = "no-default-version")))]
48+
#[cfg(all(feature = "package-2017-06_5_1", not(feature = "no-default-version")))]
4949
pub use package_2017_06_5_1::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};

services/svc/confidentialledger/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ tokio = { version = "1.0", features = ["macros"] }
2424
all-features = true
2525

2626
[features]
27-
default = ["package-0.1-preview-ledger", "enable_reqwest"]
27+
default = ["package-0_1-preview-ledger", "enable_reqwest"]
2828
enable_reqwest = ["azure_core/enable_reqwest"]
2929
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls"]
3030
no-default-version = []
31-
"package-0.1-preview-ledger" = []
32-
"package-0.1-preview-identity" = []
31+
"package-0_1-preview-ledger" = []
32+
"package-0_1-preview-identity" = []

services/svc/confidentialledger/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
#![allow(clippy::ptr_arg)]
44
#![allow(clippy::large_enum_variant)]
55
#![doc = "generated by AutoRust"]
6-
#[cfg(feature = "package-0.1-preview-ledger")]
6+
#[cfg(feature = "package-0_1-preview-ledger")]
77
pub mod package_0_1_preview_ledger;
8-
#[cfg(all(feature = "package-0.1-preview-ledger", not(feature = "no-default-version")))]
8+
#[cfg(all(feature = "package-0_1-preview-ledger", not(feature = "no-default-version")))]
99
pub use package_0_1_preview_ledger::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};
10-
#[cfg(feature = "package-0.1-preview-identity")]
10+
#[cfg(feature = "package-0_1-preview-identity")]
1111
pub mod package_0_1_preview_identity;
12-
#[cfg(all(feature = "package-0.1-preview-identity", not(feature = "no-default-version")))]
12+
#[cfg(all(feature = "package-0_1-preview-identity", not(feature = "no-default-version")))]
1313
pub use package_0_1_preview_identity::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};

services/svc/graphrbac/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ tokio = { version = "1.0", features = ["macros"] }
2424
all-features = true
2525

2626
[features]
27-
default = ["1.6", "enable_reqwest"]
27+
default = ["1_6", "enable_reqwest"]
2828
enable_reqwest = ["azure_core/enable_reqwest"]
2929
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls"]
3030
no-default-version = []
31-
"1.6" = []
31+
"1_6" = []

services/svc/graphrbac/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(clippy::ptr_arg)]
44
#![allow(clippy::large_enum_variant)]
55
#![doc = "generated by AutoRust"]
6-
#[cfg(feature = "1.6")]
6+
#[cfg(feature = "1_6")]
77
pub mod v1_6;
8-
#[cfg(all(feature = "1.6", not(feature = "no-default-version")))]
8+
#[cfg(all(feature = "1_6", not(feature = "no-default-version")))]
99
pub use v1_6::{models, operations, operations::Client, operations::ClientBuilder, operations::Error};

services/svc/iotcentral/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ tokio = { version = "1.0", features = ["macros"] }
2424
all-features = true
2525

2626
[features]
27-
default = ["package-1.0", "enable_reqwest"]
27+
default = ["package-1_0", "enable_reqwest"]
2828
enable_reqwest = ["azure_core/enable_reqwest"]
2929
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls"]
3030
no-default-version = []
31-
"package-1.1-preview" = []
31+
"package-1_1-preview" = []
3232
"package-2021-04-30-preview" = []
33-
"package-1.0" = []
33+
"package-1_0" = []

0 commit comments

Comments
 (0)