Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changes

- Update `azure_core` and `azure_identity` to 0.30.
- Changes to handle API changes in `azure_core`:
- Replace `azure_core::http::BufResponse` with `azure_core::http::RawResponse` / `AsyncRawResponse`
- Change `Response::into_body().await` to `Response::into_model()` (now synchronous)
- Update `ClientOptions::retry` field to be `RetryOptions` (no longer `Option<RetryOptions>`)
- Add required `PipelineSendOptions` parameter to `Pipeline::send()`
- Update `transport()` method to use `Transport` type (replaces `TransportOptions`)
- Fix `API_VERSION` reference to use string literal `"api-version"` instead of non-existent `query_param` module
- Changes to handle API changes in manually written code:
- Update `auth.rs` to remove deprecated `ResultExt::context()` method
- Update `date_time.rs` to use direct error construction instead of `with_context()` closure
- Update `telemetry.rs` to use `AsyncRawResponse` and new construction API

## [0.32.0]

### Changes
Expand Down
8 changes: 6 additions & 2 deletions autorust/codegen/src/autorust_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ impl<'a> PackageConfig {
let deny: HashSet<&str> = self.tags.deny.iter().map(String::as_str).collect();
tags.retain(|tag| !deny.contains(tag.name()));
}
let mut deny_contains: Vec<&str> = self.tags.deny_contains.iter().map(String::as_str).collect();
let mut deny_contains: Vec<&str> =
self.tags.deny_contains.iter().map(String::as_str).collect();
if self.tags.deny_contains_preview.unwrap_or_default() {
deny_contains.push("preview");
}
Expand Down Expand Up @@ -325,7 +326,10 @@ mod tests {
default = "package-resources-2021-04"
"#,
)?;
assert_eq!(Some("package-resources-2021-04".to_string()), config.tags.default);
assert_eq!(
Some("package-resources-2021-04".to_string()),
config.tags.default
);
Ok(())
}

Expand Down
23 changes: 19 additions & 4 deletions autorust/codegen/src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ use crate::Result;
use crate::{config_parser::Tag, jinja::CargoToml};
use camino::Utf8Path;

pub fn create(package_name: &str, tags: &[&Tag], default_tag: &Tag, has_xml: bool, path: &Utf8Path) -> Result<()> {
pub fn create(
package_name: &str,
tags: &[&Tag],
default_tag: &Tag,
has_xml: bool,
path: &Utf8Path,
) -> Result<()> {
let default_tag = &default_tag.rust_feature_name();

// https://docs.rs/about/metadata
Expand All @@ -22,7 +28,9 @@ pub fn create(package_name: &str, tags: &[&Tag], default_tag: &Tag, has_xml: boo

pub fn get_default_tag<'a>(tags: &[&'a Tag], default_tag: Option<&str>) -> &'a Tag {
let default_tag = tags.iter().find(|tag| Some(tag.name()) == default_tag);
let is_preview = default_tag.map(|tag| tag.name().contains("preview")).unwrap_or_default();
let is_preview = default_tag
.map(|tag| tag.name().contains("preview"))
.unwrap_or_default();
let stable_tag = tags.iter().find(|tag| !tag.name().contains("preview"));
match (default_tag, is_preview, stable_tag) {
(Some(default_tag), false, _) => default_tag,
Expand Down Expand Up @@ -94,13 +102,20 @@ mod tests {
];
let tags: Vec<_> = tags.into_iter().map(Tag::new).collect();
let tags: Vec<_> = tags.iter().collect();
assert_eq!("package-2020-04", get_default_tag(&tags, Some("package-2020-04")).name());
assert_eq!(
"package-2020-04",
get_default_tag(&tags, Some("package-2020-04")).name()
);
Ok(())
}

#[test]
fn specified_preview() -> Result<()> {
let tags = vec!["package-preview-2022-05", "package-2019-06-preview", "package-2019-04-preview"];
let tags = vec![
"package-preview-2022-05",
"package-2019-06-preview",
"package-2019-04-preview",
];
let tags: Vec<_> = tags.into_iter().map(Tag::new).collect();
let tags: Vec<_> = tags.iter().collect();
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ pub fn create_client(modules: &[String], endpoint: Option<&str>) -> Result<Token
#[doc = "Set the retry options."]
#[must_use]
pub fn retry(mut self, retry: impl Into<azure_core::http::RetryOptions>) -> Self {
self.options.retry = Some(retry.into());
self.options.retry = retry.into();
self
}

#[doc = "Set the transport options."]
#[must_use]
pub fn transport(mut self, transport: impl Into<azure_core::http::TransportOptions>) -> Self {
pub fn transport(mut self, transport: impl Into<azure_core::http::Transport>) -> Self {
self.options.transport = Some(transport.into());
self
}
Expand Down Expand Up @@ -134,9 +134,9 @@ pub fn create_client(modules: &[String], endpoint: Option<&str>) -> Result<Token
pub(crate) fn scopes(&self) -> Vec<&str> {
self.scopes.iter().map(String::as_str).collect()
}
pub(crate) async fn send(&self, request: &mut azure_core::http::Request) -> azure_core::Result<azure_core::http::BufResponse> {
pub(crate) async fn send(&self, request: &mut azure_core::http::Request) -> azure_core::Result<azure_core::http::RawResponse> {
let context = azure_core::http::Context::default();
self.pipeline.send(&context, request).await
self.pipeline.send(&context, request, None).await
}

#[doc = "Create a new `ClientBuilder`."]
Expand Down
14 changes: 11 additions & 3 deletions autorust/codegen/src/codegen_operations/function_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ pub(crate) struct ClientFunctionCode {
}

impl ClientFunctionCode {
pub fn new(operation: &WebOperationGen, parameters: &FunctionParams, in_operation_group: bool) -> Result<Self> {
pub fn new(
operation: &WebOperationGen,
parameters: &FunctionParams,
in_operation_group: bool,
) -> Result<Self> {
let fname = operation.function_name()?;
let summary = operation.0.summary.clone();
let description = operation.0.description.clone();
Expand All @@ -41,7 +45,9 @@ impl ToTokens for ClientFunctionCode {
}
for param in self.parameters.required_params() {
let FunctionParam {
variable_name, type_name, ..
variable_name,
type_name,
..
} = param;
let mut type_name = type_name.clone();
let is_vec = type_name.is_vec();
Expand All @@ -54,7 +60,9 @@ impl ToTokens for ClientFunctionCode {
}
for param in self.parameters.optional_params() {
let FunctionParam {
variable_name, type_name, ..
variable_name,
type_name,
..
} = param;
if type_name.is_vec() {
params.push(quote! { #variable_name: Vec::new() });
Expand Down
6 changes: 4 additions & 2 deletions autorust/codegen/src/codegen_operations/operation_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ use proc_macro2::{Ident, TokenStream};
use quote::{quote, ToTokens};

use super::{
request_builder_into_future::RequestBuilderIntoFutureCode, request_builder_send::RequestBuilderSendCode,
request_builder_setter::RequestBuilderSettersCode, request_builder_struct::RequestBuilderStructCode, response_code::ResponseCode,
request_builder_into_future::RequestBuilderIntoFutureCode,
request_builder_send::RequestBuilderSendCode,
request_builder_setter::RequestBuilderSettersCode,
request_builder_struct::RequestBuilderStructCode, response_code::ResponseCode,
};
pub struct OperationModuleCode {
pub module_name: Ident,
Expand Down
24 changes: 18 additions & 6 deletions autorust/codegen/src/codegen_operations/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,36 @@ impl OperationCode {
// get the content-types from the operation, else the spec, else default to json
let consumes = operation
.pick_consumes()
.unwrap_or_else(|| cg.spec.pick_consumes().unwrap_or(content_type::APPLICATION_JSON))
.unwrap_or_else(|| {
cg.spec
.pick_consumes()
.unwrap_or(content_type::APPLICATION_JSON)
})
.to_string();
let produces = operation
.pick_produces()
.unwrap_or_else(|| cg.spec.pick_produces().unwrap_or(content_type::APPLICATION_JSON))
.unwrap_or_else(|| {
cg.spec
.pick_produces()
.unwrap_or(content_type::APPLICATION_JSON)
})
.to_string();

let lro = operation.0.long_running_operation;
let lro_options = operation.0.long_running_operation_options.clone();

let request_builder = SetRequestCode::new(operation, parameters, consumes);
let in_operation_group = operation.0.in_group();
let client_function_code = ClientFunctionCode::new(operation, parameters, in_operation_group)?;
let request_builder_struct_code = RequestBuilderStructCode::new(parameters, in_operation_group, lro, lro_options.clone());
let client_function_code =
ClientFunctionCode::new(operation, parameters, in_operation_group)?;
let request_builder_struct_code =
RequestBuilderStructCode::new(parameters, in_operation_group, lro, lro_options.clone());
let request_builder_setters_code = RequestBuilderSettersCode::new(parameters);
let response_code = ResponseCode::new(cg, operation, produces)?;
let request_builder_send_code = RequestBuilderSendCode::new(new_request_code, request_builder, response_code.clone())?;
let request_builder_intofuture_code = RequestBuilderIntoFutureCode::new(response_code.clone(), lro, lro_options)?;
let request_builder_send_code =
RequestBuilderSendCode::new(new_request_code, request_builder, response_code.clone())?;
let request_builder_intofuture_code =
RequestBuilderIntoFutureCode::new(response_code.clone(), lro, lro_options)?;

let module_code = OperationModuleCode {
module_name: operation.function_name()?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {
req.insert_header(azure_core::http::headers::AUTHORIZATION, auth_header);
}
let response = self.client.send(&mut req).await?;
return Response(response.into()).into_body().await
return Response(response.into()).into_body()
}
LroStatus::Failed => return Err(Error::message(ErrorKind::Other, "Long running operation failed".to_string())),
LroStatus::Canceled => return Err(Error::message(ErrorKind::Other, "Long running operation canceled".to_string())),
Expand All @@ -99,7 +99,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {
}
}
} else {
response.into_body().await
response.into_body()
}
},
quote! {
Expand All @@ -113,7 +113,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {

(
quote! {
self.send().await?.into_body().await
self.send().await?.into_body()
},
quote! {
#[doc = "Returns a future that sends the request and returns the parsed response body."]
Expand All @@ -136,7 +136,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {
let response = this.send().await?;
let retry_after = get_retry_after(response.as_raw_response().headers());
let status = response.as_raw_response().status();
let body = response.into_body().await?;
let body = response.into_body()?;
let provisioning_state = get_provisioning_state(status, &body)?;
log::trace!("current provisioning_state: {provisioning_state:?}");
match provisioning_state {
Expand All @@ -159,7 +159,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {
} else {
(
quote! {
self.send().await?.into_body().await
self.send().await?.into_body()
},
quote! {
#[doc = "Returns a future that sends the request and returns the parsed response body."]
Expand Down
10 changes: 5 additions & 5 deletions autorust/codegen/src/codegen_operations/request_builder_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ impl ToTokens for RequestBuilderSendCode {
fn url(&self) -> azure_core::Result<azure_core::http::Url> {
let mut url = azure_core::http::Url::parse(&format!(#fpath, self.client.endpoint(), #url_str_args))?;

let has_api_version_already = url.query_pairs().any(|(k, _)| k == azure_core::http::headers::query_param::API_VERSION);
let has_api_version_already = url.query_pairs().any(|(k, _)| k == "api-version");
if !has_api_version_already {
url.query_pairs_mut().append_pair(azure_core::http::headers::query_param::API_VERSION, #api_version);
url.query_pairs_mut().append_pair("api-version", #api_version);
}
Ok(url)
}
Expand Down Expand Up @@ -114,9 +114,9 @@ impl ToTokens for RequestBuilderSendCode {
if request_builder.has_param_api_version {
let api_version = &request_builder.api_version;
stream_api_version.extend(quote! {
let has_api_version_already = req.url_mut().query_pairs().any(|(k, _)| k == azure_core::http::headers::query_param::API_VERSION);
let has_api_version_already = req.url_mut().query_pairs().any(|(k, _)| k == "api-version");
if !has_api_version_already {
req.url_mut().query_pairs_mut().append_pair(azure_core::http::headers::query_param::API_VERSION, #api_version);
req.url_mut().query_pairs_mut().append_pair("api-version", #api_version);
}
});
}
Expand Down Expand Up @@ -191,7 +191,7 @@ impl ToTokens for RequestBuilderSendCode {
match rsp.status() {
#match_status
};
rsp?.into_body().await
rsp?.into_body()
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ impl ToTokens for RequestBuilderSettersCode {
fn to_tokens(&self, tokens: &mut TokenStream) {
for param in self.parameters.optional_params() {
let FunctionParam {
variable_name, type_name, ..
variable_name,
type_name,
..
} = param;
let is_vec = type_name.is_vec();
let mut type_name = type_name.clone();
Expand Down
6 changes: 3 additions & 3 deletions autorust/codegen/src/codegen_operations/response_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ impl ToTokens for ResponseCode {

let body_fn = if self.response_type().is_some() {
quote! {
pub async fn into_body(self) -> azure_core::Result<#response_type_tokens> {
self.0.into_body().await
pub fn into_body(self) -> azure_core::Result<#response_type_tokens> {
self.0.into_model()
}
}
} else {
quote! {}
};

let raw_response_fn = quote! {
pub fn into_raw_response(self) -> azure_core::http::BufResponse {
pub fn into_raw_response(self) -> azure_core::http::RawResponse {
self.0.into()
}
};
Expand Down
10 changes: 8 additions & 2 deletions autorust/codegen/src/codegen_operations/web_operation_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ pub struct Pageable {
/// Creating a function name from the path and verb when an operationId is not specified.
/// All azure-rest-api-specs operations should have an operationId.
fn create_function_name(verb: &WebVerb, path: &str) -> String {
let mut path = path.split('/').filter(|&x| !x.is_empty()).collect::<Vec<_>>();
let mut path = path
.split('/')
.filter(|&x| !x.is_empty())
.collect::<Vec<_>>();
path.insert(0, verb.as_str());
path.join("_")
}
Expand All @@ -165,7 +168,10 @@ mod tests {
verb: WebVerb::Get,
..Default::default()
});
assert_eq!(Some("private_clouds".to_owned()), operation.rust_module_name());
assert_eq!(
Some("private_clouds".to_owned()),
operation.rust_module_name()
);
assert_eq!("create_or_update", operation.rust_function_name());
}

Expand Down
Loading