mesa_dev_oapi/apis/
content_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetByOrgByRepoContentError {
22 Status400(models::PostByOrgApiKeys400Response),
23 Status401(models::PostByOrgApiKeys400Response),
24 Status403(models::PostByOrgApiKeys400Response),
25 Status404(models::PostByOrgApiKeys400Response),
26 Status406(models::PostByOrgApiKeys400Response),
27 Status409(models::PostByOrgApiKeys400Response),
28 Status500(models::PostByOrgApiKeys400Response),
29 UnknownValue(serde_json::Value),
30}
31
32
33pub async fn get_by_org_by_repo_content(configuration: &configuration::Configuration, org: &str, repo: &str, oid: Option<&str>, path: Option<&str>, depth: Option<u64>) -> Result<models::GetByOrgByRepoContent200Response, Error<GetByOrgByRepoContentError>> {
35 let p_path_org = org;
37 let p_path_repo = repo;
38 let p_query_oid = oid;
39 let p_query_path = path;
40 let p_query_depth = depth;
41
42 let uri_str = format!("{}/{org}/{repo}/content", configuration.base_path, org=crate::apis::urlencode(p_path_org), repo=crate::apis::urlencode(p_path_repo));
43 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
44
45 if let Some(ref param_value) = p_query_oid {
46 req_builder = req_builder.query(&[("oid", ¶m_value.to_string())]);
47 }
48 if let Some(ref param_value) = p_query_path {
49 req_builder = req_builder.query(&[("path", ¶m_value.to_string())]);
50 }
51 if let Some(ref param_value) = p_query_depth {
52 req_builder = req_builder.query(&[("depth", ¶m_value.to_string())]);
53 }
54 if let Some(ref user_agent) = configuration.user_agent {
55 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
56 }
57 if let Some(ref token) = configuration.bearer_access_token {
58 req_builder = req_builder.bearer_auth(token.to_owned());
59 };
60
61 let req = req_builder.build()?;
62 let resp = configuration.client.execute(req).await?;
63
64 let status = resp.status();
65 let content_type = resp
66 .headers()
67 .get("content-type")
68 .and_then(|v| v.to_str().ok())
69 .unwrap_or("application/octet-stream");
70 let content_type = super::ContentType::from(content_type);
71
72 if !status.is_client_error() && !status.is_server_error() {
73 let content = resp.text().await?;
74 match content_type {
75 ContentType::Json => serde_path_to_error::deserialize(&mut serde_json::Deserializer::from_str(&content)).map_err(Error::from),
76 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetByOrgByRepoContent200Response`"))),
77 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetByOrgByRepoContent200Response`")))),
78 }
79 } else {
80 let content = resp.text().await?;
81 let entity: Option<GetByOrgByRepoContentError> = serde_json::from_str(&content).ok();
82 Err(Error::ResponseError(ResponseContent { status, content, entity }))
83 }
84}
85