jira_api_v2/apis/
issue_search_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 [`get_issue_picker_resource`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetIssuePickerResourceError {
22    Status401(),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`match_issues`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum MatchIssuesError {
30    Status400(),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`search_for_issues_using_jql`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum SearchForIssuesUsingJqlError {
38    Status400(),
39    Status401(),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`search_for_issues_using_jql_post`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum SearchForIssuesUsingJqlPostError {
47    Status400(),
48    Status401(),
49    UnknownValue(serde_json::Value),
50}
51
52
53/// Returns lists of issues matching a query string. Use this resource to provide auto-completion suggestions when the user is looking for an issue using a word or string.  This operation returns two lists:   *  `History Search` which includes issues from the user's history of created, edited, or viewed issues that contain the string in the `query` parameter.  *  `Current Search` which includes issues that match the JQL expression in `currentJQL` and contain the string in the `query` parameter.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
54pub async fn get_issue_picker_resource(configuration: &configuration::Configuration, query: Option<&str>, current_jql: Option<&str>, current_issue_key: Option<&str>, current_project_id: Option<&str>, show_sub_tasks: Option<bool>, show_sub_task_parent: Option<bool>) -> Result<models::IssuePickerSuggestions, Error<GetIssuePickerResourceError>> {
55    // add a prefix to parameters to efficiently prevent name collisions
56    let p_query = query;
57    let p_current_jql = current_jql;
58    let p_current_issue_key = current_issue_key;
59    let p_current_project_id = current_project_id;
60    let p_show_sub_tasks = show_sub_tasks;
61    let p_show_sub_task_parent = show_sub_task_parent;
62
63    let uri_str = format!("{}/rest/api/2/issue/picker", configuration.base_path);
64    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
65
66    if let Some(ref param_value) = p_query {
67        req_builder = req_builder.query(&[("query", &param_value.to_string())]);
68    }
69    if let Some(ref param_value) = p_current_jql {
70        req_builder = req_builder.query(&[("currentJQL", &param_value.to_string())]);
71    }
72    if let Some(ref param_value) = p_current_issue_key {
73        req_builder = req_builder.query(&[("currentIssueKey", &param_value.to_string())]);
74    }
75    if let Some(ref param_value) = p_current_project_id {
76        req_builder = req_builder.query(&[("currentProjectId", &param_value.to_string())]);
77    }
78    if let Some(ref param_value) = p_show_sub_tasks {
79        req_builder = req_builder.query(&[("showSubTasks", &param_value.to_string())]);
80    }
81    if let Some(ref param_value) = p_show_sub_task_parent {
82        req_builder = req_builder.query(&[("showSubTaskParent", &param_value.to_string())]);
83    }
84    if let Some(ref user_agent) = configuration.user_agent {
85        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
86    }
87    if let Some(ref token) = configuration.oauth_access_token {
88        req_builder = req_builder.bearer_auth(token.to_owned());
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<GetIssuePickerResourceError> = serde_json::from_str(&content).ok();
105        Err(Error::ResponseError(ResponseContent { status, content, entity }))
106    }
107}
108
109/// Checks whether one or more issues would be returned by one or more JQL queries.  **[Permissions](#permissions) required:** None, however, issues are only matched against JQL queries where the user has:   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
110pub async fn match_issues(configuration: &configuration::Configuration, issues_and_jql_queries: models::IssuesAndJqlQueries) -> Result<models::IssueMatches, Error<MatchIssuesError>> {
111    // add a prefix to parameters to efficiently prevent name collisions
112    let p_issues_and_jql_queries = issues_and_jql_queries;
113
114    let uri_str = format!("{}/rest/api/2/jql/match", configuration.base_path);
115    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
116
117    if let Some(ref user_agent) = configuration.user_agent {
118        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
119    }
120    if let Some(ref token) = configuration.oauth_access_token {
121        req_builder = req_builder.bearer_auth(token.to_owned());
122    };
123    if let Some(ref auth_conf) = configuration.basic_auth {
124        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
125    };
126    req_builder = req_builder.json(&p_issues_and_jql_queries);
127
128    let req = req_builder.build()?;
129    let resp = configuration.client.execute(req).await?;
130
131    let status = resp.status();
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        serde_json::from_str(&content).map_err(Error::from)
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<MatchIssuesError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent { status, content, entity }))
140    }
141}
142
143/// Searches for issues using [JQL](https://confluence.atlassian.com/x/egORLQ).  If the JQL query expression is too large to be encoded as a query parameter, use the [POST](#api-rest-api-2-search-post) version of this resource.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** Issues are included in the response where the user has:   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project containing the issue.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
144pub async fn search_for_issues_using_jql(configuration: &configuration::Configuration, jql: Option<&str>, start_at: Option<i32>, max_results: Option<i32>, validate_query: Option<&str>, fields: Option<Vec<String>>, expand: Option<&str>, properties: Option<Vec<String>>, fields_by_keys: Option<bool>) -> Result<models::SearchResults, Error<SearchForIssuesUsingJqlError>> {
145    // add a prefix to parameters to efficiently prevent name collisions
146    let p_jql = jql;
147    let p_start_at = start_at;
148    let p_max_results = max_results;
149    let p_validate_query = validate_query;
150    let p_fields = fields;
151    let p_expand = expand;
152    let p_properties = properties;
153    let p_fields_by_keys = fields_by_keys;
154
155    let uri_str = format!("{}/rest/api/2/search", configuration.base_path);
156    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
157
158    if let Some(ref param_value) = p_jql {
159        req_builder = req_builder.query(&[("jql", &param_value.to_string())]);
160    }
161    if let Some(ref param_value) = p_start_at {
162        req_builder = req_builder.query(&[("startAt", &param_value.to_string())]);
163    }
164    if let Some(ref param_value) = p_max_results {
165        req_builder = req_builder.query(&[("maxResults", &param_value.to_string())]);
166    }
167    if let Some(ref param_value) = p_validate_query {
168        req_builder = req_builder.query(&[("validateQuery", &param_value.to_string())]);
169    }
170    if let Some(ref param_value) = p_fields {
171        req_builder = match "multi" {
172            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("fields".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
173            _ => req_builder.query(&[("fields", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
174        };
175    }
176    if let Some(ref param_value) = p_expand {
177        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
178    }
179    if let Some(ref param_value) = p_properties {
180        req_builder = match "multi" {
181            "multi" => req_builder.query(&param_value.into_iter().map(|p| ("properties".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
182            _ => req_builder.query(&[("properties", &param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
183        };
184    }
185    if let Some(ref param_value) = p_fields_by_keys {
186        req_builder = req_builder.query(&[("fieldsByKeys", &param_value.to_string())]);
187    }
188    if let Some(ref user_agent) = configuration.user_agent {
189        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
190    }
191    if let Some(ref token) = configuration.oauth_access_token {
192        req_builder = req_builder.bearer_auth(token.to_owned());
193    };
194    if let Some(ref auth_conf) = configuration.basic_auth {
195        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
196    };
197
198    let req = req_builder.build()?;
199
200    let resp = configuration.client.execute(req).await?;
201
202    let status = resp.status();
203
204    if !status.is_client_error() && !status.is_server_error() {
205        let content = resp.text().await?;
206        serde_json::from_str(&content).map_err(Error::from)
207    } else {
208        let content = resp.text().await?;
209        let entity: Option<SearchForIssuesUsingJqlError> = serde_json::from_str(&content).ok();
210        Err(Error::ResponseError(ResponseContent { status, content, entity }))
211    }
212}
213
214/// Searches for issues using [JQL](https://confluence.atlassian.com/x/egORLQ).  There is a [GET](#api-rest-api-2-search-get) version of this resource that can be used for smaller JQL query expressions.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** Issues are included in the response where the user has:   *  *Browse projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project containing the issue.  *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
215pub async fn search_for_issues_using_jql_post(configuration: &configuration::Configuration, search_request_bean: models::SearchRequestBean) -> Result<models::SearchResults, Error<SearchForIssuesUsingJqlPostError>> {
216    // add a prefix to parameters to efficiently prevent name collisions
217    let p_search_request_bean = search_request_bean;
218
219    let uri_str = format!("{}/rest/api/2/search", configuration.base_path);
220    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
221
222    if let Some(ref user_agent) = configuration.user_agent {
223        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224    }
225    if let Some(ref token) = configuration.oauth_access_token {
226        req_builder = req_builder.bearer_auth(token.to_owned());
227    };
228    if let Some(ref auth_conf) = configuration.basic_auth {
229        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
230    };
231    req_builder = req_builder.json(&p_search_request_bean);
232
233    let req = req_builder.build()?;
234    let resp = configuration.client.execute(req).await?;
235
236    let status = resp.status();
237
238    if !status.is_client_error() && !status.is_server_error() {
239        let content = resp.text().await?;
240        serde_json::from_str(&content).map_err(Error::from)
241    } else {
242        let content = resp.text().await?;
243        let entity: Option<SearchForIssuesUsingJqlPostError> = serde_json::from_str(&content).ok();
244        Err(Error::ResponseError(ResponseContent { status, content, entity }))
245    }
246}
247