use crate::auth::auth_manager::AuthManager;
use crate::auth::request_credentials::RequestCredentials;
use crate::core::config_schema::Config;
use crate::data::store::EndpointRecord;
use crate::services::api_client::ApiClient;
use crate::validation::validator::{validate_input, validate_output};
pub async fn call_operation(
endpoint: &EndpointRecord,
config: &Config,
auth_manager: &mut AuthManager,
operation_id: &str,
args: serde_json::Value,
request_override: Option<&RequestCredentials>,
) -> anyhow::Result<serde_json::Value> {
validate_input(&config.api_version, operation_id, &args)?;
let client = ApiClient::new(config.clone());
let response = client
.execute(endpoint, &args, auth_manager, request_override)
.await?;
if let Err(err) = validate_output(&config.api_version, operation_id, &response) {
tracing::warn!(
operation_id,
error = %err,
"response did not match the documented schema; returning it as-is"
);
}
Ok(response)
}