diff options
-rw-r--r-- | rust/fatcat-api/examples/client.rs | 245 | ||||
-rw-r--r-- | rust/fatcat-api/examples/server.rs | 16 | ||||
-rw-r--r-- | rust/fatcat-api/examples/server_lib/server.rs | 229 | ||||
-rw-r--r-- | rust/fatcat-api/rustfmt.toml | 5 | ||||
-rw-r--r-- | rust/fatcat-api/src/client.rs | 948 | ||||
-rw-r--r-- | rust/fatcat-api/src/lib.rs | 367 | ||||
-rw-r--r-- | rust/fatcat-api/src/mimetypes.rs | 36 | ||||
-rw-r--r-- | rust/fatcat-api/src/models.rs | 5 | ||||
-rw-r--r-- | rust/fatcat-api/src/server.rs | 2102 |
9 files changed, 924 insertions, 3029 deletions
diff --git a/rust/fatcat-api/examples/client.rs b/rust/fatcat-api/examples/client.rs index bd43e7cc..8c1ec930 100644 --- a/rust/fatcat-api/examples/client.rs +++ b/rust/fatcat-api/examples/client.rs @@ -11,13 +11,9 @@ extern crate uuid; use clap::{App, Arg}; #[allow(unused_imports)] -use fatcat::{ApiError, ApiNoContext, ContainerIdGetResponse, ContainerLookupGetResponse, - ContainerPostResponse, ContextWrapperExt, CreatorIdGetResponse, - CreatorLookupGetResponse, CreatorPostResponse, EditgroupIdAcceptPostResponse, - EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, - EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse, - FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, - ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; +use fatcat::{ApiError, ApiNoContext, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, ContextWrapperExt, CreatorIdGetResponse, CreatorLookupGetResponse, + CreatorPostResponse, EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse, + FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; #[allow(unused_imports)] use futures::{future, stream, Future, Stream}; @@ -50,25 +46,9 @@ fn main() { .required(true) .index(1), ) - .arg( - Arg::with_name("https") - .long("https") - .help("Whether to use HTTPS or not"), - ) - .arg( - Arg::with_name("host") - .long("host") - .takes_value(true) - .default_value("api.fatcat.wiki") - .help("Hostname to contact"), - ) - .arg( - Arg::with_name("port") - .long("port") - .takes_value(true) - .default_value("8080") - .help("Port to contact"), - ) + .arg(Arg::with_name("https").long("https").help("Whether to use HTTPS or not")) + .arg(Arg::with_name("host").long("host").takes_value(true).default_value("api.fatcat.wiki").help("Hostname to contact")) + .arg(Arg::with_name("port").long("port").takes_value(true).default_value("8080").help("Port to contact")) .get_matches(); let is_https = matches.is_present("https"); @@ -80,272 +60,109 @@ fn main() { ); let client = if is_https { // Using Simple HTTPS - fatcat::Client::try_new_https(&base_url, "examples/ca.pem") - .expect("Failed to create HTTPS client") + fatcat::Client::try_new_https(&base_url, "examples/ca.pem").expect("Failed to create HTTPS client") } else { // Using HTTP fatcat::Client::try_new_http(&base_url).expect("Failed to create HTTP client") }; // Using a non-default `Context` is not required; this is just an example! - let client = client.with_context(fatcat::Context::new_with_span_id( - self::uuid::Uuid::new_v4().to_string(), - )); + let client = client.with_context(fatcat::Context::new_with_span_id(self::uuid::Uuid::new_v4().to_string())); match matches.value_of("operation") { Some("ContainerIdGet") => { let result = client.container_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("ContainerLookupGet") => { - let result = client - .container_lookup_get("issn_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + let result = client.container_lookup_get("issn_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("ContainerPost") => { let result = client.container_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("CreatorIdGet") => { let result = client.creator_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("CreatorLookupGet") => { - let result = client - .creator_lookup_get("orcid_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + let result = client.creator_lookup_get("orcid_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("CreatorPost") => { let result = client.creator_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("EditgroupIdAcceptPost") => { let result = client.editgroup_id_accept_post(56).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("EditgroupIdGet") => { let result = client.editgroup_id_get(56).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("EditgroupPost") => { let result = client.editgroup_post().wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("EditorUsernameChangelogGet") => { - let result = client - .editor_username_changelog_get("username_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + let result = client.editor_username_changelog_get("username_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("EditorUsernameGet") => { - let result = client - .editor_username_get("username_example".to_string()) - .wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + let result = client.editor_username_get("username_example".to_string()).wait(); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("FileIdGet") => { let result = client.file_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("FileLookupGet") => { let result = client.file_lookup_get("sha1_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("FilePost") => { let result = client.file_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("ReleaseIdGet") => { let result = client.release_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("ReleaseLookupGet") => { let result = client.release_lookup_get("doi_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("ReleasePost") => { let result = client.release_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("WorkIdGet") => { let result = client.work_id_get("id_example".to_string()).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } Some("WorkPost") => { let result = client.work_post(None).wait(); - println!( - "{:?} (X-Span-ID: {:?})", - result, - client - .context() - .x_span_id - .clone() - .unwrap_or(String::from("<none>")) - ); + println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>"))); } _ => panic!("Invalid operation provided"), diff --git a/rust/fatcat-api/examples/server.rs b/rust/fatcat-api/examples/server.rs index e97d69ca..612ec4b2 100644 --- a/rust/fatcat-api/examples/server.rs +++ b/rust/fatcat-api/examples/server.rs @@ -43,13 +43,7 @@ fn ssl() -> Result<OpensslServer, ErrorStack> { /// Create custom server, wire it to the autogenerated router, /// and pass it to the web server. fn main() { - let matches = App::new("server") - .arg( - Arg::with_name("https") - .long("https") - .help("Whether to use HTTPS or not"), - ) - .get_matches(); + let matches = App::new("server").arg(Arg::with_name("https").long("https").help("Whether to use HTTPS or not")).get_matches(); let server = server_lib::server().unwrap(); let router = fatcat::router(server); @@ -62,13 +56,9 @@ fn main() { if matches.is_present("https") { // Using Simple HTTPS - Iron::new(chain) - .https("localhost:8080", ssl().expect("Failed to load SSL keys")) - .expect("Failed to start HTTPS server"); + Iron::new(chain).https("localhost:8080", ssl().expect("Failed to load SSL keys")).expect("Failed to start HTTPS server"); } else { // Using HTTP - Iron::new(chain) - .http("localhost:8080") - .expect("Failed to start HTTP server"); + Iron::new(chain).http("localhost:8080").expect("Failed to start HTTP server"); } } diff --git a/rust/fatcat-api/examples/server_lib/server.rs b/rust/fatcat-api/examples/server_lib/server.rs index ec915786..fc0e5174 100644 --- a/rust/fatcat-api/examples/server_lib/server.rs +++ b/rust/fatcat-api/examples/server_lib/server.rs @@ -10,146 +10,69 @@ use std::collections::HashMap; use swagger; use fatcat::models; -use fatcat::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse, - ContainerPostResponse, Context, CreatorIdGetResponse, CreatorLookupGetResponse, - CreatorPostResponse, EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, - EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, - FileIdGetResponse, FileLookupGetResponse, FilePostResponse, ReleaseIdGetResponse, - ReleaseLookupGetResponse, ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; +use fatcat::{Api, ApiError, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, Context, CreatorIdGetResponse, CreatorLookupGetResponse, CreatorPostResponse, + EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileIdGetResponse, FileLookupGetResponse, + FilePostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, ReleasePostResponse, WorkIdGetResponse, WorkPostResponse}; #[derive(Copy, Clone)] pub struct Server; impl Api for Server { - fn container_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> { + fn container_id_get(&self, id: String, context: &Context) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "container_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("container_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn container_lookup_get( - &self, - issn: String, - context: &Context, - ) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { + fn container_lookup_get(&self, issn: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "container_lookup_get(\"{}\") - X-Span-ID: {:?}", - issn, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("container_lookup_get(\"{}\") - X-Span-ID: {:?}", issn, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn container_post( - &self, - body: Option<models::ContainerEntity>, - context: &Context, - ) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> { + fn container_post(&self, body: Option<models::ContainerEntity>, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "container_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("container_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn creator_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> { + fn creator_id_get(&self, id: String, context: &Context) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "creator_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("creator_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn creator_lookup_get( - &self, - orcid: String, - context: &Context, - ) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send> { + fn creator_lookup_get(&self, orcid: String, context: &Context) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "creator_lookup_get(\"{}\") - X-Span-ID: {:?}", - orcid, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("creator_lookup_get(\"{}\") - X-Span-ID: {:?}", orcid, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn creator_post( - &self, - body: Option<models::CreatorEntity>, - context: &Context, - ) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> { + fn creator_post(&self, body: Option<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "creator_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("creator_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editgroup_id_accept_post( - &self, - id: i32, - context: &Context, - ) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> { + fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "editgroup_id_accept_post({}) - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("editgroup_id_accept_post({}) - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editgroup_id_get( - &self, - id: i32, - context: &Context, - ) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> { + fn editgroup_id_get(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "editgroup_id_get({}) - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("editgroup_id_get({}) - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editgroup_post( - &self, - context: &Context, - ) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> { + fn editgroup_post(&self, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "editgroup_post() - X-Span-ID: {:?}", - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("editgroup_post() - X-Span-ID: {:?}", context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn editor_username_changelog_get( - &self, - username: String, - context: &Context, - ) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send> { + fn editor_username_changelog_get(&self, username: String, context: &Context) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send> { let context = context.clone(); println!( "editor_username_changelog_get(\"{}\") - X-Span-ID: {:?}", @@ -159,129 +82,57 @@ impl Api for Server { Box::new(futures::failed("Generic failure".into())) } - fn editor_username_get( - &self, - username: String, - context: &Context, - ) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send> { + fn editor_username_get(&self, username: String, context: &Context) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "editor_username_get(\"{}\") - X-Span-ID: {:?}", - username, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("editor_username_get(\"{}\") - X-Span-ID: {:?}", username, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn file_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send> { + fn file_id_get(&self, id: String, context: &Context) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "file_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("file_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn file_lookup_get( - &self, - sha1: String, - context: &Context, - ) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send> { + fn file_lookup_get(&self, sha1: String, context: &Context) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "file_lookup_get(\"{}\") - X-Span-ID: {:?}", - sha1, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("file_lookup_get(\"{}\") - X-Span-ID: {:?}", sha1, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn file_post( - &self, - body: Option<models::FileEntity>, - context: &Context, - ) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> { + fn file_post(&self, body: Option<models::FileEntity>, context: &Context) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "file_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("file_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn release_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send> { + fn release_id_get(&self, id: String, context: &Context) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "release_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("release_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn release_lookup_get( - &self, - doi: String, - context: &Context, - ) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send> { + fn release_lookup_get(&self, doi: String, context: &Context) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "release_lookup_get(\"{}\") - X-Span-ID: {:?}", - doi, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("release_lookup_get(\"{}\") - X-Span-ID: {:?}", doi, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn release_post( - &self, - body: Option<models::ReleaseEntity>, - context: &Context, - ) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> { + fn release_post(&self, body: Option<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "release_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("release_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn work_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send> { + fn work_id_get(&self, id: String, context: &Context) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "work_id_get(\"{}\") - X-Span-ID: {:?}", - id, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("work_id_get(\"{}\") - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } - fn work_post( - &self, - body: Option<models::WorkEntity>, - context: &Context, - ) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> { + fn work_post(&self, body: Option<models::WorkEntity>, context: &Context) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> { let context = context.clone(); - println!( - "work_post({:?}) - X-Span-ID: {:?}", - body, - context.x_span_id.unwrap_or(String::from("<none>")).clone() - ); + println!("work_post({:?}) - X-Span-ID: {:?}", body, context.x_span_id.unwrap_or(String::from("<none>")).clone()); Box::new(futures::failed("Generic failure".into())) } } diff --git a/rust/fatcat-api/rustfmt.toml b/rust/fatcat-api/rustfmt.toml new file mode 100644 index 00000000..cba42c2b --- /dev/null +++ b/rust/fatcat-api/rustfmt.toml @@ -0,0 +1,5 @@ +# 'ignore' requires nightly rust +#ignore = ['src/server.rs'] + +# For now just make the width really wide +max_width = 200 diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs index 1219e01b..06633ad9 100644 --- a/rust/fatcat-api/src/client.rs +++ b/rust/fatcat-api/src/client.rs @@ -34,18 +34,12 @@ use swagger; 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}; +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<T: IntoUrl>( - input: T, - correct_scheme: Option<&'static str>, -) -> Result<String, ClientInitError> { +fn into_base_path<T: IntoUrl>(input: T, correct_scheme: Option<&'static str>) -> Result<String, ClientInitError> { // First convert to Url, since a base path is a subset of Url. let url = input.into_url()?; @@ -96,8 +90,7 @@ impl Client { 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(); @@ -113,12 +106,7 @@ impl Client { }) } - pub fn try_new_https_mutual<T, CA, K, C>( - base_path: T, - ca_certificate: CA, - client_key: K, - client_certificate: C, - ) -> Result<Client, ClientInitError> + pub fn try_new_https_mutual<T, CA, K, C>(base_path: T, ca_certificate: CA, client_key: K, client_certificate: C) -> Result<Client, ClientInitError> where T: IntoUrl, CA: AsRef<Path>, @@ -131,17 +119,14 @@ 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()); @@ -164,10 +149,7 @@ 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<T>( - base_path: T, - hyper_client: Arc<Fn() -> hyper::client::Client + Sync + Send>, - ) -> Result<Client, ClientInitError> + pub fn try_new_with_hyper_client<T>(base_path: T, hyper_client: Arc<Fn() -> hyper::client::Client + Sync + Send>) -> Result<Client, ClientInitError> where T: IntoUrl, { @@ -179,56 +161,37 @@ impl Client { } impl Api for Client { - fn container_id_get( - &self, - param_id: String, - context: &Context, - ) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> { - let url = format!( - "{}/v0/container/{id}", - self.base_path, - id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn container_id_get(&self, param_id: String, context: &Context) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> { + let url = format!("{}/v0/container/{id}", 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<ContainerIdGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<ContainerIdGetResponse, ApiError> { 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::<models::ContainerEntity>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(ContainerIdGetResponse::GenericErrorResponse(body)) @@ -238,90 +201,60 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { + fn container_lookup_get(&self, param_issn: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { // Query parameters 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) - ); + let url = format!("{}/v0/container/lookup?{issn}", self.base_path, 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<ContainerLookupGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<ContainerLookupGetResponse, ApiError> { 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::<models::ContainerEntity>(&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::<models::Error>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(ContainerLookupGetResponse::GenericErrorResponse(body)) @@ -331,37 +264,23 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<models::ContainerEntity>, - context: &Context, - ) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> { + fn container_post(&self, param_body: Option<models::ContainerEntity>, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> { let url = format!("{}/v0/container", 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(); @@ -372,41 +291,30 @@ 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<ContainerPostResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<ContainerPostResponse, ApiError> { 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::<models::EntityEdit>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(ContainerPostResponse::GenericErrorResponse(body)) @@ -416,78 +324,50 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> { - let url = format!( - "{}/v0/creator/{id}", - self.base_path, - id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn creator_id_get(&self, param_id: String, context: &Context) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> { + let url = format!("{}/v0/creator/{id}", 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<CreatorIdGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<CreatorIdGetResponse, ApiError> { 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::<models::CreatorEntity>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(CreatorIdGetResponse::GenericErrorResponse(body)) @@ -497,90 +377,60 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send> { + fn creator_lookup_get(&self, param_orcid: String, context: &Context) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send> { // Query parameters 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) - ); + let url = format!("{}/v0/creator/lookup?{orcid}", self.base_path, 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<CreatorLookupGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<CreatorLookupGetResponse, ApiError> { 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::<models::CreatorEntity>(&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::<models::Error>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(CreatorLookupGetResponse::GenericErrorResponse(body)) @@ -590,37 +440,23 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<models::CreatorEntity>, - context: &Context, - ) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> { + fn creator_post(&self, param_body: Option<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> { 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(); @@ -631,41 +467,30 @@ 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<CreatorPostResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<CreatorPostResponse, ApiError> { 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::<models::EntityEdit>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(CreatorPostResponse::GenericErrorResponse(body)) @@ -675,89 +500,57 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> { - let url = format!( - "{}/v0/editgroup/{id}/accept", - self.base_path, - id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn editgroup_id_accept_post(&self, param_id: i32, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> { + let url = format!("{}/v0/editgroup/{id}/accept", 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<EditgroupIdAcceptPostResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<EditgroupIdAcceptPostResponse, ApiError> { 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::<models::Success>(&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::<models::Error>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(EditgroupIdAcceptPostResponse::GenericErrorResponse(body)) @@ -767,78 +560,50 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> { - let url = format!( - "{}/v0/editgroup/{id}", - self.base_path, - id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn editgroup_id_get(&self, param_id: i32, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> { + let url = format!("{}/v0/editgroup/{id}", 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<EditgroupIdGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<EditgroupIdGetResponse, ApiError> { 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::<models::Editgroup>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(EditgroupIdGetResponse::GenericErrorResponse(body)) @@ -848,73 +613,50 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = EditgroupPostResponse, Error = ApiError> + Send> { + fn editgroup_post(&self, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + 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<EditgroupPostResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<EditgroupPostResponse, ApiError> { 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::<models::Editgroup>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(EditgroupPostResponse::GenericErrorResponse(body)) @@ -924,33 +666,20 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send> { + fn editor_username_changelog_get(&self, param_username: String, context: &Context) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send> { let url = format!( "{}/v0/editor/{username}/changelog", self.base_path, @@ -961,79 +690,53 @@ impl Api for 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<EditorUsernameChangelogGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<EditorUsernameChangelogGetResponse, ApiError> { 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::<models::Changelogentry>(&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::<models::Error>(&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::<models::Error>(&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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send> { + fn editor_username_get(&self, param_username: String, context: &Context) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send> { let url = format!( "{}/v0/editor/{username}", self.base_path, @@ -1044,41 +747,30 @@ impl Api for 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<EditorUsernameGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<EditorUsernameGetResponse, ApiError> { 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::<models::Editor>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(EditorUsernameGetResponse::GenericErrorResponse(body)) @@ -1088,78 +780,50 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = FileIdGetResponse, Error = ApiError> + Send> { - let url = format!( - "{}/v0/file/{id}", - self.base_path, - id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn file_id_get(&self, param_id: String, context: &Context) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send> { + let url = format!("{}/v0/file/{id}", 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<FileIdGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<FileIdGetResponse, ApiError> { 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::<models::FileEntity>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(FileIdGetResponse::GenericErrorResponse(body)) @@ -1169,92 +833,60 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = FileLookupGetResponse, Error = ApiError> + Send> { + fn file_lookup_get(&self, param_sha1: String, context: &Context) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send> { // Query parameters 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) - ); + let url = format!("{}/v0/file/lookup?{sha1}", self.base_path, 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<FileLookupGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<FileLookupGetResponse, ApiError> { 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::<models::FileEntity>(&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::<models::Error>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(FileLookupGetResponse::GenericErrorResponse(body)) @@ -1264,37 +896,23 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<models::FileEntity>, - context: &Context, - ) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> { + fn file_post(&self, param_body: Option<models::FileEntity>, context: &Context) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> { 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(); @@ -1305,41 +923,30 @@ 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<FilePostResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<FilePostResponse, ApiError> { 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::<models::EntityEdit>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(FilePostResponse::GenericErrorResponse(body)) @@ -1349,78 +956,50 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send> { - let url = format!( - "{}/v0/release/{id}", - self.base_path, - id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn release_id_get(&self, param_id: String, context: &Context) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send> { + let url = format!("{}/v0/release/{id}", 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<ReleaseIdGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<ReleaseIdGetResponse, ApiError> { 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::<models::ReleaseEntity>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(ReleaseIdGetResponse::GenericErrorResponse(body)) @@ -1430,90 +1009,60 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send> { + fn release_lookup_get(&self, param_doi: String, context: &Context) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send> { // Query parameters 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) - ); + let url = format!("{}/v0/release/lookup?{doi}", self.base_path, 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<ReleaseLookupGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<ReleaseLookupGetResponse, ApiError> { 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::<models::ReleaseEntity>(&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::<models::Error>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(ReleaseLookupGetResponse::GenericErrorResponse(body)) @@ -1523,37 +1072,23 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<models::ReleaseEntity>, - context: &Context, - ) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> { + fn release_post(&self, param_body: Option<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> { let url = format!("{}/v0/release", 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(); @@ -1564,41 +1099,30 @@ 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<ReleasePostResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<ReleasePostResponse, ApiError> { 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::<models::EntityEdit>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(ReleasePostResponse::GenericErrorResponse(body)) @@ -1608,78 +1132,50 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<Future<Item = WorkIdGetResponse, Error = ApiError> + Send> { - let url = format!( - "{}/v0/work/{id}", - self.base_path, - id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn work_id_get(&self, param_id: String, context: &Context) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send> { + let url = format!("{}/v0/work/{id}", 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<WorkIdGetResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<WorkIdGetResponse, ApiError> { 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::<models::WorkEntity>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(WorkIdGetResponse::GenericErrorResponse(body)) @@ -1689,37 +1185,23 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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<models::WorkEntity>, - context: &Context, - ) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> { + fn work_post(&self, param_body: Option<models::WorkEntity>, context: &Context) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> { let url = format!("{}/v0/work", 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(); @@ -1730,41 +1212,30 @@ 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<WorkPostResponse, ApiError> { + fn parse_response(mut response: hyper::client::response::Response) -> Result<WorkPostResponse, ApiError> { 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::<models::EntityEdit>(&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::<models::Error>(&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::<models::Error>(&buf)?; Ok(WorkPostResponse::GenericErrorResponse(body)) @@ -1774,25 +1245,16 @@ impl Api for Client { 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!( - "<Body was not UTF8: {:?}>", - &buf[..len].to_vec() - )), + Err(_) => Cow::from(format!("<Body was not UTF8: {:?}>", &buf[..len].to_vec())), }, Err(e) => Cow::from(format!("<Failed to read body: {}>", 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)) } } diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs index 2b7c84a0..a01189ef 100644 --- a/rust/fatcat-api/src/lib.rs +++ b/rust/fatcat-api/src/lib.rs @@ -1,5 +1,4 @@ -#![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; @@ -235,213 +234,84 @@ pub enum WorkPostResponse { /// API pub trait Api { - fn container_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send>; - - fn container_lookup_get( - &self, - issn: String, - context: &Context, - ) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; - - fn container_post( - &self, - body: Option<models::ContainerEntity>, - context: &Context, - ) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>; - - fn creator_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send>; - - fn creator_lookup_get( - &self, - orcid: String, - context: &Context, - ) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send>; - - fn creator_post( - &self, - body: Option<models::CreatorEntity>, - context: &Context, - ) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>; - - fn editgroup_id_accept_post( - &self, - id: i32, - context: &Context, - ) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>; - - fn editgroup_id_get( - &self, - id: i32, - context: &Context, - ) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>; - - fn editgroup_post( - &self, - context: &Context, - ) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>; - - fn editor_username_changelog_get( - &self, - username: String, - context: &Context, - ) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send>; - - fn editor_username_get( - &self, - username: String, - context: &Context, - ) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send>; - - fn file_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send>; - - fn file_lookup_get( - &self, - sha1: String, - context: &Context, - ) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send>; - - fn file_post( - &self, - body: Option<models::FileEntity>, - context: &Context, - ) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>; - - fn release_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send>; - - fn release_lookup_get( - &self, - doi: String, - context: &Context, - ) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send>; - - fn release_post( - &self, - body: Option<models::ReleaseEntity>, - context: &Context, - ) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>; - - fn work_id_get( - &self, - id: String, - context: &Context, - ) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send>; - - fn work_post( - &self, - body: Option<models::WorkEntity>, - context: &Context, - ) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>; + fn container_id_get(&self, id: String, context: &Context) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send>; + + fn container_lookup_get(&self, issn: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; + + fn container_post(&self, body: Option<models::ContainerEntity>, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>; + + fn creator_id_get(&self, id: String, context: &Context) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send>; + + fn creator_lookup_get(&self, orcid: String, context: &Context) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send>; + + fn creator_post(&self, body: Option<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>; + + fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>; + + fn editgroup_id_get(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>; + + fn editgroup_post(&self, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>; + + fn editor_username_changelog_get(&self, username: String, context: &Context) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send>; + + fn editor_username_get(&self, username: String, context: &Context) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send>; + + fn file_id_get(&self, id: String, context: &Context) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send>; + + fn file_lookup_get(&self, sha1: String, context: &Context) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send>; + + fn file_post(&self, body: Option<models::FileEntity>, context: &Context) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>; + + fn release_id_get(&self, id: String, context: &Context) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send>; + + fn release_lookup_get(&self, doi: String, context: &Context) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send>; + + fn release_post(&self, body: Option<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>; + + fn work_id_get(&self, id: String, context: &Context) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send>; + + fn work_post(&self, body: Option<models::WorkEntity>, context: &Context) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>; } /// API without a `Context` pub trait ApiNoContext { - fn container_id_get( - &self, - id: String, - ) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send>; - - fn container_lookup_get( - &self, - issn: String, - ) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; - - fn container_post( - &self, - body: Option<models::ContainerEntity>, - ) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>; - - fn creator_id_get( - &self, - id: String, - ) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send>; - - fn creator_lookup_get( - &self, - orcid: String, - ) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send>; - - fn creator_post( - &self, - body: Option<models::CreatorEntity>, - ) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>; - - fn editgroup_id_accept_post( - &self, - id: i32, - ) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>; - - fn editgroup_id_get( - &self, - id: i32, - ) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>; + fn container_id_get(&self, id: String) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send>; + + fn container_lookup_get(&self, issn: String) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>; + + fn container_post(&self, body: Option<models::ContainerEntity>) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>; + + fn creator_id_get(&self, id: String) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send>; + + fn creator_lookup_get(&self, orcid: String) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send>; + + fn creator_post(&self, body: Option<models::CreatorEntity>) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>; + + fn editgroup_id_accept_post(&self, id: i32) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>; + + fn editgroup_id_get(&self, id: i32) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>; fn editgroup_post(&self) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>; - fn editor_username_changelog_get( - &self, - username: String, - ) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send>; - - fn editor_username_get( - &self, - username: String, - ) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send>; - - fn file_id_get( - &self, - id: String, - ) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send>; - - fn file_lookup_get( - &self, - sha1: String, - ) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send>; - - fn file_post( - &self, - body: Option<models::FileEntity>, - ) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>; - - fn release_id_get( - &self, - id: String, - ) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send>; - - fn release_lookup_get( - &self, - doi: String, - ) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send>; - - fn release_post( - &self, - body: Option<models::ReleaseEntity>, - ) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>; - - fn work_id_get( - &self, - id: String, - ) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send>; - - fn work_post( - &self, - body: Option<models::WorkEntity>, - ) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>; + fn editor_username_changelog_get(&self, username: String) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send>; + + fn editor_username_get(&self, username: String) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send>; + + fn file_id_get(&self, id: String) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send>; + + fn file_lookup_get(&self, sha1: String) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send>; + + fn file_post(&self, body: Option<models::FileEntity>) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>; + + fn release_id_get(&self, id: String) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send>; + + fn release_lookup_get(&self, doi: String) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send>; + + fn release_post(&self, body: Option<models::ReleaseEntity>) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>; + + fn work_id_get(&self, id: String) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send>; + + fn work_post(&self, body: Option<models::WorkEntity>) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>; } /// Trait to extend an API to make it easy to bind it to a context. @@ -460,59 +330,35 @@ impl<'a, T: Api + Sized> ContextWrapperExt<'a> for T { } impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { - fn container_id_get( - &self, - id: String, - ) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> { + fn container_id_get(&self, id: String) -> Box<Future<Item = ContainerIdGetResponse, Error = ApiError> + Send> { self.api().container_id_get(id, &self.context()) } - fn container_lookup_get( - &self, - issn: String, - ) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { + fn container_lookup_get(&self, issn: String) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send> { self.api().container_lookup_get(issn, &self.context()) } - fn container_post( - &self, - body: Option<models::ContainerEntity>, - ) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> { + fn container_post(&self, body: Option<models::ContainerEntity>) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> { self.api().container_post(body, &self.context()) } - fn creator_id_get( - &self, - id: String, - ) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> { + fn creator_id_get(&self, id: String) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send> { self.api().creator_id_get(id, &self.context()) } - fn creator_lookup_get( - &self, - orcid: String, - ) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send> { + fn creator_lookup_get(&self, orcid: String) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send> { self.api().creator_lookup_get(orcid, &self.context()) } - fn creator_post( - &self, - body: Option<models::CreatorEntity>, - ) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> { + fn creator_post(&self, body: Option<models::CreatorEntity>) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> { self.api().creator_post(body, &self.context()) } - fn editgroup_id_accept_post( - &self, - id: i32, - ) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> { + fn editgroup_id_accept_post(&self, id: i32) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> { self.api().editgroup_id_accept_post(id, &self.context()) } - fn editgroup_id_get( - &self, - id: i32, - ) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> { + fn editgroup_id_get(&self, id: i32) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> { self.api().editgroup_id_get(id, &self.context()) } @@ -520,74 +366,43 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().editgroup_post(&self.context()) } - fn editor_username_changelog_get( - &self, - username: String, - ) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send> { - self.api() - .editor_username_changelog_get(username, &self.context()) + fn editor_username_changelog_get(&self, username: String) -> Box<Future<Item = EditorUsernameChangelogGetResponse, Error = ApiError> + Send> { + self.api().editor_username_changelog_get(username, &self.context()) } - fn editor_username_get( - &self, - username: String, - ) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send> { + fn editor_username_get(&self, username: String) -> Box<Future<Item = EditorUsernameGetResponse, Error = ApiError> + Send> { self.api().editor_username_get(username, &self.context()) } - fn file_id_get( - &self, - id: String, - ) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send> { + fn file_id_get(&self, id: String) -> Box<Future<Item = FileIdGetResponse, Error = ApiError> + Send> { self.api().file_id_get(id, &self.context()) } - fn file_lookup_get( - &self, - sha1: String, - ) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send> { + fn file_lookup_get(&self, sha1: String) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send> { self.api().file_lookup_get(sha1, &self.context()) } - fn file_post( - &self, - body: Option<models::FileEntity>, - ) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> { + fn file_post(&self, body: Option<models::FileEntity>) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> { self.api().file_post(body, &self.context()) } - fn release_id_get( - &self, - id: String, - ) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send> { + fn release_id_get(&self, id: String) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send> { self.api().release_id_get(id, &self.context()) } - fn release_lookup_get( - &self, - doi: String, - ) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send> { + fn release_lookup_get(&self, doi: String) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send> { self.api().release_lookup_get(doi, &self.context()) } - fn release_post( - &self, - body: Option<models::ReleaseEntity>, - ) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> { + fn release_post(&self, body: Option<models::ReleaseEntity>) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> { self.api().release_post(body, &self.context()) } - fn work_id_get( - &self, - id: String, - ) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send> { + fn work_id_get(&self, id: String) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send> { self.api().work_id_get(id, &self.context()) } - fn work_post( - &self, - body: Option<models::WorkEntity>, - ) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> { + fn work_post(&self, body: Option<models::WorkEntity>) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> { self.api().work_post(body, &self.context()) } } diff --git a/rust/fatcat-api/src/mimetypes.rs b/rust/fatcat-api/src/mimetypes.rs index 6076d488..cc362421 100644 --- a/rust/fatcat-api/src/mimetypes.rs +++ b/rust/fatcat-api/src/mimetypes.rs @@ -6,8 +6,7 @@ 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! { @@ -19,8 +18,7 @@ pub mod responses { } /// 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! { @@ -60,8 +58,7 @@ pub mod responses { } /// 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! { @@ -89,13 +86,11 @@ pub mod responses { } /// 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! { @@ -103,13 +98,11 @@ pub mod responses { } /// 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! { @@ -137,18 +130,15 @@ pub mod responses { } /// 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! { @@ -172,8 +162,7 @@ pub mod responses { } /// 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! { @@ -213,8 +202,7 @@ pub mod responses { } /// 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! { diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index 3d104b78..5e5be35f 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -145,10 +145,7 @@ pub struct Editgroup { impl Editgroup { pub fn new(id: isize, editor_id: isize) -> Editgroup { - Editgroup { - id: id, - editor_id: editor_id, - } + Editgroup { id: id, editor_id: editor_id } } } diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs index 66539c55..5e799bd4 100644 --- a/rust/fatcat-api/src/server.rs +++ b/rust/fatcat-api/src/server.rs @@ -36,12 +36,9 @@ use swagger::{ApiError, Context, XSpanId}; #[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}; +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] } @@ -95,20 +92,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -116,88 +104,45 @@ where let param_id = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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) } @@ -205,19 +150,13 @@ where 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) }) }, @@ -231,20 +170,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -252,118 +182,67 @@ where let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default(); let param_issn = query_params .get("issn") - .ok_or_else(|| { - Response::with(( - status::BadRequest, - "Missing required query parameter issn".to_string(), - )) - })? + .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(), - )) - })? + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issn was empty".to_string())))? .parse::<String>() - .map_err(|e| { - Response::with(( - status::BadRequest, - format!( - "Couldn't parse query parameter issn - doesn't match schema: {}", - e - ), - )) - })?; + .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(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(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()))); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - } + 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())); + + 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) }) }, @@ -377,20 +256,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -405,11 +275,10 @@ where 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<models::ContainerEntity> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).unwrap_or(None); + let param_body: Option<models::ContainerEntity> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).unwrap_or(None); param_body } else { @@ -419,68 +288,38 @@ where 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) } @@ -488,19 +327,13 @@ where 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) }) }, @@ -514,20 +347,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -535,110 +359,59 @@ where let param_id = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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) }) }, @@ -652,20 +425,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -673,96 +437,53 @@ where let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default(); let param_orcid = query_params .get("orcid") - .ok_or_else(|| { - Response::with(( - status::BadRequest, - "Missing required query parameter orcid".to_string(), - )) - })? + .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(), - )) - })? + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter orcid was empty".to_string())))? .parse::<String>() - .map_err(|e| { - Response::with(( - status::BadRequest, - format!( - "Couldn't parse query parameter orcid - doesn't match schema: {}", - e - ), - )) - })?; + .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)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_FIND_A_SINGLE_CREATOR_BY_EXTERNAL_IDENTIFER.clone())); + 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) } @@ -770,19 +491,13 @@ where 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) }) }, @@ -796,20 +511,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -824,11 +530,10 @@ where 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<models::CreatorEntity> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).unwrap_or(None); + let param_body: Option<models::CreatorEntity> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).unwrap_or(None); param_body } else { @@ -838,68 +543,38 @@ where 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) } @@ -907,19 +582,13 @@ where 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) }) }, @@ -933,20 +602,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -954,120 +614,71 @@ where let param_id = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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"); + 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(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_EDITGROUP_IS_IN_AN_UNMERGABLE_STATE.clone())); + 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()))); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - } - EditgroupIdAcceptPostResponse::NoSuchEditgroup(body) => { - let body_string = serde_json::to_string(&body) - .expect("impossible to fail to serialize"); + 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(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_NO_SUCH_EDITGROUP.clone())); + 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()))); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - } - EditgroupIdAcceptPostResponse::GenericErrorResponse(body) => { - let body_string = serde_json::to_string(&body) - .expect("impossible to fail to serialize"); + Ok(response) + } + EditgroupIdAcceptPostResponse::NoSuchEditgroup(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(404), body_string)); + response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_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) - } + 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())); + + 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) }) }, @@ -1081,20 +692,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -1102,88 +704,45 @@ where let param_id = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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) } @@ -1191,19 +750,13 @@ where 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) }) }, @@ -1217,74 +770,43 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); 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) } @@ -1292,19 +814,13 @@ where 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) }) }, @@ -1318,20 +834,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -1339,107 +846,59 @@ where let param_username = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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"); + 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(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_USERNAME_NOT_FOUND.clone())); + 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()))); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - } - EditorUsernameChangelogGetResponse::GenericErrorResponse(body) => { - let body_string = serde_json::to_string(&body) - .expect("impossible to fail to serialize"); + 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(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(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()))); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - Ok(response) - } + 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())); + + 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) }) }, @@ -1453,20 +912,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -1474,89 +924,47 @@ where let param_username = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_FETCH_GENERIC_INFORMATION_ABOUT_AN_EDITOR.clone())); + 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) } @@ -1564,19 +972,13 @@ where 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) }) }, @@ -1590,20 +992,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -1611,89 +1004,45 @@ where let param_id = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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) } @@ -1701,19 +1050,13 @@ where 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) }) }, @@ -1727,20 +1070,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -1748,96 +1082,53 @@ where let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default(); let param_sha1 = query_params .get("sha1") - .ok_or_else(|| { - Response::with(( - status::BadRequest, - "Missing required query parameter sha1".to_string(), - )) - })? + .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(), - )) - })? + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter sha1 was empty".to_string())))? .parse::<String>() - .map_err(|e| { - Response::with(( - status::BadRequest, - format!( - "Couldn't parse query parameter sha1 - doesn't match schema: {}", - e - ), - )) - })?; + .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)); - response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_FIND_A_SINGLE_FILE_BY_EXTERNAL_IDENTIFER.clone())); + 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) } @@ -1845,19 +1136,13 @@ where 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) }) }, @@ -1871,20 +1156,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -1899,11 +1175,10 @@ where 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<models::FileEntity> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).unwrap_or(None); + let param_body: Option<models::FileEntity> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).unwrap_or(None); param_body } else { @@ -1913,68 +1188,38 @@ where 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 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())); + 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()))); + 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) } @@ -1982,19 +1227,13 @@ where 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) }) }, @@ -2008,20 +1247,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -2029,110 +1259,59 @@ where let param_id = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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) }) }, @@ -2146,20 +1325,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -2167,96 +1337,53 @@ where let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default(); let param_doi = query_params .get("doi") - .ok_or_else(|| { - Response::with(( - status::BadRequest, - "Missing required query parameter doi".to_string(), - )) - })? + .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(), - )) - })? + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter doi was empty".to_string())))? .parse::<String>() - .map_err(|e| { - Response::with(( - status::BadRequest, - format!( - "Couldn't parse query parameter doi - doesn't match schema: {}", - e - ), - )) - })?; + .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)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_FIND_A_SINGLE_RELEASE_BY_EXTERNAL_IDENTIFER.clone())); + 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) } @@ -2264,19 +1391,13 @@ where 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) }) }, @@ -2290,20 +1411,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -2318,11 +1430,10 @@ where 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<models::ReleaseEntity> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).unwrap_or(None); + let param_body: Option<models::ReleaseEntity> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).unwrap_or(None); param_body } else { @@ -2332,68 +1443,38 @@ where 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) } @@ -2401,19 +1482,13 @@ where 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) }) }, @@ -2427,20 +1502,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -2448,89 +1514,45 @@ where let param_id = { let param = req.extensions .get::<Router>() - .ok_or_else(|| { - Response::with(( - status::InternalServerError, - "An internal error occurred".to_string(), - )) - })? + .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(), - )) - })?; + .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 - ), - )) - })? + .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), - )) - })? + .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) } @@ -2538,19 +1560,13 @@ where 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) }) }, @@ -2564,20 +1580,11 @@ where 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<T>( - req: &mut Request, - api: &T, - context: &mut Context, - ) -> Result<Response, Response> + fn handle_request<T>(req: &mut Request, api: &T, context: &mut Context) -> Result<Response, Response> where T: Api, { - context.x_span_id = Some( - req.headers - .get::<XSpanId>() - .map(XSpanId::to_string) - .unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string()), - ); + context.x_span_id = Some(req.headers.get::<XSpanId>().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); context.auth_data = req.extensions.remove::<AuthData>(); context.authorization = req.extensions.remove::<Authorization>(); @@ -2592,11 +1599,10 @@ where 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<models::WorkEntity> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).unwrap_or(None); + let param_body: Option<models::WorkEntity> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).unwrap_or(None); param_body } else { @@ -2606,68 +1612,38 @@ where 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 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())); + 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()))); + 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) } @@ -2675,19 +1651,13 @@ where 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) }) }, |