authentik_client/apis/
schema_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 SchemaRetrieveError {
20 Status400(models::ValidationError),
21 Status403(models::GenericError),
22 UnknownValue(serde_json::Value),
23}
24
25pub async fn schema_retrieve(
27 configuration: &configuration::Configuration,
28 format: Option<&str>,
29 lang: Option<&str>,
30) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<SchemaRetrieveError>> {
31 let p_query_format = format;
33 let p_query_lang = lang;
34
35 let uri_str = format!("{}/schema/", configuration.base_path);
36 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
37
38 if let Some(ref param_value) = p_query_format {
39 req_builder = req_builder.query(&[("format", ¶m_value.to_string())]);
40 }
41 if let Some(ref param_value) = p_query_lang {
42 req_builder = req_builder.query(&[("lang", ¶m_value.to_string())]);
43 }
44 if let Some(ref user_agent) = configuration.user_agent {
45 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
46 }
47 if let Some(ref token) = configuration.bearer_access_token {
48 req_builder = req_builder.bearer_auth(token.to_owned());
49 };
50
51 let req = req_builder.build()?;
52 let resp = configuration.client.execute(req).await?;
53
54 let status = resp.status();
55 let content_type = resp
56 .headers()
57 .get("content-type")
58 .and_then(|v| v.to_str().ok())
59 .unwrap_or("application/octet-stream");
60 let content_type = super::ContentType::from(content_type);
61
62 if !status.is_client_error() && !status.is_server_error() {
63 let content = resp.text().await?;
64 match content_type {
65 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
66 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
67 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
68 }
69 } else {
70 let content = resp.text().await?;
71 let entity: Option<SchemaRetrieveError> = serde_json::from_str(&content).ok();
72 Err(Error::ResponseError(ResponseContent {
73 status,
74 content,
75 entity,
76 }))
77 }
78}