Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support multiple concurrent versions of generated service APIs #416

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
48 changes: 44 additions & 4 deletions services/autorust/codegen/examples/gen_mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const SKIP_SERVICES: &[&str] = &[
];

const SKIP_SERVICE_TAGS: &[(&str, &str)] = &[
("applicationinsights", "package-preview-2020-06"), // defines operation `list` multiple times
("analysisservices", "package-2017-08"),
("authorization", "package-2020-10-01-preview"),
("authorization", "package-2018-05-01-preview"),
Expand All @@ -39,6 +40,7 @@ const SKIP_SERVICE_TAGS: &[(&str, &str)] = &[
("compute", "package-2021-03-01-only"), // TODO #81 DataType::File
("compute", "package-2021-04-01"), // TODO #81 DataType::File
("compute", "package-2021-07-01"), // TODO #81 DataType::File
("consumption", "package-2018-03"), // defines get_balances_by_billing_account twice
("consumption", "package-2019-11"), // ReservationRecommendationDetails_Get has a path and query param both named "scope"
("consumption", "package-2021-05"),
("cosmos-db", "package-2021-06"), // duplicate tag https://github.com/Azure/azure-rest-api-specs/issues/14996
Expand All @@ -51,6 +53,7 @@ const SKIP_SERVICE_TAGS: &[(&str, &str)] = &[
("datamigration", "package-2018-03-15-preview"),
("datamigration", "package-2017-11-15-preview"),
("datamigration", "package-2021-06"),
("deploymentmanager", "package-2018-09-01-preview"), // identifiers are bound more than once in param list. https://github.com/Azure/azure-sdk-for-rust/issues/415
("mediaservices", "package-2019-05-preview"), // invalid unicode character of a dash instead of a hyphen https://github.com/Azure/azure-rest-api-specs/pull/11576
("marketplace", "package-2020-01-01"),
("marketplace", "package-2020-12-01"),
Expand All @@ -62,6 +65,7 @@ const SKIP_SERVICE_TAGS: &[(&str, &str)] = &[
("resources", "package-policy-2020-03"),
("resources", "package-policy-2020-09"), // SchemaNotFound { ref_key: RefKey { file_path: "../../../azure-rest-api-specs/specification/resources/resource-manager/Microsoft.Authorization/stable/2020-09-01/dataPolicyManifests.json", name: "CloudError"
("security", "package-2020-01-preview-only"), // duplicate tag https://github.com/Azure/azure-rest-api-specs/pull/13828
("security", "package-2019-08-only"), // defines `start_time_utc` param twice.
];

// because of a bug in compute specs, some properties need to be forced to be optional
Expand Down Expand Up @@ -154,11 +158,29 @@ const OPTIONAL_PROPERTIES: &[(&str, &str, &str)] = &[
// https://github.com/ctaggart/autorust/issues/73
const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
// cost-management
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2021-10-01/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2021-10-01/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2020-06-01/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/preview/2019-03-01-preview/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/preview/2019-03-01-preview/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/preview/2019-03-01-preview/costmanagement.json", "Scope", "childScope"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/preview/2019-04-01-preview/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/preview/2019-04-01-preview/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/preview/2019-04-01-preview/costmanagement.json", "Scope", "childScope"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2018-05-31/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2018-05-31/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2019-01-01/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2019-01-01/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2019-09-01/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2019-09-01/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2019-10-01/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2019-10-01/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2020-06-01/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2020-06-01/costmanagement.json", "ReportConfigFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2021-10-01/costmanagement.json", "QueryFilter", "not"),
("../../../azure-rest-api-specs/specification/cost-management/resource-manager/Microsoft.CostManagement/stable/2021-10-01/costmanagement.json", "ReportConfigFilter", "not"),
// databox
("../../../azure-rest-api-specs/specification/databox/resource-manager/Microsoft.DataBox/preview/2021-08-01-preview/databox.json", "transferFilterDetails", "include"),
("../../../azure-rest-api-specs/specification/databox/resource-manager/Microsoft.DataBox/preview/2021-08-01-preview/databox.json", "transferAllDetails", "include"),
("../../../azure-rest-api-specs/specification/databox/resource-manager/Microsoft.DataBox/stable/2020-04-01/databox.json", "transferFilterDetails", "include"),
("../../../azure-rest-api-specs/specification/databox/resource-manager/Microsoft.DataBox/stable/2020-04-01/databox.json", "transferAllDetails", "include"),
("../../../azure-rest-api-specs/specification/databox/resource-manager/Microsoft.DataBox/stable/2020-11-01/databox.json", "transferFilterDetails", "include"),
("../../../azure-rest-api-specs/specification/databox/resource-manager/Microsoft.DataBox/stable/2020-11-01/databox.json", "transferAllDetails", "include"),
("../../../azure-rest-api-specs/specification/databox/resource-manager/Microsoft.DataBox/stable/2021-03-01/databox.json", "transferFilterDetails", "include"),
Expand All @@ -168,6 +190,9 @@ const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
// dataprotection
("../../../azure-rest-api-specs/specification/dataprotection/resource-manager/Microsoft.DataProtection/stable/2021-01-01/dataprotection.json", "InnerError", "embeddedInnerError"),
("../../../azure-rest-api-specs/specification/dataprotection/resource-manager/Microsoft.DataProtection/stable/2021-07-01/dataprotection.json", "InnerError", "embeddedInnerError"),
("../../../azure-rest-api-specs/specification/dataprotection/resource-manager/Microsoft.DataProtection/preview/2021-02-01-preview/dataprotection.json", "InnerError", "embeddedInnerError"),
("../../../azure-rest-api-specs/specification/dataprotection/resource-manager/Microsoft.DataProtection/preview/2021-06-01-preview/dataprotection.json", "InnerError", "embeddedInnerError"),
("../../../azure-rest-api-specs/specification/dataprotection/resource-manager/Microsoft.DataProtection/preview/2021-10-01-preview/dataprotection.json", "InnerError", "embeddedInnerError"),
// hardwaresecuritymodels
("../../../azure-rest-api-specs/specification/hardwaresecuritymodules/resource-manager/Microsoft.HardwareSecurityModules/preview/2018-10-31-preview/dedicatedhsm.json", "Error", "innererror"),
// logic
Expand Down Expand Up @@ -250,6 +275,21 @@ const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2021-02-01/publicIpAddress.json", "PublicIPAddress", "properties"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2021-03-01/customIpPrefix.json", "CustomIpPrefix", "properties"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2021-03-01/publicIpAddress.json", "PublicIPAddress", "properties"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-06-01/network.json", "PublicIPAddressPropertiesFormat", "ipConfiguration"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-06-01/network.json", "PublicIPAddress", "properties"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-06-01/network.json", "IPConfigurationPropertiesFormat", "publicIPAddress"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-06-01/network.json", "IPConfiguration", "properties"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-03-30/network.json", "PublicIPAddressPropertiesFormat", "ipConfiguration"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-03-30/network.json", "PublicIPAddress", "properties"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-03-30/network.json", "IPConfigurationPropertiesFormat", "publicIPAddress"),
("../../../azure-rest-api-specs/specification/network/resource-manager/Microsoft.Network/stable/2016-03-30/network.json", "IPConfiguration", "properties"),
// operationalinsights
("../../../azure-rest-api-specs/specification/operationalinsights/resource-manager/Microsoft.OperationalInsights/preview/2019-09-01-preview/QueryPackQueries_API.json", "ErrorInfo", "innererror"),
("../../../azure-rest-api-specs/specification/operationalinsights/resource-manager/Microsoft.OperationalInsights/preview/2019-09-01-preview/QueryPacks_API.json", "ErrorInfo", "innererror"),
// keyvault
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/preview/2020-04-01-preview/managedHsm.json", "Error" , "innererror"),
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/preview/2021-04-01-preview/managedHsm.json", "Error" , "innererror"),
("../../../azure-rest-api-specs/specification/keyvault/resource-manager/Microsoft.KeyVault/preview/2021-06-01-preview/managedHsm.json", "Error" , "innererror"),
];

pub type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -327,7 +367,7 @@ fn gen_crate(spec: &SpecReadme) -> Result<()> {
for config in spec.configs() {
let tag = config.tag.as_str();
if skip_service_tags.contains(&(spec.spec(), tag)) {
// println!(" skipping {}", tag);
println!(" skipping {}", tag);
continue;
}
println!(" {}", tag);
Expand Down
12 changes: 12 additions & 0 deletions services/autorust/codegen/examples/gen_svc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const SKIP_SERVICES: &[&str] = &[
"keyvault", // `{field_name}` used in formatting url
"videoanalyzer", // no operations
"mediaservices", // no operations
"marketplacecatalog", // BadRequest400 uses models::String?
];

const SKIP_SERVICE_TAGS: &[(&str, &str)] = &[
Expand Down Expand Up @@ -112,6 +113,17 @@ const BOX_PROPERTIES: &[(&str, &str, &str)] = &[
"../../../azure-rest-api-specs/specification/timeseriesinsights/data-plane/Microsoft.TimeSeriesInsights/stable/2020-07-31/timeseriesinsights.json",
"TsiErrorBody",
"innerError",
),
// datalake-analytics
(
"../../../azure-rest-api-specs/specification/datalake-analytics/data-plane/Microsoft.DataLakeAnalytics/stable/2016-11-01/job.json",
"JobInnerError",
"innerError"
),
(
"../../../azure-rest-api-specs/specification/datalake-analytics/data-plane/Microsoft.DataLakeAnalytics/preview/2017-09-01-preview/job.json",
"JobInnerError",
"innerError"
)
];

Expand Down
9 changes: 4 additions & 5 deletions services/autorust/codegen/src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn create(crate_name: &str, feature_mod_names: &Vec<(String, String)>, path:
let file = File::create(path).map_err(|source| Error::IoError { source })?;
let mut file = LineWriter::new(file);
let version = &env!("CARGO_PKG_VERSION");
let default = get_default_feature(feature_mod_names);
file.write_all(
format!(
r#"# generated by AutoRust {}
Expand All @@ -38,17 +39,15 @@ azure_identity = {{ path = "../../../sdk/identity", version = "0.1.0" }}
tokio = {{ version = "1.0", features = ["macros"] }}

[features]
default = ["{}"]
no-default-version = []
"#,
version, crate_name
version, crate_name, default
)
.as_bytes(),
)
.map_err(|source| Error::IoError { source })?;

let default = get_default_feature(feature_mod_names);
file.write_all(format!("default = [\"{}\"]\n", default).as_bytes())
.map_err(|source| Error::IoError { source })?;

for (feature_name, _mod_name) in feature_mod_names {
file.write_all(format!("\"{}\" = []\n", feature_name).as_bytes())
.map_err(|source| Error::IoError { source })?;
Expand Down
6 changes: 3 additions & 3 deletions services/autorust/codegen/src/codegen_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn create_operations(cg: &CodeGen) -> Result<TokenStream, Error> {
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(unused_imports)]
use crate::models::*;
use super::{models, models::*};

});
let mut modules: IndexMap<Option<String>, TokenStream> = IndexMap::new();
Expand Down Expand Up @@ -59,7 +59,7 @@ pub fn create_operations(cg: &CodeGen) -> Result<TokenStream, Error> {
let name = ident(&module_name).map_err(Error::ModuleName)?;
file.extend(quote! {
pub mod #name {
use crate::models::*;
use super::{models, models::*};

#module
}
Expand Down Expand Up @@ -462,7 +462,7 @@ fn create_function(cg: &CodeGen, doc_file: &Path, operation: &WebOperation) -> R
}
}
pub mod #fname {
use crate::{models, models::*};
use super::{models, models::*};

#response_enum

Expand Down
16 changes: 13 additions & 3 deletions services/autorust/codegen/src/lib_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ fn create_body(feature_mod_names: &Vec<(String, String)>) -> Result<TokenStream>
})?;
cfgs.extend(quote! {
#[cfg(feature = #feature_name)]
mod #mod_name;
#[cfg(feature = #feature_name)]
pub mod #mod_name;
#[cfg(all(feature = #feature_name, not(feature = "no-default-version")))]
pub use #mod_name::{models, operations, API_VERSION};
});
}
Expand All @@ -38,6 +38,16 @@ fn create_body(feature_mod_names: &Vec<(String, String)>) -> Result<TokenStream>
#cfgs
use azure_core::setters;

#[cfg(not(feature = "no-default-version"))]
fn get_default_feature() -> String {
API_VERSION.to_owned()
}

#[cfg(feature = "no-default-version")]
fn get_default_feature() -> String {
"".to_owned()
}

pub fn config(
http_client: std::sync::Arc<dyn azure_core::HttpClient>,
token_credential: Box<dyn azure_core::TokenCredential>,
Expand Down Expand Up @@ -68,7 +78,7 @@ fn create_body(feature_mod_names: &Vec<(String, String)>) -> Result<TokenStream>

pub fn build(self) -> OperationConfig {
OperationConfig {
api_version: self.api_version.unwrap_or(API_VERSION.to_owned()),
api_version: self.api_version.unwrap_or_else(|| get_default_feature()),
http_client: self.http_client,
base_path: self.base_path.unwrap_or("https://management.azure.com".to_owned()),
token_credential: Some(self.token_credential),
Expand Down
1 change: 1 addition & 0 deletions services/mgmt/addons/Cargo.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions services/mgmt/addons/src/lib.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading