jira/gen/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
11use super::{configuration, Error};
12use crate::gen::apis::ResponseContent;
13use crate::gen::models;
14
15/// struct for passing parameters to the method `create_custom_field`
16#[derive(Clone, Debug)]
17pub struct CreateCustomFieldParams {
18    /// Definition of the custom field to be created
19    pub custom_field_definition_json_bean: models::CustomFieldDefinitionJsonBean,
20}
21
22/// struct for passing parameters to the method `get_contexts_for_field_deprecated`
23#[derive(Clone, Debug)]
24pub struct GetContextsForFieldDeprecatedParams {
25    /// The ID of the field to return contexts for.
26    pub field_id: String,
27    /// The index of the first item to return in a page of results (page offset).
28    pub start_at: Option<i64>,
29    /// The maximum number of items to return per page.
30    pub max_results: Option<i32>,
31}
32
33/// struct for passing parameters to the method `get_fields_paginated`
34#[derive(Clone, Debug)]
35pub struct GetFieldsPaginatedParams {
36    /// The index of the first item to return in a page of results (page offset).
37    pub start_at: Option<i64>,
38    /// The maximum number of items to return per page.
39    pub max_results: Option<i32>,
40    /// The type of fields to search.
41    pub _type: Option<Vec<String>>,
42    /// The IDs of the custom fields to return or, where `query` is specified, filter.
43    pub id: Option<Vec<String>>,
44    /// String used to perform a case-insensitive partial match with field names or descriptions.
45    pub query: Option<String>,
46    /// [Order](#ordering) the results by a field:   *  `contextsCount` Sorts by the number of contexts related to a field.  *  `lastUsed` Sorts by the date when the value of the field last changed.  *  `name` Sorts by the field name.  *  `screensCount` Sorts by the number of screens related to a field.
47    pub order_by: Option<String>,
48    /// Use [expand](#expansion) to include additional information in the response. This parameter accepts a comma-separated list. Expand options include:   *  `key` Returns the key for each field.  *  `lastUsed` Returns the date when the value of the field last changed.  *  `screensCount` Returns the number of screens related to a field.  *  `contextsCount` Returns the number of contexts related to a field.  *  `isLocked` Returns information about whether the field is [locked](https://confluence.atlassian.com/x/ZSN7Og).
49    pub expand: Option<String>,
50}
51
52/// struct for typed errors of method `create_custom_field`
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum CreateCustomFieldError {
56    Status400(),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method `get_contexts_for_field_deprecated`
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum GetContextsForFieldDeprecatedError {
64    Status401(),
65    Status403(),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method `get_fields`
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum GetFieldsError {
73    Status401(),
74    UnknownValue(serde_json::Value),
75}
76
77/// struct for typed errors of method `get_fields_paginated`
78#[derive(Debug, Clone, Serialize, Deserialize)]
79#[serde(untagged)]
80pub enum GetFieldsPaginatedError {
81    Status400(models::ErrorCollection),
82    Status401(),
83    Status403(models::ErrorCollection),
84    UnknownValue(serde_json::Value),
85}
86
87/// Creates a custom field.  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
88pub async fn create_custom_field(
89    configuration: &configuration::Configuration,
90    params: CreateCustomFieldParams,
91) -> Result<models::FieldDetails, Error<CreateCustomFieldError>> {
92    // unbox the parameters
93    let custom_field_definition_json_bean = params.custom_field_definition_json_bean;
94
95    let local_var_client = &configuration.client;
96
97    let local_var_uri_str = format!("{}/rest/api/3/field", configuration.base_path);
98    let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
99
100    if let Some(ref local_var_user_agent) = configuration.user_agent {
101        local_var_req_builder =
102            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
103    }
104    if let Some(ref local_var_token) = configuration.oauth_access_token {
105        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
106    };
107    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
108        local_var_req_builder = local_var_req_builder.basic_auth(
109            local_var_auth_conf.0.to_owned(),
110            local_var_auth_conf.1.to_owned(),
111        );
112    };
113    local_var_req_builder = local_var_req_builder.json(&custom_field_definition_json_bean);
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        serde_json::from_str(&local_var_content).map_err(Error::from)
123    } else {
124        let local_var_entity: Option<CreateCustomFieldError> =
125            serde_json::from_str(&local_var_content).ok();
126        let local_var_error = ResponseContent {
127            status: local_var_status,
128            content: local_var_content,
129            entity: local_var_entity,
130        };
131        Err(Error::ResponseError(local_var_error))
132    }
133}
134
135/// Returns a [paginated](#pagination) list of the contexts a field is used in. Deprecated, use [ Get custom field contexts](#api-rest-api-3-field-fieldId-context-get).  **[Permissions](#permissions) required:** *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg).
136pub async fn get_contexts_for_field_deprecated(
137    configuration: &configuration::Configuration,
138    params: GetContextsForFieldDeprecatedParams,
139) -> Result<models::PageBeanContext, Error<GetContextsForFieldDeprecatedError>> {
140    // unbox the parameters
141    let field_id = params.field_id;
142    let start_at = params.start_at;
143    let max_results = params.max_results;
144
145    let local_var_client = &configuration.client;
146
147    let local_var_uri_str = format!(
148        "{}/rest/api/3/field/{fieldId}/contexts",
149        configuration.base_path,
150        fieldId = crate::gen::apis::urlencode(field_id)
151    );
152    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
153
154    if let Some(ref local_var_str) = start_at {
155        local_var_req_builder =
156            local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
157    }
158    if let Some(ref local_var_str) = max_results {
159        local_var_req_builder =
160            local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
161    }
162    if let Some(ref local_var_user_agent) = configuration.user_agent {
163        local_var_req_builder =
164            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
165    }
166    if let Some(ref local_var_token) = configuration.oauth_access_token {
167        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
168    };
169    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
170        local_var_req_builder = local_var_req_builder.basic_auth(
171            local_var_auth_conf.0.to_owned(),
172            local_var_auth_conf.1.to_owned(),
173        );
174    };
175
176    let local_var_req = local_var_req_builder.build()?;
177    let local_var_resp = local_var_client.execute(local_var_req).await?;
178
179    let local_var_status = local_var_resp.status();
180    let local_var_content = local_var_resp.text().await?;
181
182    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
183        serde_json::from_str(&local_var_content).map_err(Error::from)
184    } else {
185        let local_var_entity: Option<GetContextsForFieldDeprecatedError> =
186            serde_json::from_str(&local_var_content).ok();
187        let local_var_error = ResponseContent {
188            status: local_var_status,
189            content: local_var_content,
190            entity: local_var_entity,
191        };
192        Err(Error::ResponseError(local_var_error))
193    }
194}
195
196/// 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.
197pub async fn get_fields(
198    configuration: &configuration::Configuration,
199) -> Result<Vec<models::FieldDetails>, Error<GetFieldsError>> {
200    // unbox the parameters
201
202    let local_var_client = &configuration.client;
203
204    let local_var_uri_str = format!("{}/rest/api/3/field", configuration.base_path);
205    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
206
207    if let Some(ref local_var_user_agent) = configuration.user_agent {
208        local_var_req_builder =
209            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
210    }
211    if let Some(ref local_var_token) = configuration.oauth_access_token {
212        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
213    };
214    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
215        local_var_req_builder = local_var_req_builder.basic_auth(
216            local_var_auth_conf.0.to_owned(),
217            local_var_auth_conf.1.to_owned(),
218        );
219    };
220
221    let local_var_req = local_var_req_builder.build()?;
222    let local_var_resp = local_var_client.execute(local_var_req).await?;
223
224    let local_var_status = local_var_resp.status();
225    let local_var_content = local_var_resp.text().await?;
226
227    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
228        serde_json::from_str(&local_var_content).map_err(Error::from)
229    } else {
230        let local_var_entity: Option<GetFieldsError> =
231            serde_json::from_str(&local_var_content).ok();
232        let local_var_error = ResponseContent {
233            status: local_var_status,
234            content: local_var_content,
235            entity: local_var_entity,
236        };
237        Err(Error::ResponseError(local_var_error))
238    }
239}
240
241/// 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).
242pub async fn get_fields_paginated(
243    configuration: &configuration::Configuration,
244    params: GetFieldsPaginatedParams,
245) -> Result<models::PageBeanField, Error<GetFieldsPaginatedError>> {
246    // unbox the parameters
247    let start_at = params.start_at;
248    let max_results = params.max_results;
249    let _type = params._type;
250    let id = params.id;
251    let query = params.query;
252    let order_by = params.order_by;
253    let expand = params.expand;
254
255    let local_var_client = &configuration.client;
256
257    let local_var_uri_str = format!("{}/rest/api/3/field/search", configuration.base_path);
258    let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
259
260    if let Some(ref local_var_str) = start_at {
261        local_var_req_builder =
262            local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
263    }
264    if let Some(ref local_var_str) = max_results {
265        local_var_req_builder =
266            local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
267    }
268    if let Some(ref local_var_str) = _type {
269        local_var_req_builder = local_var_req_builder.query(&[(
270            "type",
271            &local_var_str
272                .into_iter()
273                .map(|p| p.to_string())
274                .collect::<Vec<String>>()
275                .join(",")
276                .to_string(),
277        )]);
278    }
279    if let Some(ref local_var_str) = id {
280        local_var_req_builder = local_var_req_builder.query(&[(
281            "id",
282            &local_var_str
283                .into_iter()
284                .map(|p| p.to_string())
285                .collect::<Vec<String>>()
286                .join(",")
287                .to_string(),
288        )]);
289    }
290    if let Some(ref local_var_str) = query {
291        local_var_req_builder =
292            local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
293    }
294    if let Some(ref local_var_str) = order_by {
295        local_var_req_builder =
296            local_var_req_builder.query(&[("orderBy", &local_var_str.to_string())]);
297    }
298    if let Some(ref local_var_str) = expand {
299        local_var_req_builder =
300            local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
301    }
302    if let Some(ref local_var_user_agent) = configuration.user_agent {
303        local_var_req_builder =
304            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
305    }
306    if let Some(ref local_var_token) = configuration.oauth_access_token {
307        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
308    };
309    if let Some(ref local_var_auth_conf) = configuration.basic_auth {
310        local_var_req_builder = local_var_req_builder.basic_auth(
311            local_var_auth_conf.0.to_owned(),
312            local_var_auth_conf.1.to_owned(),
313        );
314    };
315
316    let local_var_req = local_var_req_builder.build()?;
317    let local_var_resp = local_var_client.execute(local_var_req).await?;
318
319    let local_var_status = local_var_resp.status();
320    let local_var_content = local_var_resp.text().await?;
321
322    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
323        serde_json::from_str(&local_var_content).map_err(Error::from)
324    } else {
325        let local_var_entity: Option<GetFieldsPaginatedError> =
326            serde_json::from_str(&local_var_content).ok();
327        let local_var_error = ResponseContent {
328            status: local_var_status,
329            content: local_var_content,
330            entity: local_var_entity,
331        };
332        Err(Error::ResponseError(local_var_error))
333    }
334}