From 28978964a77e853031874230c2415b1b835e93fc Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 15 May 2018 00:35:52 -0700 Subject: fmt and cleanup --- rust/fatcat-api/src/client.rs | 1315 +++++++++++-------- rust/fatcat-api/src/lib.rs | 573 +++++---- rust/fatcat-api/src/mimetypes.rs | 156 +-- rust/fatcat-api/src/models.rs | 137 +- rust/fatcat-api/src/server.rs | 2597 ++++++++++++++++++++++++++------------ 5 files changed, 3106 insertions(+), 1672 deletions(-) (limited to 'rust/fatcat-api/src') diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs index e8546f95..1219e01b 100644 --- a/rust/fatcat-api/src/client.rs +++ b/rust/fatcat-api/src/client.rs @@ -1,66 +1,51 @@ #![allow(unused_extern_crates)] -extern crate hyper_openssl; extern crate chrono; +extern crate hyper_openssl; extern crate url; - - -use hyper; -use hyper::client::IntoUrl; -use hyper::mime; -use hyper::header::{Headers, ContentType}; -use hyper::mime::{Mime, TopLevel, SubLevel, Attr, Value}; -use hyper::Url; use self::hyper_openssl::openssl; use self::url::percent_encoding::{utf8_percent_encode, PATH_SEGMENT_ENCODE_SET, QUERY_ENCODE_SET}; use futures; use futures::{Future, Stream}; use futures::{future, stream}; +use hyper; +use hyper::Url; +use hyper::client::IntoUrl; +use hyper::header::{ContentType, Headers}; +use hyper::mime; +use hyper::mime::{Attr, Mime, SubLevel, TopLevel, Value}; use std::borrow::Cow; -use std::io::{Read, Error}; use std::error; use std::fmt; +use std::io::{Error, Read}; use std::path::Path; -use std::sync::Arc; use std::str; +use std::sync::Arc; use mimetypes; use serde_json; - #[allow(unused_imports)] -use std::collections::{HashMap, BTreeMap}; +use std::collections::{BTreeMap, HashMap}; #[allow(unused_imports)] use swagger; -use swagger::{Context, ApiError, XSpanId}; - -use {Api, - ContainerIdGetResponse, - ContainerLookupGetResponse, - ContainerPostResponse, - CreatorIdGetResponse, - CreatorLookupGetResponse, - CreatorPostResponse, - EditgroupIdAcceptPostResponse, - EditgroupIdGetResponse, - EditgroupPostResponse, - EditorUsernameChangelogGetResponse, - EditorUsernameGetResponse, - FileIdGetResponse, - FileLookupGetResponse, - FilePostResponse, - ReleaseIdGetResponse, - ReleaseLookupGetResponse, - ReleasePostResponse, - WorkIdGetResponse, - WorkPostResponse - }; +use swagger::{ApiError, Context, XSpanId}; + use models; +use {Api, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, + CreatorIdGetResponse, CreatorLookupGetResponse, CreatorPostResponse, + EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse, + EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse, + FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, + ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. -fn into_base_path(input: T, correct_scheme: Option<&'static str>) -> Result { +fn into_base_path( + input: T, + correct_scheme: Option<&'static str>, +) -> Result { // First convert to Url, since a base path is a subset of Url. let url = input.into_url()?; @@ -93,7 +78,8 @@ impl fmt::Debug for Client { impl Client { pub fn try_new_http(base_path: T) -> Result - where T: IntoUrl + where + T: IntoUrl, { Ok(Client { base_path: into_base_path(base_path, Some("http"))?, @@ -101,17 +87,17 @@ impl Client { }) } - pub fn try_new_https(base_path: T, - ca_certificate: CA) - -> Result - where T: IntoUrl, - CA: AsRef + pub fn try_new_https(base_path: T, ca_certificate: CA) -> Result + where + T: IntoUrl, + CA: AsRef, { let ca_certificate = ca_certificate.as_ref().to_owned(); let https_hyper_client = move || { // SSL implementation - let mut ssl = openssl::ssl::SslConnectorBuilder::new(openssl::ssl::SslMethod::tls()).unwrap(); + let mut ssl = + openssl::ssl::SslConnectorBuilder::new(openssl::ssl::SslMethod::tls()).unwrap(); // Server authentication ssl.set_ca_file(ca_certificate.clone()).unwrap(); @@ -122,20 +108,22 @@ impl Client { }; Ok(Client { - base_path: into_base_path(base_path, Some("https"))?, - hyper_client: Arc::new(https_hyper_client), - }) + base_path: into_base_path(base_path, Some("https"))?, + hyper_client: Arc::new(https_hyper_client), + }) } - pub fn try_new_https_mutual(base_path: T, - ca_certificate: CA, - client_key: K, - client_certificate: C) - -> Result - where T: IntoUrl, - CA: AsRef, - K: AsRef, - C: AsRef + pub fn try_new_https_mutual( + base_path: T, + ca_certificate: CA, + client_key: K, + client_certificate: C, + ) -> Result + where + T: IntoUrl, + CA: AsRef, + K: AsRef, + C: AsRef, { let ca_certificate = ca_certificate.as_ref().to_owned(); let client_key = client_key.as_ref().to_owned(); @@ -143,14 +131,17 @@ impl Client { let https_mutual_hyper_client = move || { // SSL implementation - let mut ssl = openssl::ssl::SslConnectorBuilder::new(openssl::ssl::SslMethod::tls()).unwrap(); + let mut ssl = + openssl::ssl::SslConnectorBuilder::new(openssl::ssl::SslMethod::tls()).unwrap(); // Server authentication ssl.set_ca_file(ca_certificate.clone()).unwrap(); // Client authentication - ssl.set_private_key_file(client_key.clone(), openssl::x509::X509_FILETYPE_PEM).unwrap(); - ssl.set_certificate_chain_file(client_certificate.clone()).unwrap(); + ssl.set_private_key_file(client_key.clone(), openssl::x509::X509_FILETYPE_PEM) + .unwrap(); + ssl.set_certificate_chain_file(client_certificate.clone()) + .unwrap(); ssl.check_private_key().unwrap(); let ssl = hyper_openssl::OpensslClient::from(ssl.build()); @@ -159,9 +150,9 @@ impl Client { }; Ok(Client { - base_path: into_base_path(base_path, Some("https"))?, - hyper_client: Arc::new(https_mutual_hyper_client) - }) + base_path: into_base_path(base_path, Some("https"))?, + hyper_client: Arc::new(https_mutual_hyper_client), + }) } /// Constructor for creating a `Client` by passing in a pre-made `hyper` client. @@ -173,169 +164,204 @@ impl Client { /// The reason for this function's existence is to support legacy test code, which did mocking at the hyper layer. /// This is not a recommended way to write new tests. If other reasons are found for using this function, they /// should be mentioned here. - pub fn try_new_with_hyper_client(base_path: T, - hyper_client: Arc hyper::client::Client + Sync + Send>) - -> Result - where T: IntoUrl + pub fn try_new_with_hyper_client( + base_path: T, + hyper_client: Arc hyper::client::Client + Sync + Send>, + ) -> Result + where + T: IntoUrl, { Ok(Client { base_path: into_base_path(base_path, None)?, - hyper_client: hyper_client + hyper_client: hyper_client, }) } } impl Api for Client { - - fn container_id_get(&self, param_id: String, context: &Context) -> Box + Send> { - - + fn container_id_get( + &self, + param_id: String, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/container/{id}", - self.base_path, id=utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerIdGetResponse::FetchASingleContainerById(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerIdGetResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerIdGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn container_lookup_get(&self, param_issn: String, context: &Context) -> Box + Send> { - + fn container_lookup_get( + &self, + param_issn: String, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_issn = format!("issn={issn}&", issn=param_issn.to_string()); - + let query_issn = format!("issn={issn}&", issn = param_issn.to_string()); let url = format!( "{}/v0/container/lookup?{issn}", self.base_path, - issn=utf8_percent_encode(&query_issn, QUERY_ENCODE_SET) + issn = utf8_percent_encode(&query_issn, QUERY_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerLookupGetResponse::FindASingleContainerByExternalIdentifer(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerLookupGetResponse::BadRequest(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerLookupGetResponse::NoSuchContainer(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerLookupGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn container_post(&self, param_body: Option, context: &Context) -> Box + Send> { - - - let url = format!( - "{}/v0/container", - self.base_path - ); - - let body = param_body.map(|ref body| { + fn container_post( + &self, + param_body: Option, + context: &Context, + ) -> Box + Send> { + let url = format!("{}/v0/container", self.base_path); - serde_json::to_string(body).expect("impossible to fail to serialize") - }); + let body = param_body + .map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize")); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); @@ -346,205 +372,255 @@ impl Api for Client { }; custom_headers.set(ContentType(mimetypes::requests::CONTAINER_POST.clone())); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 201 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerPostResponse::Created(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerPostResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ContainerPostResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn creator_id_get(&self, param_id: String, context: &Context) -> Box + Send> { - - + fn creator_id_get( + &self, + param_id: String, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/creator/{id}", - self.base_path, id=utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorIdGetResponse::FetchASingleCreatorById(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorIdGetResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorIdGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn creator_lookup_get(&self, param_orcid: String, context: &Context) -> Box + Send> { - + fn creator_lookup_get( + &self, + param_orcid: String, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_orcid = format!("orcid={orcid}&", orcid=param_orcid.to_string()); - + let query_orcid = format!("orcid={orcid}&", orcid = param_orcid.to_string()); let url = format!( "{}/v0/creator/lookup?{orcid}", self.base_path, - orcid=utf8_percent_encode(&query_orcid, QUERY_ENCODE_SET) + orcid = utf8_percent_encode(&query_orcid, QUERY_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorLookupGetResponse::FindASingleCreatorByExternalIdentifer(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorLookupGetResponse::BadRequest(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorLookupGetResponse::NoSuchCreator(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorLookupGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn creator_post(&self, param_body: Option, context: &Context) -> Box + Send> { + fn creator_post( + &self, + param_body: Option, + context: &Context, + ) -> Box + Send> { + let url = format!("{}/v0/creator", self.base_path); - - let url = format!( - "{}/v0/creator", - self.base_path - ); - - let body = param_body.map(|ref body| { - - serde_json::to_string(body).expect("impossible to fail to serialize") - }); + let body = param_body + .map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize")); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); @@ -555,527 +631,670 @@ impl Api for Client { }; custom_headers.set(ContentType(mimetypes::requests::CREATOR_POST.clone())); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 201 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorPostResponse::Created(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorPostResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(CreatorPostResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn editgroup_id_accept_post(&self, param_id: i32, context: &Context) -> Box + Send> { - - + fn editgroup_id_accept_post( + &self, + param_id: i32, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/editgroup/{id}/accept", - self.base_path, id=utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(EditgroupIdAcceptPostResponse::MergedEditgroupSuccessfully_(body)) - }, + Ok(EditgroupIdAcceptPostResponse::MergedEditgroupSuccessfully_( + body, + )) + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupIdAcceptPostResponse::EditgroupIsInAnUnmergableState(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupIdAcceptPostResponse::NoSuchEditgroup(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupIdAcceptPostResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn editgroup_id_get(&self, param_id: i32, context: &Context) -> Box + Send> { - - + fn editgroup_id_get( + &self, + param_id: i32, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/editgroup/{id}", - self.base_path, id=utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupIdGetResponse::FetchEditgroupByIdentifier(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupIdGetResponse::NoSuchEditgroup(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupIdGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn editgroup_post(&self, context: &Context) -> Box + Send> { - - - let url = format!( - "{}/v0/editgroup", - self.base_path - ); - + fn editgroup_post( + &self, + context: &Context, + ) -> Box + Send> { + let url = format!("{}/v0/editgroup", self.base_path); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 201 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupPostResponse::SuccessfullyCreated(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupPostResponse::InvalidRequestParameters(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditgroupPostResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn editor_username_changelog_get(&self, param_username: String, context: &Context) -> Box + Send> { - - + fn editor_username_changelog_get( + &self, + param_username: String, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/editor/{username}/changelog", - self.base_path, username=utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + username = utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditorUsernameChangelogGetResponse::FindChanges_(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditorUsernameChangelogGetResponse::UsernameNotFound(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(EditorUsernameChangelogGetResponse::GenericErrorResponse(body)) - }, + Ok(EditorUsernameChangelogGetResponse::GenericErrorResponse( + body, + )) + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn editor_username_get(&self, param_username: String, context: &Context) -> Box + Send> { - - + fn editor_username_get( + &self, + param_username: String, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/editor/{username}", - self.base_path, username=utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + username = utf8_percent_encode(¶m_username.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditorUsernameGetResponse::FetchGenericInformationAboutAnEditor(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditorUsernameGetResponse::UsernameNotFound(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(EditorUsernameGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn file_id_get(&self, param_id: String, context: &Context) -> Box + Send> { - - + fn file_id_get( + &self, + param_id: String, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/file/{id}", - self.base_path, id=utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FileIdGetResponse::FetchASingleFileById(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FileIdGetResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FileIdGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn file_lookup_get(&self, param_sha1: String, context: &Context) -> Box + Send> { - + fn file_lookup_get( + &self, + param_sha1: String, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_sha1 = format!("sha1={sha1}&", sha1=param_sha1.to_string()); - + let query_sha1 = format!("sha1={sha1}&", sha1 = param_sha1.to_string()); let url = format!( "{}/v0/file/lookup?{sha1}", self.base_path, - sha1=utf8_percent_encode(&query_sha1, QUERY_ENCODE_SET) + sha1 = utf8_percent_encode(&query_sha1, QUERY_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(FileLookupGetResponse::FindASingleFileByExternalIdentifer(body)) - }, + Ok(FileLookupGetResponse::FindASingleFileByExternalIdentifer( + body, + )) + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FileLookupGetResponse::BadRequest(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FileLookupGetResponse::NoSuchFile(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FileLookupGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn file_post(&self, param_body: Option, context: &Context) -> Box + Send> { + fn file_post( + &self, + param_body: Option, + context: &Context, + ) -> Box + Send> { + let url = format!("{}/v0/file", self.base_path); - - let url = format!( - "{}/v0/file", - self.base_path - ); - - let body = param_body.map(|ref body| { - - serde_json::to_string(body).expect("impossible to fail to serialize") - }); + let body = param_body + .map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize")); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); @@ -1086,205 +1305,255 @@ impl Api for Client { }; custom_headers.set(ContentType(mimetypes::requests::FILE_POST.clone())); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 201 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FilePostResponse::Created(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FilePostResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(FilePostResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn release_id_get(&self, param_id: String, context: &Context) -> Box + Send> { - - + fn release_id_get( + &self, + param_id: String, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/release/{id}", - self.base_path, id=utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleaseIdGetResponse::FetchASingleReleaseById(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleaseIdGetResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleaseIdGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn release_lookup_get(&self, param_doi: String, context: &Context) -> Box + Send> { - + fn release_lookup_get( + &self, + param_doi: String, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_doi = format!("doi={doi}&", doi=param_doi.to_string()); - + let query_doi = format!("doi={doi}&", doi = param_doi.to_string()); let url = format!( "{}/v0/release/lookup?{doi}", self.base_path, - doi=utf8_percent_encode(&query_doi, QUERY_ENCODE_SET) + doi = utf8_percent_encode(&query_doi, QUERY_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleaseLookupGetResponse::FindASingleReleaseByExternalIdentifer(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleaseLookupGetResponse::BadRequest(body)) - }, + } 404 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleaseLookupGetResponse::NoSuchRelease(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleaseLookupGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn release_post(&self, param_body: Option, context: &Context) -> Box + Send> { - - - let url = format!( - "{}/v0/release", - self.base_path - ); - - let body = param_body.map(|ref body| { + fn release_post( + &self, + param_body: Option, + context: &Context, + ) -> Box + Send> { + let url = format!("{}/v0/release", self.base_path); - serde_json::to_string(body).expect("impossible to fail to serialize") - }); + let body = param_body + .map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize")); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); @@ -1295,131 +1564,162 @@ impl Api for Client { }; custom_headers.set(ContentType(mimetypes::requests::RELEASE_POST.clone())); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 201 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleasePostResponse::Created(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleasePostResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(ReleasePostResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn work_id_get(&self, param_id: String, context: &Context) -> Box + Send> { - - + fn work_id_get( + &self, + param_id: String, + context: &Context, + ) -> Box + Send> { let url = format!( "{}/v0/work/{id}", - self.base_path, id=utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(WorkIdGetResponse::FetchASingleWorkById(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(WorkIdGetResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(WorkIdGetResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - fn work_post(&self, param_body: Option, context: &Context) -> Box + Send> { - - - let url = format!( - "{}/v0/work", - self.base_path - ); - - let body = param_body.map(|ref body| { + fn work_post( + &self, + param_body: Option, + context: &Context, + ) -> Box + Send> { + let url = format!("{}/v0/work", self.base_path); - serde_json::to_string(body).expect("impossible to fail to serialize") - }); + let body = param_body + .map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize")); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); @@ -1430,56 +1730,71 @@ impl Api for Client { }; custom_headers.set(ContentType(mimetypes::requests::WORK_POST.clone())); - context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - + context + .x_span_id + .as_ref() + .map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response( + mut response: hyper::client::response::Response, + ) -> Result { match response.status.to_u16() { 201 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(WorkPostResponse::Created(body)) - }, + } 400 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(WorkPostResponse::BadRequest(body)) - }, + } 0 => { let mut buf = String::new(); - response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + response + .read_to_string(&mut buf) + .map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; Ok(WorkPostResponse::GenericErrorResponse(body)) - }, + } code => { let mut buf = [0; 100]; let debug_body = match response.read(&mut buf) { Ok(len) => match str::from_utf8(&buf[..len]) { Ok(body) => Cow::from(body), - Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + Err(_) => Cow::from(format!( + "", + &buf[..len].to_vec() + )), }, Err(e) => Cow::from(format!("", e)), }; - Err(ApiError(format!("Unexpected response code {}:\n{:?}\n\n{}", - code, - response.headers, - debug_body))) + Err(ApiError(format!( + "Unexpected response code {}:\n{:?}\n\n{}", + code, response.headers, debug_body + ))) } } } - let result = request.send().map_err(|e| ApiError(format!("No response received: {}", e))).and_then(parse_response); + let result = request + .send() + .map_err(|e| ApiError(format!("No response received: {}", e))) + .and_then(parse_response); Box::new(futures::done(result)) } - } #[derive(Debug)] @@ -1487,7 +1802,7 @@ pub enum ClientInitError { InvalidScheme, InvalidUrl(hyper::error::ParseError), MissingHost, - SslError(openssl::error::ErrorStack) + SslError(openssl::error::ErrorStack), } impl From for ClientInitError { diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs index e695daa7..2b7c84a0 100644 --- a/rust/fatcat-api/src/lib.rs +++ b/rust/fatcat-api/src/lib.rs @@ -1,11 +1,12 @@ -#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, unused_extern_crates, non_camel_case_types)] +#![allow(missing_docs, trivial_casts, unused_variables, unused_mut, unused_imports, + unused_extern_crates, non_camel_case_types)] extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; -extern crate futures; extern crate chrono; +extern crate futures; #[macro_use] extern crate lazy_static; @@ -32,441 +33,563 @@ mod mimetypes; pub use swagger::{ApiError, Context, ContextWrapper}; - #[derive(Debug, PartialEq)] pub enum ContainerIdGetResponse { /// fetch a single container by id - FetchASingleContainerById ( models::ContainerEntity ) , + FetchASingleContainerById(models::ContainerEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum ContainerLookupGetResponse { /// find a single container by external identifer - FindASingleContainerByExternalIdentifer ( models::ContainerEntity ) , + FindASingleContainerByExternalIdentifer(models::ContainerEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// no such container - NoSuchContainer ( models::Error ) , + NoSuchContainer(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum ContainerPostResponse { /// created - Created ( models::EntityEdit ) , + Created(models::EntityEdit), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum CreatorIdGetResponse { /// fetch a single creator by id - FetchASingleCreatorById ( models::CreatorEntity ) , + FetchASingleCreatorById(models::CreatorEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum CreatorLookupGetResponse { /// find a single creator by external identifer - FindASingleCreatorByExternalIdentifer ( models::CreatorEntity ) , + FindASingleCreatorByExternalIdentifer(models::CreatorEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// no such creator - NoSuchCreator ( models::Error ) , + NoSuchCreator(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum CreatorPostResponse { /// created - Created ( models::EntityEdit ) , + Created(models::EntityEdit), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum EditgroupIdAcceptPostResponse { /// merged editgroup successfully (\"live\") - MergedEditgroupSuccessfully_ ( models::Success ) , + MergedEditgroupSuccessfully_(models::Success), /// editgroup is in an unmergable state - EditgroupIsInAnUnmergableState ( models::Error ) , + EditgroupIsInAnUnmergableState(models::Error), /// no such editgroup - NoSuchEditgroup ( models::Error ) , + NoSuchEditgroup(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum EditgroupIdGetResponse { /// fetch editgroup by identifier - FetchEditgroupByIdentifier ( models::Editgroup ) , + FetchEditgroupByIdentifier(models::Editgroup), /// no such editgroup - NoSuchEditgroup ( models::Error ) , + NoSuchEditgroup(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum EditgroupPostResponse { /// successfully created - SuccessfullyCreated ( models::Editgroup ) , + SuccessfullyCreated(models::Editgroup), /// invalid request parameters - InvalidRequestParameters ( models::Error ) , + InvalidRequestParameters(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum EditorUsernameChangelogGetResponse { /// find changes (editgroups) by this editor which have been merged - FindChanges_ ( models::Changelogentry ) , + FindChanges_(models::Changelogentry), /// username not found - UsernameNotFound ( models::Error ) , + UsernameNotFound(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum EditorUsernameGetResponse { /// fetch generic information about an editor - FetchGenericInformationAboutAnEditor ( models::Editor ) , + FetchGenericInformationAboutAnEditor(models::Editor), /// username not found - UsernameNotFound ( models::Error ) , + UsernameNotFound(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum FileIdGetResponse { /// fetch a single file by id - FetchASingleFileById ( models::FileEntity ) , + FetchASingleFileById(models::FileEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum FileLookupGetResponse { /// find a single file by external identifer - FindASingleFileByExternalIdentifer ( models::FileEntity ) , + FindASingleFileByExternalIdentifer(models::FileEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// no such file - NoSuchFile ( models::Error ) , + NoSuchFile(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum FilePostResponse { /// created - Created ( models::EntityEdit ) , + Created(models::EntityEdit), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum ReleaseIdGetResponse { /// fetch a single release by id - FetchASingleReleaseById ( models::ReleaseEntity ) , + FetchASingleReleaseById(models::ReleaseEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum ReleaseLookupGetResponse { /// find a single release by external identifer - FindASingleReleaseByExternalIdentifer ( models::ReleaseEntity ) , + FindASingleReleaseByExternalIdentifer(models::ReleaseEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// no such release - NoSuchRelease ( models::Error ) , + NoSuchRelease(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum ReleasePostResponse { /// created - Created ( models::EntityEdit ) , + Created(models::EntityEdit), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum WorkIdGetResponse { /// fetch a single work by id - FetchASingleWorkById ( models::WorkEntity ) , + FetchASingleWorkById(models::WorkEntity), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } #[derive(Debug, PartialEq)] pub enum WorkPostResponse { /// created - Created ( models::EntityEdit ) , + Created(models::EntityEdit), /// bad request - BadRequest ( models::Error ) , + BadRequest(models::Error), /// generic error response - GenericErrorResponse ( models::Error ) , + GenericErrorResponse(models::Error), } - /// API pub trait Api { - - - fn container_id_get(&self, id: String, context: &Context) -> Box + Send>; - - - fn container_lookup_get(&self, issn: String, context: &Context) -> Box + Send>; - - - fn container_post(&self, body: Option, context: &Context) -> Box + Send>; - - - fn creator_id_get(&self, id: String, context: &Context) -> Box + Send>; - - - fn creator_lookup_get(&self, orcid: String, context: &Context) -> Box + Send>; - - - fn creator_post(&self, body: Option, context: &Context) -> Box + Send>; - - - fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box + Send>; - - - fn editgroup_id_get(&self, id: i32, context: &Context) -> Box + Send>; - - - fn editgroup_post(&self, context: &Context) -> Box + Send>; - - - fn editor_username_changelog_get(&self, username: String, context: &Context) -> Box + Send>; - - - fn editor_username_get(&self, username: String, context: &Context) -> Box + Send>; - - - fn file_id_get(&self, id: String, context: &Context) -> Box + Send>; - - - fn file_lookup_get(&self, sha1: String, context: &Context) -> Box + Send>; - - - fn file_post(&self, body: Option, context: &Context) -> Box + Send>; - - - fn release_id_get(&self, id: String, context: &Context) -> Box + Send>; - - - fn release_lookup_get(&self, doi: String, context: &Context) -> Box + Send>; - - - fn release_post(&self, body: Option, context: &Context) -> Box + Send>; - - - fn work_id_get(&self, id: String, context: &Context) -> Box + Send>; - - - fn work_post(&self, body: Option, context: &Context) -> Box + Send>; - + fn container_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send>; + + fn container_lookup_get( + &self, + issn: String, + context: &Context, + ) -> Box + Send>; + + fn container_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send>; + + fn creator_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send>; + + fn creator_lookup_get( + &self, + orcid: String, + context: &Context, + ) -> Box + Send>; + + fn creator_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send>; + + fn editgroup_id_accept_post( + &self, + id: i32, + context: &Context, + ) -> Box + Send>; + + fn editgroup_id_get( + &self, + id: i32, + context: &Context, + ) -> Box + Send>; + + fn editgroup_post( + &self, + context: &Context, + ) -> Box + Send>; + + fn editor_username_changelog_get( + &self, + username: String, + context: &Context, + ) -> Box + Send>; + + fn editor_username_get( + &self, + username: String, + context: &Context, + ) -> Box + Send>; + + fn file_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send>; + + fn file_lookup_get( + &self, + sha1: String, + context: &Context, + ) -> Box + Send>; + + fn file_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send>; + + fn release_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send>; + + fn release_lookup_get( + &self, + doi: String, + context: &Context, + ) -> Box + Send>; + + fn release_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send>; + + fn work_id_get( + &self, + id: String, + context: &Context, + ) -> Box + Send>; + + fn work_post( + &self, + body: Option, + context: &Context, + ) -> Box + Send>; } /// API without a `Context` pub trait ApiNoContext { - - - fn container_id_get(&self, id: String) -> Box + Send>; - - - fn container_lookup_get(&self, issn: String) -> Box + Send>; - - - fn container_post(&self, body: Option) -> Box + Send>; - - - fn creator_id_get(&self, id: String) -> Box + Send>; - - - fn creator_lookup_get(&self, orcid: String) -> Box + Send>; - - - fn creator_post(&self, body: Option) -> Box + Send>; - - - fn editgroup_id_accept_post(&self, id: i32) -> Box + Send>; - - - fn editgroup_id_get(&self, id: i32) -> Box + Send>; - - - fn editgroup_post(&self) -> Box + Send>; - - - fn editor_username_changelog_get(&self, username: String) -> Box + Send>; - - - fn editor_username_get(&self, username: String) -> Box + Send>; - - - fn file_id_get(&self, id: String) -> Box + Send>; - - - fn file_lookup_get(&self, sha1: String) -> Box + Send>; - - - fn file_post(&self, body: Option) -> Box + Send>; - - - fn release_id_get(&self, id: String) -> Box + Send>; - - - fn release_lookup_get(&self, doi: String) -> Box + Send>; - - - fn release_post(&self, body: Option) -> Box + Send>; - - - fn work_id_get(&self, id: String) -> Box + Send>; - - - fn work_post(&self, body: Option) -> Box + Send>; - + fn container_id_get( + &self, + id: String, + ) -> Box + Send>; + + fn container_lookup_get( + &self, + issn: String, + ) -> Box + Send>; + + fn container_post( + &self, + body: Option, + ) -> Box + Send>; + + fn creator_id_get( + &self, + id: String, + ) -> Box + Send>; + + fn creator_lookup_get( + &self, + orcid: String, + ) -> Box + Send>; + + fn creator_post( + &self, + body: Option, + ) -> Box + Send>; + + fn editgroup_id_accept_post( + &self, + id: i32, + ) -> Box + Send>; + + fn editgroup_id_get( + &self, + id: i32, + ) -> Box + Send>; + + fn editgroup_post(&self) -> Box + Send>; + + fn editor_username_changelog_get( + &self, + username: String, + ) -> Box + Send>; + + fn editor_username_get( + &self, + username: String, + ) -> Box + Send>; + + fn file_id_get( + &self, + id: String, + ) -> Box + Send>; + + fn file_lookup_get( + &self, + sha1: String, + ) -> Box + Send>; + + fn file_post( + &self, + body: Option, + ) -> Box + Send>; + + fn release_id_get( + &self, + id: String, + ) -> Box + Send>; + + fn release_lookup_get( + &self, + doi: String, + ) -> Box + Send>; + + fn release_post( + &self, + body: Option, + ) -> Box + Send>; + + fn work_id_get( + &self, + id: String, + ) -> Box + Send>; + + fn work_post( + &self, + body: Option, + ) -> Box + Send>; } /// Trait to extend an API to make it easy to bind it to a context. -pub trait ContextWrapperExt<'a> where Self: Sized { +pub trait ContextWrapperExt<'a> +where + Self: Sized, +{ /// Binds this API to a context. fn with_context(self: &'a Self, context: Context) -> ContextWrapper<'a, Self>; } impl<'a, T: Api + Sized> ContextWrapperExt<'a> for T { fn with_context(self: &'a T, context: Context) -> ContextWrapper<'a, T> { - ContextWrapper::::new(self, context) + ContextWrapper::::new(self, context) } } impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { - - - fn container_id_get(&self, id: String) -> Box + Send> { + fn container_id_get( + &self, + id: String, + ) -> Box + Send> { self.api().container_id_get(id, &self.context()) } - - fn container_lookup_get(&self, issn: String) -> Box + Send> { + fn container_lookup_get( + &self, + issn: String, + ) -> Box + Send> { self.api().container_lookup_get(issn, &self.context()) } - - fn container_post(&self, body: Option) -> Box + Send> { + fn container_post( + &self, + body: Option, + ) -> Box + Send> { self.api().container_post(body, &self.context()) } - - fn creator_id_get(&self, id: String) -> Box + Send> { + fn creator_id_get( + &self, + id: String, + ) -> Box + Send> { self.api().creator_id_get(id, &self.context()) } - - fn creator_lookup_get(&self, orcid: String) -> Box + Send> { + fn creator_lookup_get( + &self, + orcid: String, + ) -> Box + Send> { self.api().creator_lookup_get(orcid, &self.context()) } - - fn creator_post(&self, body: Option) -> Box + Send> { + fn creator_post( + &self, + body: Option, + ) -> Box + Send> { self.api().creator_post(body, &self.context()) } - - fn editgroup_id_accept_post(&self, id: i32) -> Box + Send> { + fn editgroup_id_accept_post( + &self, + id: i32, + ) -> Box + Send> { self.api().editgroup_id_accept_post(id, &self.context()) } - - fn editgroup_id_get(&self, id: i32) -> Box + Send> { + fn editgroup_id_get( + &self, + id: i32, + ) -> Box + Send> { self.api().editgroup_id_get(id, &self.context()) } - - fn editgroup_post(&self) -> Box + Send> { + fn editgroup_post(&self) -> Box + Send> { self.api().editgroup_post(&self.context()) } - - fn editor_username_changelog_get(&self, username: String) -> Box + Send> { - self.api().editor_username_changelog_get(username, &self.context()) + fn editor_username_changelog_get( + &self, + username: String, + ) -> Box + Send> { + self.api() + .editor_username_changelog_get(username, &self.context()) } - - fn editor_username_get(&self, username: String) -> Box + Send> { + fn editor_username_get( + &self, + username: String, + ) -> Box + Send> { self.api().editor_username_get(username, &self.context()) } - - fn file_id_get(&self, id: String) -> Box + Send> { + fn file_id_get( + &self, + id: String, + ) -> Box + Send> { self.api().file_id_get(id, &self.context()) } - - fn file_lookup_get(&self, sha1: String) -> Box + Send> { + fn file_lookup_get( + &self, + sha1: String, + ) -> Box + Send> { self.api().file_lookup_get(sha1, &self.context()) } - - fn file_post(&self, body: Option) -> Box + Send> { + fn file_post( + &self, + body: Option, + ) -> Box + Send> { self.api().file_post(body, &self.context()) } - - fn release_id_get(&self, id: String) -> Box + Send> { + fn release_id_get( + &self, + id: String, + ) -> Box + Send> { self.api().release_id_get(id, &self.context()) } - - fn release_lookup_get(&self, doi: String) -> Box + Send> { + fn release_lookup_get( + &self, + doi: String, + ) -> Box + Send> { self.api().release_lookup_get(doi, &self.context()) } - - fn release_post(&self, body: Option) -> Box + Send> { + fn release_post( + &self, + body: Option, + ) -> Box + Send> { self.api().release_post(body, &self.context()) } - - fn work_id_get(&self, id: String) -> Box + Send> { + fn work_id_get( + &self, + id: String, + ) -> Box + Send> { self.api().work_id_get(id, &self.context()) } - - fn work_post(&self, body: Option) -> Box + Send> { + fn work_post( + &self, + body: Option, + ) -> Box + Send> { self.api().work_post(body, &self.context()) } - } #[cfg(feature = "client")] diff --git a/rust/fatcat-api/src/mimetypes.rs b/rust/fatcat-api/src/mimetypes.rs index c0b83a05..6076d488 100644 --- a/rust/fatcat-api/src/mimetypes.rs +++ b/rust/fatcat-api/src/mimetypes.rs @@ -6,276 +6,288 @@ pub mod responses { // The macro is called per-operation to beat the recursion limit /// Create Mime objects for the response content types for ContainerIdGet lazy_static! { - pub static ref CONTAINER_ID_GET_FETCH_A_SINGLE_CONTAINER_BY_ID: Mime = mime!(Application/Json); + pub static ref CONTAINER_ID_GET_FETCH_A_SINGLE_CONTAINER_BY_ID: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerIdGet lazy_static! { - pub static ref CONTAINER_ID_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref CONTAINER_ID_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerIdGet lazy_static! { - pub static ref CONTAINER_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref CONTAINER_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerLookupGet lazy_static! { - pub static ref CONTAINER_LOOKUP_GET_FIND_A_SINGLE_CONTAINER_BY_EXTERNAL_IDENTIFER: Mime = mime!(Application/Json); + pub static ref CONTAINER_LOOKUP_GET_FIND_A_SINGLE_CONTAINER_BY_EXTERNAL_IDENTIFER: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerLookupGet lazy_static! { - pub static ref CONTAINER_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref CONTAINER_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerLookupGet lazy_static! { - pub static ref CONTAINER_LOOKUP_GET_NO_SUCH_CONTAINER: Mime = mime!(Application/Json); + pub static ref CONTAINER_LOOKUP_GET_NO_SUCH_CONTAINER: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerLookupGet lazy_static! { - pub static ref CONTAINER_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref CONTAINER_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerPost lazy_static! { - pub static ref CONTAINER_POST_CREATED: Mime = mime!(Application/Json); + pub static ref CONTAINER_POST_CREATED: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerPost lazy_static! { - pub static ref CONTAINER_POST_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref CONTAINER_POST_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ContainerPost lazy_static! { - pub static ref CONTAINER_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref CONTAINER_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorIdGet lazy_static! { - pub static ref CREATOR_ID_GET_FETCH_A_SINGLE_CREATOR_BY_ID: Mime = mime!(Application/Json); + pub static ref CREATOR_ID_GET_FETCH_A_SINGLE_CREATOR_BY_ID: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorIdGet lazy_static! { - pub static ref CREATOR_ID_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref CREATOR_ID_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorIdGet lazy_static! { - pub static ref CREATOR_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref CREATOR_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorLookupGet lazy_static! { - pub static ref CREATOR_LOOKUP_GET_FIND_A_SINGLE_CREATOR_BY_EXTERNAL_IDENTIFER: Mime = mime!(Application/Json); + pub static ref CREATOR_LOOKUP_GET_FIND_A_SINGLE_CREATOR_BY_EXTERNAL_IDENTIFER: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorLookupGet lazy_static! { - pub static ref CREATOR_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref CREATOR_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorLookupGet lazy_static! { - pub static ref CREATOR_LOOKUP_GET_NO_SUCH_CREATOR: Mime = mime!(Application/Json); + pub static ref CREATOR_LOOKUP_GET_NO_SUCH_CREATOR: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorLookupGet lazy_static! { - pub static ref CREATOR_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref CREATOR_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorPost lazy_static! { - pub static ref CREATOR_POST_CREATED: Mime = mime!(Application/Json); + pub static ref CREATOR_POST_CREATED: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorPost lazy_static! { - pub static ref CREATOR_POST_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref CREATOR_POST_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for CreatorPost lazy_static! { - pub static ref CREATOR_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref CREATOR_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdAcceptPost lazy_static! { - pub static ref EDITGROUP_ID_ACCEPT_POST_MERGED_EDITGROUP_SUCCESSFULLY_: Mime = mime!(Application/Json); + pub static ref EDITGROUP_ID_ACCEPT_POST_MERGED_EDITGROUP_SUCCESSFULLY_: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdAcceptPost lazy_static! { - pub static ref EDITGROUP_ID_ACCEPT_POST_EDITGROUP_IS_IN_AN_UNMERGABLE_STATE: Mime = mime!(Application/Json); + pub static ref EDITGROUP_ID_ACCEPT_POST_EDITGROUP_IS_IN_AN_UNMERGABLE_STATE: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdAcceptPost lazy_static! { - pub static ref EDITGROUP_ID_ACCEPT_POST_NO_SUCH_EDITGROUP: Mime = mime!(Application/Json); + pub static ref EDITGROUP_ID_ACCEPT_POST_NO_SUCH_EDITGROUP: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdAcceptPost lazy_static! { - pub static ref EDITGROUP_ID_ACCEPT_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref EDITGROUP_ID_ACCEPT_POST_GENERIC_ERROR_RESPONSE: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdGet lazy_static! { - pub static ref EDITGROUP_ID_GET_FETCH_EDITGROUP_BY_IDENTIFIER: Mime = mime!(Application/Json); + pub static ref EDITGROUP_ID_GET_FETCH_EDITGROUP_BY_IDENTIFIER: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdGet lazy_static! { - pub static ref EDITGROUP_ID_GET_NO_SUCH_EDITGROUP: Mime = mime!(Application/Json); + pub static ref EDITGROUP_ID_GET_NO_SUCH_EDITGROUP: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupIdGet lazy_static! { - pub static ref EDITGROUP_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref EDITGROUP_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupPost lazy_static! { - pub static ref EDITGROUP_POST_SUCCESSFULLY_CREATED: Mime = mime!(Application/Json); + pub static ref EDITGROUP_POST_SUCCESSFULLY_CREATED: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupPost lazy_static! { - pub static ref EDITGROUP_POST_INVALID_REQUEST_PARAMETERS: Mime = mime!(Application/Json); + pub static ref EDITGROUP_POST_INVALID_REQUEST_PARAMETERS: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditgroupPost lazy_static! { - pub static ref EDITGROUP_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref EDITGROUP_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditorUsernameChangelogGet lazy_static! { - pub static ref EDITOR_USERNAME_CHANGELOG_GET_FIND_CHANGES_: Mime = mime!(Application/Json); + pub static ref EDITOR_USERNAME_CHANGELOG_GET_FIND_CHANGES_: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditorUsernameChangelogGet lazy_static! { - pub static ref EDITOR_USERNAME_CHANGELOG_GET_USERNAME_NOT_FOUND: Mime = mime!(Application/Json); + pub static ref EDITOR_USERNAME_CHANGELOG_GET_USERNAME_NOT_FOUND: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for EditorUsernameChangelogGet lazy_static! { - pub static ref EDITOR_USERNAME_CHANGELOG_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref EDITOR_USERNAME_CHANGELOG_GET_GENERIC_ERROR_RESPONSE: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for EditorUsernameGet lazy_static! { - pub static ref EDITOR_USERNAME_GET_FETCH_GENERIC_INFORMATION_ABOUT_AN_EDITOR: Mime = mime!(Application/Json); + pub static ref EDITOR_USERNAME_GET_FETCH_GENERIC_INFORMATION_ABOUT_AN_EDITOR: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for EditorUsernameGet lazy_static! { - pub static ref EDITOR_USERNAME_GET_USERNAME_NOT_FOUND: Mime = mime!(Application/Json); + pub static ref EDITOR_USERNAME_GET_USERNAME_NOT_FOUND: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for EditorUsernameGet lazy_static! { - pub static ref EDITOR_USERNAME_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref EDITOR_USERNAME_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FileIdGet lazy_static! { - pub static ref FILE_ID_GET_FETCH_A_SINGLE_FILE_BY_ID: Mime = mime!(Application/Json); + pub static ref FILE_ID_GET_FETCH_A_SINGLE_FILE_BY_ID: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FileIdGet lazy_static! { - pub static ref FILE_ID_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref FILE_ID_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FileIdGet lazy_static! { - pub static ref FILE_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref FILE_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FileLookupGet lazy_static! { - pub static ref FILE_LOOKUP_GET_FIND_A_SINGLE_FILE_BY_EXTERNAL_IDENTIFER: Mime = mime!(Application/Json); + pub static ref FILE_LOOKUP_GET_FIND_A_SINGLE_FILE_BY_EXTERNAL_IDENTIFER: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for FileLookupGet lazy_static! { - pub static ref FILE_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref FILE_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FileLookupGet lazy_static! { - pub static ref FILE_LOOKUP_GET_NO_SUCH_FILE: Mime = mime!(Application/Json); + pub static ref FILE_LOOKUP_GET_NO_SUCH_FILE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FileLookupGet lazy_static! { - pub static ref FILE_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref FILE_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FilePost lazy_static! { - pub static ref FILE_POST_CREATED: Mime = mime!(Application/Json); + pub static ref FILE_POST_CREATED: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FilePost lazy_static! { - pub static ref FILE_POST_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref FILE_POST_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for FilePost lazy_static! { - pub static ref FILE_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref FILE_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleaseIdGet lazy_static! { - pub static ref RELEASE_ID_GET_FETCH_A_SINGLE_RELEASE_BY_ID: Mime = mime!(Application/Json); + pub static ref RELEASE_ID_GET_FETCH_A_SINGLE_RELEASE_BY_ID: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleaseIdGet lazy_static! { - pub static ref RELEASE_ID_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref RELEASE_ID_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleaseIdGet lazy_static! { - pub static ref RELEASE_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref RELEASE_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleaseLookupGet lazy_static! { - pub static ref RELEASE_LOOKUP_GET_FIND_A_SINGLE_RELEASE_BY_EXTERNAL_IDENTIFER: Mime = mime!(Application/Json); + pub static ref RELEASE_LOOKUP_GET_FIND_A_SINGLE_RELEASE_BY_EXTERNAL_IDENTIFER: Mime = + mime!(Application / Json); } /// Create Mime objects for the response content types for ReleaseLookupGet lazy_static! { - pub static ref RELEASE_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref RELEASE_LOOKUP_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleaseLookupGet lazy_static! { - pub static ref RELEASE_LOOKUP_GET_NO_SUCH_RELEASE: Mime = mime!(Application/Json); + pub static ref RELEASE_LOOKUP_GET_NO_SUCH_RELEASE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleaseLookupGet lazy_static! { - pub static ref RELEASE_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref RELEASE_LOOKUP_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleasePost lazy_static! { - pub static ref RELEASE_POST_CREATED: Mime = mime!(Application/Json); + pub static ref RELEASE_POST_CREATED: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleasePost lazy_static! { - pub static ref RELEASE_POST_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref RELEASE_POST_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for ReleasePost lazy_static! { - pub static ref RELEASE_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref RELEASE_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for WorkIdGet lazy_static! { - pub static ref WORK_ID_GET_FETCH_A_SINGLE_WORK_BY_ID: Mime = mime!(Application/Json); + pub static ref WORK_ID_GET_FETCH_A_SINGLE_WORK_BY_ID: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for WorkIdGet lazy_static! { - pub static ref WORK_ID_GET_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref WORK_ID_GET_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for WorkIdGet lazy_static! { - pub static ref WORK_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref WORK_ID_GET_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for WorkPost lazy_static! { - pub static ref WORK_POST_CREATED: Mime = mime!(Application/Json); + pub static ref WORK_POST_CREATED: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for WorkPost lazy_static! { - pub static ref WORK_POST_BAD_REQUEST: Mime = mime!(Application/Json); + pub static ref WORK_POST_BAD_REQUEST: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for WorkPost lazy_static! { - pub static ref WORK_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application/Json); + pub static ref WORK_POST_GENERIC_ERROR_RESPONSE: Mime = mime!(Application / Json); } } pub mod requests { use hyper::mime::*; - /// Create Mime objects for the request content types for ContainerPost + /// Create Mime objects for the request content types for ContainerPost lazy_static! { - pub static ref CONTAINER_POST: Mime = mime!(Application/Json); + pub static ref CONTAINER_POST: Mime = mime!(Application / Json); } - /// Create Mime objects for the request content types for CreatorPost + /// Create Mime objects for the request content types for CreatorPost lazy_static! { - pub static ref CREATOR_POST: Mime = mime!(Application/Json); + pub static ref CREATOR_POST: Mime = mime!(Application / Json); } - /// Create Mime objects for the request content types for FilePost + /// Create Mime objects for the request content types for FilePost lazy_static! { - pub static ref FILE_POST: Mime = mime!(Application/Json); + pub static ref FILE_POST: Mime = mime!(Application / Json); } - /// Create Mime objects for the request content types for ReleasePost + /// Create Mime objects for the request content types for ReleasePost lazy_static! { - pub static ref RELEASE_POST: Mime = mime!(Application/Json); + pub static ref RELEASE_POST: Mime = mime!(Application / Json); } - /// Create Mime objects for the request content types for WorkPost + /// Create Mime objects for the request content types for WorkPost lazy_static! { - pub static ref WORK_POST: Mime = mime!(Application/Json); + pub static ref WORK_POST: Mime = mime!(Application / Json); } } diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index 1d7ed56a..3d104b78 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -2,31 +2,28 @@ extern crate chrono; extern crate uuid; - use serde::ser::Serializer; -use std::collections::HashMap; use models; +use std::collections::HashMap; use swagger; - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Changelogentry { #[serde(rename = "index")] pub index: isize, #[serde(rename = "editgroup_id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub editgroup_id: Option, #[serde(rename = "timestamp")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub timestamp: Option>, - } impl Changelogentry { - pub fn new(index: isize, ) -> Changelogentry { + pub fn new(index: isize) -> Changelogentry { Changelogentry { index: index, editgroup_id: None, @@ -38,42 +35,41 @@ impl Changelogentry { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ContainerEntity { #[serde(rename = "issn")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub issn: Option, #[serde(rename = "publisher")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub publisher: Option, #[serde(rename = "parent")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub parent: Option, #[serde(rename = "name")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, #[serde(rename = "ident")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub ident: Option, #[serde(rename = "revision")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, #[serde(rename = "redirect")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, #[serde(rename = "editgroup")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub editgroup: Option, - } impl ContainerEntity { @@ -95,34 +91,33 @@ impl ContainerEntity { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct CreatorEntity { #[serde(rename = "orcid")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub orcid: Option, #[serde(rename = "name")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, #[serde(rename = "editgroup")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub editgroup: Option, #[serde(rename = "redirect")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, #[serde(rename = "revision")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, #[serde(rename = "ident")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub ident: Option, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, - } impl CreatorEntity { @@ -146,11 +141,10 @@ pub struct Editgroup { #[serde(rename = "editor_id")] pub editor_id: isize, - } impl Editgroup { - pub fn new(id: isize, editor_id: isize, ) -> Editgroup { + pub fn new(id: isize, editor_id: isize) -> Editgroup { Editgroup { id: id, editor_id: editor_id, @@ -162,35 +156,31 @@ impl Editgroup { pub struct Editor { #[serde(rename = "username")] pub username: String, - } impl Editor { - pub fn new(username: String, ) -> Editor { - Editor { - username: username, - } + pub fn new(username: String) -> Editor { + Editor { username: username } } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct EntityEdit { #[serde(rename = "editgroup_id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub editgroup_id: Option, #[serde(rename = "revision")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, #[serde(rename = "ident")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub ident: Option, #[serde(rename = "id")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub id: Option, - } impl EntityEdit { @@ -208,52 +198,48 @@ impl EntityEdit { pub struct Error { #[serde(rename = "message")] pub message: String, - } impl Error { - pub fn new(message: String, ) -> Error { - Error { - message: message, - } + pub fn new(message: String) -> Error { + Error { message: message } } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FileEntity { #[serde(rename = "url")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub url: Option, #[serde(rename = "sha1")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub sha1: Option, #[serde(rename = "size")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, #[serde(rename = "editgroup")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub editgroup: Option, #[serde(rename = "redirect")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, #[serde(rename = "revision")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, #[serde(rename = "ident")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub ident: Option, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, - } impl FileEntity { @@ -274,58 +260,57 @@ impl FileEntity { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ReleaseEntity { #[serde(rename = "issue")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub issue: Option, #[serde(rename = "pages")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub pages: Option, #[serde(rename = "volume")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub volume: Option, #[serde(rename = "doi")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub doi: Option, #[serde(rename = "release_type")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub release_type: Option, #[serde(rename = "license")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub license: Option, #[serde(rename = "container")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub container: Option, #[serde(rename = "work")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub work: Option, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, #[serde(rename = "ident")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub ident: Option, #[serde(rename = "revision")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, #[serde(rename = "redirect")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, #[serde(rename = "editgroup")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub editgroup: Option, - } impl ReleaseEntity { @@ -352,48 +337,44 @@ impl ReleaseEntity { pub struct Success { #[serde(rename = "message")] pub message: String, - } impl Success { - pub fn new(message: String, ) -> Success { - Success { - message: message, - } + pub fn new(message: String) -> Success { + Success { message: message } } } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct WorkEntity { #[serde(rename = "work_type")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub work_type: Option, #[serde(rename = "title")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, #[serde(rename = "editgroup")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub editgroup: Option, #[serde(rename = "redirect")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, #[serde(rename = "revision")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, #[serde(rename = "ident")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub ident: Option, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] - #[serde(skip_serializing_if="Option::is_none")] + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, - } impl WorkEntity { diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs index cb307ad4..66539c55 100644 --- a/rust/fatcat-api/src/server.rs +++ b/rust/fatcat-api/src/server.rs @@ -1,34 +1,31 @@ #![allow(unused_extern_crates)] -extern crate serde_ignored; +extern crate bodyparser; +extern crate chrono; extern crate iron; extern crate router; -extern crate bodyparser; +extern crate serde_ignored; extern crate urlencoded; extern crate uuid; -extern crate chrono; - -use futures::Future; -use futures::future; -use futures::{stream, Stream}; -use hyper; -use hyper::header::{Headers, ContentType}; use self::iron::prelude::*; -use self::iron::{status, modifiers, BeforeMiddleware}; use self::iron::url::percent_encoding::percent_decode; +use self::iron::{modifiers, status, BeforeMiddleware}; use self::router::Router; use self::urlencoded::UrlEncodedQuery; +use futures::Future; +use futures::future; +use futures::{stream, Stream}; +use hyper; +use hyper::header::{ContentType, Headers}; use mimetypes; - use serde_json; - #[allow(unused_imports)] -use std::collections::{HashMap, BTreeMap}; +use std::collections::{BTreeMap, HashMap}; +use std::io::Error; #[allow(unused_imports)] use swagger; -use std::io::Error; #[allow(unused_imports)] use std::collections::BTreeSet; @@ -37,34 +34,22 @@ pub use swagger::auth::Authorization; use swagger::auth::{AuthData, Scopes}; use swagger::{ApiError, Context, XSpanId}; -use {Api, - ContainerIdGetResponse, - ContainerLookupGetResponse, - ContainerPostResponse, - CreatorIdGetResponse, - CreatorLookupGetResponse, - CreatorPostResponse, - EditgroupIdAcceptPostResponse, - EditgroupIdGetResponse, - EditgroupPostResponse, - EditorUsernameChangelogGetResponse, - EditorUsernameGetResponse, - FileIdGetResponse, - FileLookupGetResponse, - FilePostResponse, - ReleaseIdGetResponse, - ReleaseLookupGetResponse, - ReleasePostResponse, - WorkIdGetResponse, - WorkPostResponse - }; #[allow(unused_imports)] use models; +use {Api, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, + CreatorIdGetResponse, CreatorLookupGetResponse, CreatorPostResponse, + EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse, + EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse, + FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, + ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; header! { (Warning, "Warning") => [String] } /// Create a new router for `Api` -pub fn router(api: T) -> Router where T: Api + Send + Sync + Clone + 'static { +pub fn router(api: T) -> Router +where + T: Api + Send + Sync + Clone + 'static, +{ let mut router = Router::new(); add_routes(&mut router, api); router @@ -90,14 +75,19 @@ pub fn router(api: T) -> Router where T: Api + Send + Sync + Clone + 'static /// /// This function exists to allow legacy code, which doesn't separate its APIs properly, to make /// use of this crate. -#[deprecated(note="APIs should not overlap - only for use in legacy code.")] -pub fn route(router: &mut Router, api: T) where T: Api + Send + Sync + Clone + 'static { +#[deprecated(note = "APIs should not overlap - only for use in legacy code.")] +pub fn route(router: &mut Router, api: T) +where + T: Api + Send + Sync + Clone + 'static, +{ add_routes(router, api) } /// Add routes for `Api` to a provided router -fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone + 'static { - +fn add_routes(router: &mut Router, api: T) +where + T: Api + Send + Sync + Clone + 'static, +{ let api_clone = api.clone(); router.get( "/v0/container/:id", @@ -105,75 +95,134 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_id = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("id") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter id".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter id: {}", e), + )) + })? }; - - match api.container_id_get(param_id, context).wait() { Ok(rsp) => match rsp { ContainerIdGetResponse::FetchASingleContainerById(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_FETCH_A_SINGLE_CONTAINER_BY_ID.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } ContainerIdGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CONTAINER_ID_GET_BAD_REQUEST.clone(), + )); - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } ContainerIdGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CONTAINER_ID_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "ContainerIdGet"); + "ContainerIdGet", + ); let api_clone = api.clone(); router.get( @@ -182,84 +231,144 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_issn = query_params.get("issn") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter issn".to_string())))? - .first().ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issn was empty".to_string())))? - .parse::().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter issn - doesn't match schema: {}", e))))?; - + let param_issn = query_params + .get("issn") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing required query parameter issn".to_string(), + )) + })? + .first() + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Required query parameter issn was empty".to_string(), + )) + })? + .parse::() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!( + "Couldn't parse query parameter issn - doesn't match schema: {}", + e + ), + )) + })?; match api.container_lookup_get(param_issn, context).wait() { - Ok(rsp) => match rsp { - ContainerLookupGetResponse::FindASingleContainerByExternalIdentifer(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_FIND_A_SINGLE_CONTAINER_BY_EXTERNAL_IDENTIFER.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - ContainerLookupGetResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - ContainerLookupGetResponse::NoSuchContainer(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_NO_SUCH_CONTAINER.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - ContainerLookupGetResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + Ok(rsp) => { + match rsp { + ContainerLookupGetResponse::FindASingleContainerByExternalIdentifer( + body, + ) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_FIND_A_SINGLE_CONTAINER_BY_EXTERNAL_IDENTIFER.clone())); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + ContainerLookupGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CONTAINER_LOOKUP_GET_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + ContainerLookupGetResponse::NoSuchContainer(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CONTAINER_LOOKUP_GET_NO_SUCH_CONTAINER + .clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + ContainerLookupGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - }, - }, + Ok(response) + } + } + } Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "ContainerLookupGet"); + "ContainerLookupGet", + ); let api_clone = api.clone(); router.post( @@ -268,15 +377,23 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -285,10 +402,11 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { + let param_body = if let Some(param_body_raw) = param_body { let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); - let param_body: Option = serde_ignored::deserialize(deserializer, |path| { + let param_body: Option = + serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).unwrap_or(None); @@ -296,65 +414,98 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone param_body } else { None - };; - + }; match api.container_post(param_body, context).wait() { Ok(rsp) => match rsp { ContainerPostResponse::Created(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_CREATED.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CONTAINER_POST_CREATED.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } ContainerPostResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CONTAINER_POST_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } ContainerPostResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CONTAINER_POST_GENERIC_ERROR_RESPONSE.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "ContainerPost"); + "ContainerPost", + ); let api_clone = api.clone(); router.get( @@ -363,75 +514,136 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_id = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("id") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter id".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter id: {}", e), + )) + })? }; - - match api.creator_id_get(param_id, context).wait() { - Ok(rsp) => match rsp { - CreatorIdGetResponse::FetchASingleCreatorById(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_FETCH_A_SINGLE_CREATOR_BY_ID.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - CreatorIdGetResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - CreatorIdGetResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - }, + Ok(rsp) => { + match rsp { + CreatorIdGetResponse::FetchASingleCreatorById(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_FETCH_A_SINGLE_CREATOR_BY_ID.clone())); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + CreatorIdGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_ID_GET_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + CreatorIdGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_ID_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + } + } Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "CreatorIdGet"); + "CreatorIdGet", + ); let api_clone = api.clone(); router.get( @@ -440,84 +652,142 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_orcid = query_params.get("orcid") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter orcid".to_string())))? - .first().ok_or_else(|| Response::with((status::BadRequest, "Required query parameter orcid was empty".to_string())))? - .parse::().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter orcid - doesn't match schema: {}", e))))?; - + let param_orcid = query_params + .get("orcid") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing required query parameter orcid".to_string(), + )) + })? + .first() + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Required query parameter orcid was empty".to_string(), + )) + })? + .parse::() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!( + "Couldn't parse query parameter orcid - doesn't match schema: {}", + e + ), + )) + })?; match api.creator_lookup_get(param_orcid, context).wait() { Ok(rsp) => match rsp { CreatorLookupGetResponse::FindASingleCreatorByExternalIdentifer(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_FIND_A_SINGLE_CREATOR_BY_EXTERNAL_IDENTIFER.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } CreatorLookupGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_BAD_REQUEST.clone())); + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_LOOKUP_GET_BAD_REQUEST.clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } CreatorLookupGetResponse::NoSuchCreator(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_LOOKUP_GET_NO_SUCH_CREATOR.clone(), + )); - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_NO_SUCH_CREATOR.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } CreatorLookupGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_LOOKUP_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "CreatorLookupGet"); + "CreatorLookupGet", + ); let api_clone = api.clone(); router.post( @@ -526,15 +796,23 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -543,10 +821,11 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { + let param_body = if let Some(param_body_raw) = param_body { let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); - let param_body: Option = serde_ignored::deserialize(deserializer, |path| { + let param_body: Option = + serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).unwrap_or(None); @@ -554,65 +833,98 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone param_body } else { None - };; - + }; match api.creator_post(param_body, context).wait() { Ok(rsp) => match rsp { CreatorPostResponse::Created(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_CREATED.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_POST_CREATED.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } CreatorPostResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_POST_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } CreatorPostResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::CREATOR_POST_GENERIC_ERROR_RESPONSE.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "CreatorPost"); + "CreatorPost", + ); let api_clone = api.clone(); router.post( @@ -621,86 +933,146 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_id = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("id") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter id".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter id: {}", e), + )) + })? }; - - match api.editgroup_id_accept_post(param_id, context).wait() { - Ok(rsp) => match rsp { - EditgroupIdAcceptPostResponse::MergedEditgroupSuccessfully_(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_MERGED_EDITGROUP_SUCCESSFULLY_.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - EditgroupIdAcceptPostResponse::EditgroupIsInAnUnmergableState(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_EDITGROUP_IS_IN_AN_UNMERGABLE_STATE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + Ok(rsp) => { + match rsp { + EditgroupIdAcceptPostResponse::MergedEditgroupSuccessfully_(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_MERGED_EDITGROUP_SUCCESSFULLY_.clone())); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + EditgroupIdAcceptPostResponse::EditgroupIsInAnUnmergableState(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - Ok(response) - }, - EditgroupIdAcceptPostResponse::NoSuchEditgroup(body) => { + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_EDITGROUP_IS_IN_AN_UNMERGABLE_STATE.clone())); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_NO_SUCH_EDITGROUP.clone())); + Ok(response) + } + EditgroupIdAcceptPostResponse::NoSuchEditgroup(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_NO_SUCH_EDITGROUP.clone())); - Ok(response) - }, - EditgroupIdAcceptPostResponse::GenericErrorResponse(body) => { + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + Ok(response) + } + EditgroupIdAcceptPostResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_GENERIC_ERROR_RESPONSE.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - }, - }, + Ok(response) + } + } + } Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "EditgroupIdAcceptPost"); + "EditgroupIdAcceptPost", + ); let api_clone = api.clone(); router.get( @@ -709,75 +1081,134 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_id = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("id") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter id".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter id: {}", e), + )) + })? }; - - match api.editgroup_id_get(param_id, context).wait() { Ok(rsp) => match rsp { EditgroupIdGetResponse::FetchEditgroupByIdentifier(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_FETCH_EDITGROUP_BY_IDENTIFIER.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } EditgroupIdGetResponse::NoSuchEditgroup(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType( + mimetypes::responses::EDITGROUP_ID_GET_NO_SUCH_EDITGROUP.clone(), + )); - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_NO_SUCH_EDITGROUP.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } EditgroupIdGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::EDITGROUP_ID_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "EditgroupIdGet"); + "EditgroupIdGet", + ); let api_clone = api.clone(); router.post( @@ -786,66 +1217,99 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - - match api.editgroup_post(context).wait() { Ok(rsp) => match rsp { EditgroupPostResponse::SuccessfullyCreated(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType( + mimetypes::responses::EDITGROUP_POST_SUCCESSFULLY_CREATED.clone(), + )); - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_SUCCESSFULLY_CREATED.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } EditgroupPostResponse::InvalidRequestParameters(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_INVALID_REQUEST_PARAMETERS.clone())); + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::EDITGROUP_POST_INVALID_REQUEST_PARAMETERS + .clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } EditgroupPostResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::EDITGROUP_POST_GENERIC_ERROR_RESPONSE.clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "EditgroupPost"); + "EditgroupPost", + ); let api_clone = api.clone(); router.get( @@ -854,75 +1318,133 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_username = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("username").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("username") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter username".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter username: {}", e), + )) + })? }; + match api.editor_username_changelog_get(param_username, context) + .wait() + { + Ok(rsp) => { + match rsp { + EditorUsernameChangelogGetResponse::FindChanges_(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_FIND_CHANGES_.clone())); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + EditorUsernameChangelogGetResponse::UsernameNotFound(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_USERNAME_NOT_FOUND.clone())); - match api.editor_username_changelog_get(param_username, context).wait() { - Ok(rsp) => match rsp { - EditorUsernameChangelogGetResponse::FindChanges_(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_FIND_CHANGES_.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - EditorUsernameChangelogGetResponse::UsernameNotFound(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_USERNAME_NOT_FOUND.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - EditorUsernameChangelogGetResponse::GenericErrorResponse(body) => { + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + Ok(response) + } + EditorUsernameChangelogGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_GENERIC_ERROR_RESPONSE.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - }, - }, + Ok(response) + } + } + } Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "EditorUsernameChangelogGet"); + "EditorUsernameChangelogGet", + ); let api_clone = api.clone(); router.get( @@ -931,75 +1453,135 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_username = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("username").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("username") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter username".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter username: {}", e), + )) + })? }; - - match api.editor_username_get(param_username, context).wait() { Ok(rsp) => match rsp { EditorUsernameGetResponse::FetchGenericInformationAboutAnEditor(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_FETCH_GENERIC_INFORMATION_ABOUT_AN_EDITOR.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } EditorUsernameGetResponse::UsernameNotFound(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_USERNAME_NOT_FOUND.clone())); + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType( + mimetypes::responses::EDITOR_USERNAME_GET_USERNAME_NOT_FOUND + .clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } EditorUsernameGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::EDITOR_USERNAME_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "EditorUsernameGet"); + "EditorUsernameGet", + ); let api_clone = api.clone(); router.get( @@ -1008,75 +1590,135 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_id = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("id") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter id".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter id: {}", e), + )) + })? }; - - match api.file_id_get(param_id, context).wait() { Ok(rsp) => match rsp { FileIdGetResponse::FetchASingleFileById(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_FETCH_A_SINGLE_FILE_BY_ID.clone())); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_ID_GET_FETCH_A_SINGLE_FILE_BY_ID.clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } FileIdGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_ID_GET_BAD_REQUEST.clone(), + )); - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } FileIdGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_ID_GET_GENERIC_ERROR_RESPONSE.clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "FileIdGet"); + "FileIdGet", + ); let api_clone = api.clone(); router.get( @@ -1085,84 +1727,142 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_sha1 = query_params.get("sha1") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter sha1".to_string())))? - .first().ok_or_else(|| Response::with((status::BadRequest, "Required query parameter sha1 was empty".to_string())))? - .parse::().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter sha1 - doesn't match schema: {}", e))))?; - + let param_sha1 = query_params + .get("sha1") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing required query parameter sha1".to_string(), + )) + })? + .first() + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Required query parameter sha1 was empty".to_string(), + )) + })? + .parse::() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!( + "Couldn't parse query parameter sha1 - doesn't match schema: {}", + e + ), + )) + })?; match api.file_lookup_get(param_sha1, context).wait() { Ok(rsp) => match rsp { FileLookupGetResponse::FindASingleFileByExternalIdentifer(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_FIND_A_SINGLE_FILE_BY_EXTERNAL_IDENTIFER.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } FileLookupGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_BAD_REQUEST.clone())); + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_LOOKUP_GET_BAD_REQUEST.clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } FileLookupGetResponse::NoSuchFile(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_LOOKUP_GET_NO_SUCH_FILE.clone(), + )); - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_NO_SUCH_FILE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } FileLookupGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone())); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_LOOKUP_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "FileLookupGet"); + "FileLookupGet", + ); let api_clone = api.clone(); router.post( @@ -1171,15 +1871,23 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1188,10 +1896,11 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { + let param_body = if let Some(param_body_raw) = param_body { let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); - let param_body: Option = serde_ignored::deserialize(deserializer, |path| { + let param_body: Option = + serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).unwrap_or(None); @@ -1199,65 +1908,98 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone param_body } else { None - };; - + }; match api.file_post(param_body, context).wait() { Ok(rsp) => match rsp { FilePostResponse::Created(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_POST_CREATED.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(201), body_string)); + response + .headers + .set(ContentType(mimetypes::responses::FILE_POST_CREATED.clone())); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } FilePostResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_POST_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_POST_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } FilePostResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_POST_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::FILE_POST_GENERIC_ERROR_RESPONSE.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "FilePost"); + "FilePost", + ); let api_clone = api.clone(); router.get( @@ -1266,75 +2008,136 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_id = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("id") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter id".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter id: {}", e), + )) + })? }; - - match api.release_id_get(param_id, context).wait() { - Ok(rsp) => match rsp { - ReleaseIdGetResponse::FetchASingleReleaseById(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_FETCH_A_SINGLE_RELEASE_BY_ID.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - ReleaseIdGetResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - ReleaseIdGetResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - }, - }, + Ok(rsp) => { + match rsp { + ReleaseIdGetResponse::FetchASingleReleaseById(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_FETCH_A_SINGLE_RELEASE_BY_ID.clone())); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + ReleaseIdGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_ID_GET_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + ReleaseIdGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_ID_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + } + } Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "ReleaseIdGet"); + "ReleaseIdGet", + ); let api_clone = api.clone(); router.get( @@ -1343,84 +2146,142 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_doi = query_params.get("doi") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter doi".to_string())))? - .first().ok_or_else(|| Response::with((status::BadRequest, "Required query parameter doi was empty".to_string())))? - .parse::().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter doi - doesn't match schema: {}", e))))?; - + let param_doi = query_params + .get("doi") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing required query parameter doi".to_string(), + )) + })? + .first() + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Required query parameter doi was empty".to_string(), + )) + })? + .parse::() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!( + "Couldn't parse query parameter doi - doesn't match schema: {}", + e + ), + )) + })?; match api.release_lookup_get(param_doi, context).wait() { Ok(rsp) => match rsp { ReleaseLookupGetResponse::FindASingleReleaseByExternalIdentifer(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(200), body_string)); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_FIND_A_SINGLE_RELEASE_BY_EXTERNAL_IDENTIFER.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } ReleaseLookupGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_LOOKUP_GET_BAD_REQUEST.clone(), + )); - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } ReleaseLookupGetResponse::NoSuchRelease(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_NO_SUCH_RELEASE.clone())); + let mut response = + Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_LOOKUP_GET_NO_SUCH_RELEASE.clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } ReleaseLookupGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_LOOKUP_GET_GENERIC_ERROR_RESPONSE + .clone(), + )); - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "ReleaseLookupGet"); + "ReleaseLookupGet", + ); let api_clone = api.clone(); router.post( @@ -1429,15 +2290,23 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1446,10 +2315,11 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { + let param_body = if let Some(param_body_raw) = param_body { let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); - let param_body: Option = serde_ignored::deserialize(deserializer, |path| { + let param_body: Option = + serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).unwrap_or(None); @@ -1457,65 +2327,98 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone param_body } else { None - };; - + }; match api.release_post(param_body, context).wait() { Ok(rsp) => match rsp { ReleasePostResponse::Created(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_CREATED.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_POST_CREATED.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } ReleasePostResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_POST_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } ReleasePostResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::RELEASE_POST_GENERIC_ERROR_RESPONSE.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "ReleasePost"); + "ReleasePost", + ); let api_clone = api.clone(); router.get( @@ -1524,75 +2427,135 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - // Path parameters let param_id = { - let param = req.extensions.get::().ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id").ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()).decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse().map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + let param = req.extensions + .get::() + .ok_or_else(|| { + Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + )) + })? + .find("id") + .ok_or_else(|| { + Response::with(( + status::BadRequest, + "Missing path parameter id".to_string(), + )) + })?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| { + Response::with(( + status::BadRequest, + format!( + "Couldn't percent-decode path parameter as UTF-8: {}", + param + ), + )) + })? + .parse() + .map_err(|e| { + Response::with(( + status::BadRequest, + format!("Couldn't parse path parameter id: {}", e), + )) + })? }; - - match api.work_id_get(param_id, context).wait() { Ok(rsp) => match rsp { WorkIdGetResponse::FetchASingleWorkById(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType( + mimetypes::responses::WORK_ID_GET_FETCH_A_SINGLE_WORK_BY_ID.clone(), + )); - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_FETCH_A_SINGLE_WORK_BY_ID.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } WorkIdGetResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_BAD_REQUEST.clone())); + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::WORK_ID_GET_BAD_REQUEST.clone(), + )); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } WorkIdGetResponse::GenericErrorResponse(body) => { + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::WORK_ID_GET_GENERIC_ERROR_RESPONSE.clone(), + )); - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "WorkIdGet"); + "WorkIdGet", + ); let api_clone = api.clone(); router.post( @@ -1601,15 +2564,23 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut context = Context::default(); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result where T: Api { - - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + fn handle_request( + req: &mut Request, + api: &T, + context: &mut Context, + ) -> Result + where + T: Api, + { + context.x_span_id = Some( + req.headers + .get::() + .map(XSpanId::to_string) + .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), + ); context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - - - // Body parameters (note that non-required body parameters will ignore garbage // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. @@ -1618,10 +2589,11 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { + let param_body = if let Some(param_body_raw) = param_body { let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); - let param_body: Option = serde_ignored::deserialize(deserializer, |path| { + let param_body: Option = + serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).unwrap_or(None); @@ -1629,66 +2601,98 @@ fn add_routes(router: &mut Router, api: T) where T: Api + Send + Sync + Clone param_body } else { None - };; - + }; match api.work_post(param_body, context).wait() { Ok(rsp) => match rsp { WorkPostResponse::Created(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_POST_CREATED.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(201), body_string)); + response + .headers + .set(ContentType(mimetypes::responses::WORK_POST_CREATED.clone())); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } WorkPostResponse::BadRequest(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_POST_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType( + mimetypes::responses::WORK_POST_BAD_REQUEST.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } WorkPostResponse::GenericErrorResponse(body) => { - - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_POST_GENERIC_ERROR_RESPONSE.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let body_string = serde_json::to_string(&body) + .expect("impossible to fail to serialize"); + + let mut response = + Response::with((status::Status::from_u16(0), body_string)); + response.headers.set(ContentType( + mimetypes::responses::WORK_POST_GENERIC_ERROR_RESPONSE.clone(), + )); + + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + response.headers.set(Warning(format!( + "Ignoring unknown fields in body: {:?}", + unused_elements + ))); } Ok(response) - }, + } }, Err(_) => { // Application code returned an error. This should not happen, as the implementation should // return a valid response. - Err(Response::with((status::InternalServerError, "An internal error occurred".to_string()))) + Err(Response::with(( + status::InternalServerError, + "An internal error occurred".to_string(), + ))) } } } handle_request(req, &api_clone, &mut context).or_else(|mut response| { - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + context + .x_span_id + .as_ref() + .map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) }) }, - "WorkPost"); - + "WorkPost", + ); } /// Middleware to extract authentication data from request @@ -1696,7 +2700,6 @@ pub struct ExtractAuthData; impl BeforeMiddleware for ExtractAuthData { fn before(&self, req: &mut Request) -> IronResult<()> { - Ok(()) } } -- cgit v1.2.3