jirav2/apis/
project_key_and_name_validation_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`get_valid_project_key`]
18#[derive(Clone, Debug, Default)]
19pub struct GetValidProjectKeyParams {
20    /// The project key.
21    pub key: Option<String>
22}
23
24/// struct for passing parameters to the method [`get_valid_project_name`]
25#[derive(Clone, Debug, Default)]
26pub struct GetValidProjectNameParams {
27    /// The project name.
28    pub name: String
29}
30
31/// struct for passing parameters to the method [`validate_project_key`]
32#[derive(Clone, Debug, Default)]
33pub struct ValidateProjectKeyParams {
34    /// The project key.
35    pub key: Option<String>
36}
37
38
39/// struct for typed successes of method [`get_valid_project_key`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetValidProjectKeySuccess {
43    Status200(String),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed successes of method [`get_valid_project_name`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum GetValidProjectNameSuccess {
51    Status200(String),
52    UnknownValue(serde_json::Value),
53}
54
55/// struct for typed successes of method [`validate_project_key`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum ValidateProjectKeySuccess {
59    Status200(crate::models::ErrorCollection),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`get_valid_project_key`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetValidProjectKeyError {
67    Status401(),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`get_valid_project_name`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum GetValidProjectNameError {
75    Status400(),
76    Status401(),
77    Status404(),
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`validate_project_key`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum ValidateProjectKeyError {
85    Status401(),
86    UnknownValue(serde_json::Value),
87}
88
89
90/// Validates a project key and, if the key is invalid or in use, generates a valid random string for the project key.  **[Permissions](#permissions) required:** None.
91pub async fn get_valid_project_key(configuration: &configuration::Configuration, params: GetValidProjectKeyParams) -> Result<ResponseContent<GetValidProjectKeySuccess>, Error<GetValidProjectKeyError>> {
92    let local_var_configuration = configuration;
93
94    // unbox the parameters
95    let key = params.key;
96
97
98    let local_var_client = &local_var_configuration.client;
99
100    let local_var_uri_str = format!("{}/rest/api/2/projectvalidate/validProjectKey", local_var_configuration.base_path);
101    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
102
103    if let Some(ref local_var_str) = key {
104        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
105    }
106    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
107        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
108    }
109    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
110        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
111    };
112
113    let local_var_req = local_var_req_builder.build()?;
114    let local_var_resp = local_var_client.execute(local_var_req).await?;
115
116    let local_var_status = local_var_resp.status();
117    let local_var_content = local_var_resp.text().await?;
118
119    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
120        let local_var_entity: Option<GetValidProjectKeySuccess> = serde_json::from_str(&local_var_content).ok();
121        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
122        Ok(local_var_result)
123    } else {
124        let local_var_entity: Option<GetValidProjectKeyError> = serde_json::from_str(&local_var_content).ok();
125        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129
130/// Checks that a project name isn't in use. If the name isn't in use, the passed string is returned. If the name is in use, this operation attempts to generate a valid project name based on the one supplied, usually by adding a sequence number. If a valid project name cannot be generated, a 404 response is returned.  **[Permissions](#permissions) required:** None.
131pub async fn get_valid_project_name(configuration: &configuration::Configuration, params: GetValidProjectNameParams) -> Result<ResponseContent<GetValidProjectNameSuccess>, Error<GetValidProjectNameError>> {
132    let local_var_configuration = configuration;
133
134    // unbox the parameters
135    let name = params.name;
136
137
138    let local_var_client = &local_var_configuration.client;
139
140    let local_var_uri_str = format!("{}/rest/api/2/projectvalidate/validProjectName", local_var_configuration.base_path);
141    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
142
143    local_var_req_builder = local_var_req_builder.query(&[("name", &name.to_string())]);
144    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
145        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
146    }
147    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
148        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
149    };
150
151    let local_var_req = local_var_req_builder.build()?;
152    let local_var_resp = local_var_client.execute(local_var_req).await?;
153
154    let local_var_status = local_var_resp.status();
155    let local_var_content = local_var_resp.text().await?;
156
157    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158        let local_var_entity: Option<GetValidProjectNameSuccess> = serde_json::from_str(&local_var_content).ok();
159        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
160        Ok(local_var_result)
161    } else {
162        let local_var_entity: Option<GetValidProjectNameError> = serde_json::from_str(&local_var_content).ok();
163        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
164        Err(Error::ResponseError(local_var_error))
165    }
166}
167
168/// Validates a project key by confirming the key is a valid string and not in use.  **[Permissions](#permissions) required:** None.
169pub async fn validate_project_key(configuration: &configuration::Configuration, params: ValidateProjectKeyParams) -> Result<ResponseContent<ValidateProjectKeySuccess>, Error<ValidateProjectKeyError>> {
170    let local_var_configuration = configuration;
171
172    // unbox the parameters
173    let key = params.key;
174
175
176    let local_var_client = &local_var_configuration.client;
177
178    let local_var_uri_str = format!("{}/rest/api/2/projectvalidate/key", local_var_configuration.base_path);
179    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
180
181    if let Some(ref local_var_str) = key {
182        local_var_req_builder = local_var_req_builder.query(&[("key", &local_var_str.to_string())]);
183    }
184    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
185        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
186    }
187    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
188        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
189    };
190    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
191        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
192    };
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        let local_var_entity: Option<ValidateProjectKeySuccess> = serde_json::from_str(&local_var_content).ok();
202        let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
203        Ok(local_var_result)
204    } else {
205        let local_var_entity: Option<ValidateProjectKeyError> = serde_json::from_str(&local_var_content).ok();
206        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
207        Err(Error::ResponseError(local_var_error))
208    }
209}
210