Skip to content

Commit 2f22149

Browse files
Update azure-autorust to append path and parameters via URL lib (#1663)
* Update azure-autorust to append path and parameters via URL lib When returning a URL from Client::endpoint the URL contains a tailing slash in any case. This is handled by the URL lib which will append the tailing slash to the end upon calling Display::fmt. Therefore formatting the returned URL from Client::endpoint will result in a duplicated slash, which could cause some (not all) Azure endpoints to have some trouble. For example: Base URL: https://some-app-conf.azconfig.io/ AppConfigUrl: https://some-app-conf.azconfig.io//keys?api-version=2023-10-01 This resulted in a 404 response. Removing the tailing slash from the URL manually does not solve the problem, due to the reason mentioned above. This patch applies a fix to append (set) the formatted path via rust URL lib, which will handle the duplicated slash (or any other problem). * Fix Code Style issue * Fix Code Style issues for doc-comments --------- Co-authored-by: Heath Stewart <[email protected]>
1 parent f013d0c commit 2f22149

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

services/autorust/codegen/src/codegen_operations/request_builder_send.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ impl ToTokens for RequestBuilderSendCode {
3838
quote! { &self.#url_arg }
3939
});
4040
let url_str_args = quote! { #(#url_args),* };
41-
42-
let fpath = format!("{{}}{}", &format_path(&new_request_code.path));
41+
let fpath = PARAM_RE.replace_all(&new_request_code.path, "{}");
4342

4443
let mut match_status = TokenStream::new();
4544
for status_response in &self.response_code.status_responses {
@@ -58,7 +57,8 @@ impl ToTokens for RequestBuilderSendCode {
5857
let api_version = &self.request_builder.api_version;
5958
quote! {
6059
fn url(&self) -> azure_core::Result<azure_core::Url> {
61-
let mut url = azure_core::Url::parse(&format!(#fpath, self.client.endpoint(), #url_str_args))?;
60+
let mut url = self.client.endpoint().clone();
61+
url.set_path(&format!(#fpath, #url_str_args));
6262

6363
let has_api_version_already = url.query_pairs().any(|(k, _)| k == azure_core::query_param::API_VERSION);
6464
if !has_api_version_already {
@@ -70,7 +70,9 @@ impl ToTokens for RequestBuilderSendCode {
7070
} else {
7171
quote! {
7272
fn url(&self) -> azure_core::Result<azure_core::Url> {
73-
let url = azure_core::Url::parse(&format!(#fpath, self.client.endpoint(), #url_str_args))?;
73+
let mut url = self.client.endpoint().clone();
74+
url.set_path(&format!(#fpath, #url_str_args));
75+
7476
Ok(url)
7577
}
7678
}
@@ -211,10 +213,6 @@ impl ToTokens for RequestBuilderSendCode {
211213
}
212214
}
213215

214-
fn format_path(path: &str) -> String {
215-
PARAM_RE.replace_all(path, "{}").to_string()
216-
}
217-
218216
fn get_continuable_param(next_link_name: &str, request_builder: &SetRequestCode) -> Option<String> {
219217
let next_link_name = next_link_name.to_snake_case();
220218
let link_name = next_link_name.strip_prefix("next_");

0 commit comments

Comments
 (0)