Skip to main content

gitbundle_sdk/apis/
keyword_search_api.rs

1/*
2 * GitBundle API
3 *
4 * GitBundle API documentation.
5 *
6 * The version of the OpenAPI document: 3.4.1
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`search`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum SearchError {
21    UnknownValue(serde_json::Value),
22}
23
24pub async fn search(
25    configuration: &configuration::Configuration,
26) -> Result<String, Error<SearchError>> {
27    let uri_str = format!("{}/search", configuration.base_path);
28    let mut req_builder = configuration
29        .client
30        .request(reqwest::Method::POST, &uri_str);
31
32    if let Some(ref user_agent) = configuration.user_agent {
33        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
34    }
35
36    let req = req_builder.build()?;
37    let resp = configuration.client.execute(req).await?;
38
39    let status = resp.status();
40    let content_type = resp
41        .headers()
42        .get("content-type")
43        .and_then(|v| v.to_str().ok())
44        .unwrap_or("application/octet-stream");
45    let content_type = super::ContentType::from(content_type);
46
47    if !status.is_client_error() && !status.is_server_error() {
48        let content = resp.text().await?;
49        match content_type {
50            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
51            ContentType::Text => Ok(content),
52            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
53        }
54    } else {
55        let content = resp.text().await?;
56        let entity: Option<SearchError> = serde_json::from_str(&content).ok();
57        Err(Error::ResponseError(ResponseContent {
58            status,
59            content,
60            entity,
61        }))
62    }
63}