typesense_rs/apis/
debug_api.rs

1// Typesense API
2//
3// An open source search engine for building delightful search experiences.
4//
5// The version of the OpenAPI document: 27.0
6//
7// Generated by: https://openapi-generator.tech
8
9use std::sync::Arc;
10
11use async_trait::async_trait;
12use reqwest;
13use serde::{Deserialize, Serialize};
14
15use super::{configuration, Error};
16use crate::apis::ResponseContent;
17use crate::models;
18
19#[async_trait]
20pub trait DebugApi: Send + Sync {
21	async fn debug(&self) -> Result<models::Debug200Response, Error<DebugError>>;
22}
23
24pub struct DebugApiClient {
25	configuration: Arc<configuration::Configuration>,
26}
27
28impl DebugApiClient {
29	pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
30		Self { configuration }
31	}
32}
33
34#[async_trait]
35impl DebugApi for DebugApiClient {
36	/// Print debugging information
37	async fn debug(&self) -> Result<models::Debug200Response, Error<DebugError>> {
38		let local_var_configuration = &self.configuration;
39
40		let local_var_client = &local_var_configuration.client;
41
42		let local_var_uri_str = format!("{}/debug", local_var_configuration.base_path);
43		let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
44
45		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
46			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
47		}
48		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
49			let local_var_key = local_var_apikey.key.clone();
50			let local_var_value = match local_var_apikey.prefix {
51				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
52				None => local_var_key,
53			};
54			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
55		};
56
57		let local_var_req = local_var_req_builder.build()?;
58		let local_var_resp = local_var_client.execute(local_var_req).await?;
59
60		let local_var_status = local_var_resp.status();
61		let local_var_content = local_var_resp.text().await?;
62
63		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
64			serde_json::from_str(&local_var_content).map_err(Error::from)
65		} else {
66			let local_var_entity: Option<DebugError> = serde_json::from_str(&local_var_content).ok();
67			let local_var_error = ResponseContent {
68				status: local_var_status,
69				content: local_var_content,
70				entity: local_var_entity,
71			};
72			Err(Error::ResponseError(local_var_error))
73		}
74	}
75}
76
77/// struct for typed errors of method [`debug`]
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum DebugError {
81	UnknownValue(serde_json::Value),
82}