authentik_rust/apis/
schema_api.rs

1/*
2 * authentik
3 *
4 * Making authentication simple.
5 *
6 * The version of the OpenAPI document: 2024.2.1
7 * Contact: hello@goauthentik.io
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`schema_retrieve`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum SchemaRetrieveError {
22    Status400(models::ValidationError),
23    Status403(models::GenericError),
24    UnknownValue(serde_json::Value),
25}
26
27
28/// OpenApi3 schema for this API. Format can be selected via content negotiation.  - YAML: application/vnd.oai.openapi - JSON: application/vnd.oai.openapi+json
29pub async fn schema_retrieve(configuration: &configuration::Configuration, format: Option<&str>, lang: Option<&str>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<SchemaRetrieveError>> {
30    let local_var_configuration = configuration;
31
32    let local_var_client = &local_var_configuration.client;
33
34    let local_var_uri_str = format!("{}/schema/", local_var_configuration.base_path);
35    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
36
37    if let Some(ref local_var_str) = format {
38        local_var_req_builder = local_var_req_builder.query(&[("format", &local_var_str.to_string())]);
39    }
40    if let Some(ref local_var_str) = lang {
41        local_var_req_builder = local_var_req_builder.query(&[("lang", &local_var_str.to_string())]);
42    }
43    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
44        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
45    }
46    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
47        let local_var_key = local_var_apikey.key.clone();
48        let local_var_value = match local_var_apikey.prefix {
49            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
50            None => local_var_key,
51        };
52        local_var_req_builder = local_var_req_builder.header("Authorization", local_var_value);
53    };
54
55    let local_var_req = local_var_req_builder.build()?;
56    let local_var_resp = local_var_client.execute(local_var_req).await?;
57
58    let local_var_status = local_var_resp.status();
59    let local_var_content = local_var_resp.text().await?;
60
61    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
62        serde_json::from_str(&local_var_content).map_err(Error::from)
63    } else {
64        let local_var_entity: Option<SchemaRetrieveError> = serde_json::from_str(&local_var_content).ok();
65        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
66        Err(Error::ResponseError(local_var_error))
67    }
68}
69