artcoded_api/apis/
x_path_utils_rest_controller_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ModelConversionError {
20 UnknownValue(serde_json::Value),
21}
22
23pub async fn model_conversion(
24 configuration: &configuration::Configuration,
25 expression: &str,
26 data: &str,
27) -> Result<String, Error<ModelConversionError>> {
28 let p_query_expression = expression;
30 let p_query_data = data;
31
32 let uri_str = format!(
33 "{}/api/toolbox/public/xpath/evaluate",
34 configuration.base_path
35 );
36 let mut req_builder = configuration
37 .client
38 .request(reqwest::Method::POST, &uri_str);
39
40 req_builder = req_builder.query(&[("expression", &p_query_expression.to_string())]);
41 req_builder = req_builder.query(&[("data", &p_query_data.to_string())]);
42 if let Some(ref user_agent) = configuration.user_agent {
43 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
44 }
45 if let Some(ref token) = configuration.bearer_access_token {
46 req_builder = req_builder.bearer_auth(token.to_owned());
47 };
48
49 let req = req_builder.build()?;
50 let resp = configuration.client.execute(req).await?;
51
52 let status = resp.status();
53 let content_type = resp
54 .headers()
55 .get("content-type")
56 .and_then(|v| v.to_str().ok())
57 .unwrap_or("application/octet-stream");
58 let content_type = super::ContentType::from(content_type);
59
60 if !status.is_client_error() && !status.is_server_error() {
61 let content = resp.text().await?;
62 match content_type {
63 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
64 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))),
65 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
66 }
67 } else {
68 let content = resp.text().await?;
69 let entity: Option<ModelConversionError> = serde_json::from_str(&content).ok();
70 Err(Error::ResponseError(ResponseContent {
71 status,
72 content,
73 entity,
74 }))
75 }
76}