/*
* The Jira Cloud platform REST API
*
* Jira Cloud platform REST API documentation
*
* The version of the OpenAPI document: 1001.0.0-SNAPSHOT
* Contact: ecosystem@atlassian.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
/// struct for typed errors of method [`get_issue_picker_resource`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetIssuePickerResourceError {
Status401(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`match_issues`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum MatchIssuesError {
Status400(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`search_for_issues_using_jql`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchForIssuesUsingJqlError {
Status400(),
Status401(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`search_for_issues_using_jql_post`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchForIssuesUsingJqlPostError {
Status400(),
Status401(),
UnknownValue(serde_json::Value),
}
/// 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.
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query = query;
let p_current_jql = current_jql;
let p_current_issue_key = current_issue_key;
let p_current_project_id = current_project_id;
let p_show_sub_tasks = show_sub_tasks;
let p_show_sub_task_parent = show_sub_task_parent;
let uri_str = format!("{}/rest/api/2/issue/picker", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query {
req_builder = req_builder.query(&[("query", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_current_jql {
req_builder = req_builder.query(&[("currentJQL", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_current_issue_key {
req_builder = req_builder.query(&[("currentIssueKey", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_current_project_id {
req_builder = req_builder.query(&[("currentProjectId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_show_sub_tasks {
req_builder = req_builder.query(&[("showSubTasks", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_show_sub_task_parent {
req_builder = req_builder.query(&[("showSubTaskParent", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<GetIssuePickerResourceError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn match_issues(configuration: &configuration::Configuration, issues_and_jql_queries: models::IssuesAndJqlQueries) -> Result<models::IssueMatches, Error<MatchIssuesError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_issues_and_jql_queries = issues_and_jql_queries;
let uri_str = format!("{}/rest/api/2/jql/match", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_issues_and_jql_queries);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<MatchIssuesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub 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>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_jql = jql;
let p_start_at = start_at;
let p_max_results = max_results;
let p_validate_query = validate_query;
let p_fields = fields;
let p_expand = expand;
let p_properties = properties;
let p_fields_by_keys = fields_by_keys;
let uri_str = format!("{}/rest/api/2/search", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_jql {
req_builder = req_builder.query(&[("jql", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_start_at {
req_builder = req_builder.query(&[("startAt", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_max_results {
req_builder = req_builder.query(&[("maxResults", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_validate_query {
req_builder = req_builder.query(&[("validateQuery", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_fields {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("fields".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("fields", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_expand {
req_builder = req_builder.query(&[("expand", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_properties {
req_builder = match "multi" {
"multi" => req_builder.query(¶m_value.into_iter().map(|p| ("properties".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
_ => req_builder.query(&[("properties", ¶m_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
};
}
if let Some(ref param_value) = p_fields_by_keys {
req_builder = req_builder.query(&[("fieldsByKeys", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<SearchForIssuesUsingJqlError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// 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.
pub async fn search_for_issues_using_jql_post(configuration: &configuration::Configuration, search_request_bean: models::SearchRequestBean) -> Result<models::SearchResults, Error<SearchForIssuesUsingJqlPostError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_search_request_bean = search_request_bean;
let uri_str = format!("{}/rest/api/2/search", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_search_request_bean);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<SearchForIssuesUsingJqlPostError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}