jira_api_v2/apis/
issue_fields_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;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_custom_field`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateCustomFieldError {
22    Status400(),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`get_contexts_for_field_deprecated`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetContextsForFieldDeprecatedError {
30    Status401(),
31    Status403(),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`get_fields`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetFieldsError {
39    Status401(),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`get_fields_paginated`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum GetFieldsPaginatedError {
47    Status400(models::ErrorCollection),
48    Status401(),
49    Status403(models::ErrorCollection),
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`update_custom_field`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum UpdateCustomFieldError {
57    Status400(),
58    Status401(),
59    Status403(),
60    Status404(),
61    UnknownValue(serde_json::Value),
62}
63
64
65/// Creates a custom field.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
66pub async fn create_custom_field(configuration: &configuration::Configuration, custom_field_definition_json_bean: models::CustomFieldDefinitionJsonBean) -> Result<models::FieldDetails, Error<CreateCustomFieldError>> {
67    // add a prefix to parameters to efficiently prevent name collisions
68    let p_custom_field_definition_json_bean = custom_field_definition_json_bean;
69
70    let uri_str = format!("{}/rest/api/2/field", configuration.base_path);
71    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
72
73    if let Some(ref user_agent) = configuration.user_agent {
74        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75    }
76    if let Some(ref token) = configuration.oauth_access_token {
77        req_builder = req_builder.bearer_auth(token.to_owned());
78    };
79    if let Some(ref auth_conf) = configuration.basic_auth {
80        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
81    };
82    req_builder = req_builder.json(&p_custom_field_definition_json_bean);
83
84    let req = req_builder.build()?;
85    let resp = configuration.client.execute(req).await?;
86
87    let status = resp.status();
88
89    if !status.is_client_error() && !status.is_server_error() {
90        let content = resp.text().await?;
91        serde_json::from_str(&content).map_err(Error::from)
92    } else {
93        let content = resp.text().await?;
94        let entity: Option<CreateCustomFieldError> = serde_json::from_str(&content).ok();
95        Err(Error::ResponseError(ResponseContent { status, content, entity }))
96    }
97}
98
99/// Returns a [paginated](#pagination) list of the contexts a field is used in. Deprecated, use [ Get custom field contexts](#api-rest-api-2-field-fieldId-context-get).  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
100pub async fn get_contexts_for_field_deprecated(configuration: &configuration::Configuration, field_id: &str, start_at: Option<i64>, max_results: Option<i32>) -> Result<models::PageBeanContext, Error<GetContextsForFieldDeprecatedError>> {
101    // add a prefix to parameters to efficiently prevent name collisions
102    let p_field_id = field_id;
103    let p_start_at = start_at;
104    let p_max_results = max_results;
105
106    let uri_str = format!("{}/rest/api/2/field/{fieldId}/contexts", configuration.base_path, fieldId=crate::apis::urlencode(p_field_id));
107    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
108
109    if let Some(ref param_value) = p_start_at {
110        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
111    }
112    if let Some(ref param_value) = p_max_results {
113        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
114    }
115    if let Some(ref user_agent) = configuration.user_agent {
116        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
117    }
118    if let Some(ref token) = configuration.oauth_access_token {
119        req_builder = req_builder.bearer_auth(token.to_owned());
120    };
121    if let Some(ref auth_conf) = configuration.basic_auth {
122        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
123    };
124
125    let req = req_builder.build()?;
126    let resp = configuration.client.execute(req).await?;
127
128    let status = resp.status();
129
130    if !status.is_client_error() && !status.is_server_error() {
131        let content = resp.text().await?;
132        serde_json::from_str(&content).map_err(Error::from)
133    } else {
134        let content = resp.text().await?;
135        let entity: Option<GetContextsForFieldDeprecatedError> = serde_json::from_str(&content).ok();
136        Err(Error::ResponseError(ResponseContent { status, content, entity }))
137    }
138}
139
140/// Returns system and custom issue fields according to the following rules:   *  Fields that cannot be added to the issue navigator are always returned.  *  Fields that cannot be placed on an issue screen are always returned.  *  Fields that depend on global Jira settings are only returned if the setting is enabled. That is, timetracking fields, subtasks, votes, and watches.  *  For all other fields, this operation only returns the fields that the user has permission to view (that is, the field is used in at least one project that the user has *Browse Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for.)  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
141pub async fn get_fields(configuration: &configuration::Configuration, ) -> Result<Vec<models::FieldDetails>, Error<GetFieldsError>> {
142
143    let uri_str = format!("{}/rest/api/2/field", configuration.base_path);
144    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
145
146    if let Some(ref user_agent) = configuration.user_agent {
147        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
148    }
149    if let Some(ref token) = configuration.oauth_access_token {
150        req_builder = req_builder.bearer_auth(token.to_owned());
151    };
152    if let Some(ref auth_conf) = configuration.basic_auth {
153        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
154    };
155
156    let req = req_builder.build()?;
157    let resp = configuration.client.execute(req).await?;
158
159    let status = resp.status();
160
161    if !status.is_client_error() && !status.is_server_error() {
162        let content = resp.text().await?;
163        serde_json::from_str(&content).map_err(Error::from)
164    } else {
165        let content = resp.text().await?;
166        let entity: Option<GetFieldsError> = serde_json::from_str(&content).ok();
167        Err(Error::ResponseError(ResponseContent { status, content, entity }))
168    }
169}
170
171/// Returns a [paginated](#pagination) list of fields for Classic Jira projects. The list can include:   *  all fields.  *  specific fields, by defining `id`.  *  fields that contain a string in the field name or description, by defining `query`.  *  specific fields that contain a string in the field name or description, by defining `id` and `query`.  Only custom fields can be queried, `type` must be set to `custom`.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
172pub async fn get_fields_paginated(configuration: &configuration::Configuration, start_at: Option<i64>, max_results: Option<i32>, r#type: Option<Vec<String>>, id: Option<Vec<String>>, query: Option<&str>, order_by: Option<&str>, expand: Option<&str>) -> Result<models::PageBeanField, Error<GetFieldsPaginatedError>> {
173    // add a prefix to parameters to efficiently prevent name collisions
174    let p_start_at = start_at;
175    let p_max_results = max_results;
176    let p_type = r#type;
177    let p_id = id;
178    let p_query = query;
179    let p_order_by = order_by;
180    let p_expand = expand;
181
182    let uri_str = format!("{}/rest/api/2/field/search", configuration.base_path);
183    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
184
185    if let Some(ref param_value) = p_start_at {
186        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
187    }
188    if let Some(ref param_value) = p_max_results {
189        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
190    }
191    if let Some(ref param_value) = p_type {
192        req_builder = match "multi" {
193            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
194            _ => req_builder.query(&[("type", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
195        };
196    }
197    if let Some(ref param_value) = p_id {
198        req_builder = match "multi" {
199            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("id".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
200            _ => req_builder.query(&[("id", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
201        };
202    }
203    if let Some(ref param_value) = p_query {
204        req_builder = req_builder.query(&[("query", &param_value.to_string())]);
205    }
206    if let Some(ref param_value) = p_order_by {
207        req_builder = req_builder.query(&[("orderBy", &param_value.to_string())]);
208    }
209    if let Some(ref param_value) = p_expand {
210        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
211    }
212    if let Some(ref user_agent) = configuration.user_agent {
213        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214    }
215    if let Some(ref token) = configuration.oauth_access_token {
216        req_builder = req_builder.bearer_auth(token.to_owned());
217    };
218    if let Some(ref auth_conf) = configuration.basic_auth {
219        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
220    };
221
222    let req = req_builder.build()?;
223    let resp = configuration.client.execute(req).await?;
224
225    let status = resp.status();
226
227    if !status.is_client_error() && !status.is_server_error() {
228        let content = resp.text().await?;
229        serde_json::from_str(&content).map_err(Error::from)
230    } else {
231        let content = resp.text().await?;
232        let entity: Option<GetFieldsPaginatedError> = serde_json::from_str(&content).ok();
233        Err(Error::ResponseError(ResponseContent { status, content, entity }))
234    }
235}
236
237/// Updates a custom field.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
238pub async fn update_custom_field(configuration: &configuration::Configuration, field_id: &str, update_custom_field_details: models::UpdateCustomFieldDetails) -> Result<serde_json::Value, Error<UpdateCustomFieldError>> {
239    // add a prefix to parameters to efficiently prevent name collisions
240    let p_field_id = field_id;
241    let p_update_custom_field_details = update_custom_field_details;
242
243    let uri_str = format!("{}/rest/api/2/field/{fieldId}", configuration.base_path, fieldId=crate::apis::urlencode(p_field_id));
244    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
245
246    if let Some(ref user_agent) = configuration.user_agent {
247        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
248    }
249    if let Some(ref token) = configuration.oauth_access_token {
250        req_builder = req_builder.bearer_auth(token.to_owned());
251    };
252    if let Some(ref auth_conf) = configuration.basic_auth {
253        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
254    };
255    req_builder = req_builder.json(&p_update_custom_field_details);
256
257    let req = req_builder.build()?;
258    let resp = configuration.client.execute(req).await?;
259
260    let status = resp.status();
261
262    if !status.is_client_error() && !status.is_server_error() {
263        let content = resp.text().await?;
264        serde_json::from_str(&content).map_err(Error::from)
265    } else {
266        let content = resp.text().await?;
267        let entity: Option<UpdateCustomFieldError> = serde_json::from_str(&content).ok();
268        Err(Error::ResponseError(ResponseContent { status, content, entity }))
269    }
270}
271