Skip to main content

nautobot_openapi/apis/
swagger_json_api.rs

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