From a604259fa8031188b286a01054abdcfb51c907ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Herv=C3=A9?= Date: Wed, 12 Mar 2025 19:05:58 +0100 Subject: [PATCH] Fix get_operation_host I believe the logic is wrong, we need to check if there are overrides per operation, and otherwise rely on the global values. In particular server_operation_variables and server_operation_index are not meant to be used only in the case where there is a specific server operation. Fixes #542 --- .../src/generator/templates/configuration.j2 | 33 ++++++++----------- src/datadog/configuration.rs | 33 ++++++++----------- 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/.generator/src/generator/templates/configuration.j2 b/.generator/src/generator/templates/configuration.j2 index 65c260f74..e2bde78a0 100644 --- a/.generator/src/generator/templates/configuration.j2 +++ b/.generator/src/generator/templates/configuration.j2 @@ -60,26 +60,19 @@ impl Configuration { pub fn get_operation_host(&self, operation_str: &str) -> String { let operation = operation_str.to_string(); - if let Some(servers) = OPERATION_SERVERS.get(&operation) { - let server_index = self - .server_operation_index - .get(&operation) - .cloned() - .unwrap_or(0); - return servers - .get(server_index) - .expect(&format!("Server index for operation {operation} not found")) - .get_url( - &self - .server_operation_variables - .get(&operation) - .unwrap_or(&HashMap::new()), - ); - } - SERVERS - .get(self.server_index) - .expect("Server index not found.") - .get_url(&self.server_variables) + let server_index = self + .server_operation_index + .get(&operation) + .unwrap_or(&self.server_index); + let server_variables = self + .server_operation_variables + .get(&operation) + .unwrap_or(&self.server_variables); + let servers = OPERATION_SERVERS.get(&operation).unwrap_or(&SERVERS); + servers + .get(*server_index) + .expect(&format!("Server index for operation {operation} not found")) + .get_url(&server_variables) } pub fn set_unstable_operation_enabled(&mut self, operation: &str, enabled: bool) -> bool { diff --git a/src/datadog/configuration.rs b/src/datadog/configuration.rs index 82972eda8..4f1ebaa0e 100644 --- a/src/datadog/configuration.rs +++ b/src/datadog/configuration.rs @@ -62,26 +62,19 @@ impl Configuration { pub fn get_operation_host(&self, operation_str: &str) -> String { let operation = operation_str.to_string(); - if let Some(servers) = OPERATION_SERVERS.get(&operation) { - let server_index = self - .server_operation_index - .get(&operation) - .cloned() - .unwrap_or(0); - return servers - .get(server_index) - .expect(&format!("Server index for operation {operation} not found")) - .get_url( - &self - .server_operation_variables - .get(&operation) - .unwrap_or(&HashMap::new()), - ); - } - SERVERS - .get(self.server_index) - .expect("Server index not found.") - .get_url(&self.server_variables) + let server_index = self + .server_operation_index + .get(&operation) + .unwrap_or(&self.server_index); + let server_variables = self + .server_operation_variables + .get(&operation) + .unwrap_or(&self.server_variables); + let servers = OPERATION_SERVERS.get(&operation).unwrap_or(&SERVERS); + servers + .get(*server_index) + .expect(&format!("Server index for operation {operation} not found")) + .get_url(&server_variables) } pub fn set_unstable_operation_enabled(&mut self, operation: &str, enabled: bool) -> bool {