jira_api_v2/apis/
project_key_and_name_validation_api.rs1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetValidProjectKeyError {
22 Status401(),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetValidProjectNameError {
30 Status400(),
31 Status401(),
32 Status404(),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum ValidateProjectKeyError {
40 Status401(),
41 UnknownValue(serde_json::Value),
42}
43
44
45pub async fn get_valid_project_key(configuration: &configuration::Configuration, key: Option<&str>) -> Result<String, Error<GetValidProjectKeyError>> {
47 let p_key = key;
49
50 let uri_str = format!("{}/rest/api/2/projectvalidate/validProjectKey", configuration.base_path);
51 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
52
53 if let Some(ref param_value) = p_key {
54 req_builder = req_builder.query(&[("key", ¶m_value.to_string())]);
55 }
56 if let Some(ref user_agent) = configuration.user_agent {
57 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58 }
59 if let Some(ref auth_conf) = configuration.basic_auth {
60 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
61 };
62
63 let req = req_builder.build()?;
64 let resp = configuration.client.execute(req).await?;
65
66 let status = resp.status();
67
68 if !status.is_client_error() && !status.is_server_error() {
69 let content = resp.text().await?;
70 serde_json::from_str(&content).map_err(Error::from)
71 } else {
72 let content = resp.text().await?;
73 let entity: Option<GetValidProjectKeyError> = serde_json::from_str(&content).ok();
74 Err(Error::ResponseError(ResponseContent { status, content, entity }))
75 }
76}
77
78pub async fn get_valid_project_name(configuration: &configuration::Configuration, name: &str) -> Result<String, Error<GetValidProjectNameError>> {
80 let p_name = name;
82
83 let uri_str = format!("{}/rest/api/2/projectvalidate/validProjectName", configuration.base_path);
84 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
85
86 req_builder = req_builder.query(&[("name", &p_name.to_string())]);
87 if let Some(ref user_agent) = configuration.user_agent {
88 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89 }
90 if let Some(ref auth_conf) = configuration.basic_auth {
91 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
92 };
93
94 let req = req_builder.build()?;
95 let resp = configuration.client.execute(req).await?;
96
97 let status = resp.status();
98
99 if !status.is_client_error() && !status.is_server_error() {
100 let content = resp.text().await?;
101 serde_json::from_str(&content).map_err(Error::from)
102 } else {
103 let content = resp.text().await?;
104 let entity: Option<GetValidProjectNameError> = serde_json::from_str(&content).ok();
105 Err(Error::ResponseError(ResponseContent { status, content, entity }))
106 }
107}
108
109pub async fn validate_project_key(configuration: &configuration::Configuration, key: Option<&str>) -> Result<models::ErrorCollection, Error<ValidateProjectKeyError>> {
111 let p_key = key;
113
114 let uri_str = format!("{}/rest/api/2/projectvalidate/key", configuration.base_path);
115 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
116
117 if let Some(ref param_value) = p_key {
118 req_builder = req_builder.query(&[("key", ¶m_value.to_string())]);
119 }
120 if let Some(ref user_agent) = configuration.user_agent {
121 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
122 }
123 if let Some(ref token) = configuration.oauth_access_token {
124 req_builder = req_builder.bearer_auth(token.to_owned());
125 };
126 if let Some(ref auth_conf) = configuration.basic_auth {
127 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
128 };
129
130 let req = req_builder.build()?;
131 let resp = configuration.client.execute(req).await?;
132
133 let status = resp.status();
134
135 if !status.is_client_error() && !status.is_server_error() {
136 let content = resp.text().await?;
137 serde_json::from_str(&content).map_err(Error::from)
138 } else {
139 let content = resp.text().await?;
140 let entity: Option<ValidateProjectKeyError> = serde_json::from_str(&content).ok();
141 Err(Error::ResponseError(ResponseContent { status, content, entity }))
142 }
143}
144