From 061e66c4c41063e6b7321f1f421b5152e9e5a84d Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 13 Dec 2018 19:36:25 +0800 Subject: schema tweaks, and rust codegen --- rust/fatcat-api-spec/src/client.rs | 1473 +++++++++++- rust/fatcat-api-spec/src/lib.rs | 464 +++- rust/fatcat-api-spec/src/mimetypes.rs | 320 +++ rust/fatcat-api-spec/src/models.rs | 34 +- rust/fatcat-api-spec/src/server.rs | 4018 ++++++++++++++++++++++++--------- 5 files changed, 5109 insertions(+), 1200 deletions(-) (limited to 'rust/fatcat-api-spec/src') diff --git a/rust/fatcat-api-spec/src/client.rs b/rust/fatcat-api-spec/src/client.rs index bc325361..5a5f4693 100644 --- a/rust/fatcat-api-spec/src/client.rs +++ b/rust/fatcat-api-spec/src/client.rs @@ -36,11 +36,14 @@ use swagger::{ApiError, Context, XSpanId}; use models; use { AcceptEditgroupResponse, Api, CreateContainerBatchResponse, CreateContainerResponse, CreateCreatorBatchResponse, CreateCreatorResponse, CreateEditgroupResponse, CreateFileBatchResponse, - CreateFileResponse, CreateReleaseBatchResponse, CreateReleaseResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerResponse, DeleteCreatorResponse, DeleteFileResponse, - DeleteReleaseResponse, DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, GetContainerHistoryResponse, GetContainerResponse, GetCreatorHistoryResponse, - GetCreatorReleasesResponse, GetCreatorResponse, GetEditgroupResponse, GetEditorChangelogResponse, GetEditorResponse, GetFileHistoryResponse, GetFileResponse, GetReleaseFilesResponse, - GetReleaseHistoryResponse, GetReleaseResponse, GetStatsResponse, GetWorkHistoryResponse, GetWorkReleasesResponse, GetWorkResponse, LookupContainerResponse, LookupCreatorResponse, - LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateFileResponse, UpdateReleaseResponse, UpdateWorkResponse, + CreateFileResponse, CreateReleaseBatchResponse, CreateReleaseResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, + DeleteCreatorEditResponse, DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, DeleteWorkEditResponse, DeleteWorkResponse, + GetChangelogEntryResponse, GetChangelogResponse, GetContainerEditResponse, GetContainerHistoryResponse, GetContainerRedirectsResponse, GetContainerResponse, GetContainerRevisionResponse, + GetCreatorEditResponse, GetCreatorHistoryResponse, GetCreatorRedirectsResponse, GetCreatorReleasesResponse, GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupResponse, + GetEditorChangelogResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetReleaseEditResponse, + GetReleaseFilesResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, GetStatsResponse, GetWorkEditResponse, GetWorkHistoryResponse, + GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, + UpdateContainerResponse, UpdateCreatorResponse, UpdateFileResponse, UpdateReleaseResponse, UpdateWorkResponse, }; /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. @@ -382,6 +385,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn delete_container_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/container/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Delete, &url); + let mut custom_headers = hyper::header::Headers::new(); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteContainerEditResponse::DeletedEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteContainerEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteContainerEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteContainerEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_container(&self, param_id: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); @@ -452,6 +519,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_container_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/container/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerEditResponse::FoundEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_container_history(&self, param_id: String, param_limit: Option, context: &Context) -> Box + Send> { // Query parameters let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); @@ -520,15 +651,163 @@ impl Api for Client { Box::new(futures::done(result)) } - fn lookup_container(&self, param_issnl: String, param_hide: Option, context: &Context) -> Box + Send> { + fn get_container_redirects(&self, param_id: String, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/container/{id}/redirects", + 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetContainerRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerRedirectsResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerRedirectsResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerRedirectsResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_container_revision( + &self, + param_id: String, + param_expand: Option, + param_hide: Option, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_issnl = format!("issnl={issnl}&", issnl = param_issnl.to_string()); + let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/container/lookup?{issnl}{hide}", + "{}/v0/container/rev/{id}?{expand}{hide}", + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), + hide = utf8_percent_encode(&query_hide, 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerRevisionResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerRevisionResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetContainerRevisionResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn lookup_container( + &self, + param_issnl: Option, + param_wikidata_qid: Option, + param_hide: Option, + context: &Context, + ) -> Box + Send> { + // Query parameters + let query_issnl = param_issnl.map_or_else(String::new, |query| format!("issnl={issnl}&", issnl = query.to_string())); + let query_wikidata_qid = param_wikidata_qid.map_or_else(String::new, |query| format!("wikidata_qid={wikidata_qid}&", wikidata_qid = query.to_string())); + let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); + + let url = format!( + "{}/v0/container/lookup?{issnl}{wikidata_qid}{hide}", self.base_path, issnl = utf8_percent_encode(&query_issnl, QUERY_ENCODE_SET), + wikidata_qid = utf8_percent_encode(&query_wikidata_qid, QUERY_ENCODE_SET), hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); @@ -884,6 +1163,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn delete_creator_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/creator/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Delete, &url); + let mut custom_headers = hyper::header::Headers::new(); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteCreatorEditResponse::DeletedEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteCreatorEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteCreatorEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteCreatorEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_creator(&self, param_id: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); @@ -954,6 +1297,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_creator_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/creator/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorEditResponse::FoundEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_creator_history(&self, param_id: String, param_limit: Option, context: &Context) -> Box + Send> { // Query parameters let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); @@ -995,14 +1402,142 @@ impl Api for Client { response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetCreatorHistoryResponse::NotFound(body)) + Ok(GetCreatorHistoryResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorHistoryResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_creator_redirects(&self, param_id: String, context: &Context) -> Box + Send> { + let url = format!("{}/v0/creator/{id}/redirects", 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetCreatorRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorRedirectsResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorRedirectsResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorRedirectsResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_creator_releases(&self, param_id: String, param_hide: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); + + let url = format!( + "{}/v0/creator/{id}/releases?{hide}", + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), + hide = utf8_percent_encode(&query_hide, 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetCreatorReleasesResponse::Found(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorReleasesResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetCreatorReleasesResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetCreatorHistoryResponse::GenericError(body)) + Ok(GetCreatorReleasesResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -1022,14 +1557,22 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_creator_releases(&self, param_id: String, param_hide: Option, context: &Context) -> Box + Send> { + fn get_creator_revision( + &self, + param_id: String, + param_expand: Option, + param_hide: Option, + context: &Context, + ) -> Box + Send> { // Query parameters + let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/creator/{id}/releases?{hide}", + "{}/v0/creator/rev/{id}?{expand}{hide}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); @@ -1042,35 +1585,35 @@ impl Api for Client { let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; - let body = serde_json::from_str::>(&buf)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetCreatorReleasesResponse::Found(body)) + Ok(GetCreatorRevisionResponse::FoundEntityRevision(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetCreatorReleasesResponse::BadRequest(body)) + Ok(GetCreatorRevisionResponse::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)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetCreatorReleasesResponse::NotFound(body)) + Ok(GetCreatorRevisionResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetCreatorReleasesResponse::GenericError(body)) + Ok(GetCreatorRevisionResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -1090,15 +1633,23 @@ impl Api for Client { Box::new(futures::done(result)) } - fn lookup_creator(&self, param_orcid: String, param_hide: Option, context: &Context) -> Box + Send> { + fn lookup_creator( + &self, + param_orcid: Option, + param_wikidata_qid: Option, + param_hide: Option, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_orcid = format!("orcid={orcid}&", orcid = param_orcid.to_string()); + let query_orcid = param_orcid.map_or_else(String::new, |query| format!("orcid={orcid}&", orcid = query.to_string())); + let query_wikidata_qid = param_wikidata_qid.map_or_else(String::new, |query| format!("wikidata_qid={wikidata_qid}&", wikidata_qid = query.to_string())); let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/creator/lookup?{orcid}{hide}", + "{}/v0/creator/lookup?{orcid}{wikidata_qid}{hide}", self.base_path, orcid = utf8_percent_encode(&query_orcid, QUERY_ENCODE_SET), + wikidata_qid = utf8_percent_encode(&query_wikidata_qid, QUERY_ENCODE_SET), hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); @@ -1910,6 +2461,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn delete_file_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/file/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Delete, &url); + let mut custom_headers = hyper::header::Headers::new(); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteFileEditResponse::DeletedEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteFileEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteFileEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteFileEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_file(&self, param_id: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); @@ -1939,28 +2554,220 @@ impl Api for Client { response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetFileResponse::FoundEntity(body)) + Ok(GetFileResponse::FoundEntity(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_file_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/file/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileEditResponse::FoundEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_file_history(&self, param_id: String, param_limit: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); + + let url = format!( + "{}/v0/file/{id}/history?{limit}", + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), + limit = utf8_percent_encode(&query_limit, 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetFileHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileHistoryResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileHistoryResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetFileHistoryResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_file_redirects(&self, param_id: String, context: &Context) -> Box + Send> { + let url = format!("{}/v0/file/{id}/redirects", 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetFileRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetFileResponse::BadRequest(body)) + Ok(GetFileRedirectsResponse::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)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetFileResponse::NotFound(body)) + Ok(GetFileRedirectsResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetFileResponse::GenericError(body)) + Ok(GetFileRedirectsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -1980,15 +2787,17 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_file_history(&self, param_id: String, param_limit: Option, context: &Context) -> Box + Send> { + fn get_file_revision(&self, param_id: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters - let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); + let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); + let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/file/{id}/history?{limit}", + "{}/v0/file/rev/{id}?{expand}{hide}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), - limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET) + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), + hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); @@ -2000,35 +2809,35 @@ impl Api for Client { let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; - let body = serde_json::from_str::>(&buf)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetFileHistoryResponse::FoundEntityHistory(body)) + Ok(GetFileRevisionResponse::FoundEntityRevision(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetFileHistoryResponse::BadRequest(body)) + Ok(GetFileRevisionResponse::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)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetFileHistoryResponse::NotFound(body)) + Ok(GetFileRevisionResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetFileHistoryResponse::GenericError(body)) + Ok(GetFileRevisionResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2048,15 +2857,26 @@ impl Api for Client { Box::new(futures::done(result)) } - fn lookup_file(&self, param_sha1: String, param_hide: Option, context: &Context) -> Box + Send> { + fn lookup_file( + &self, + param_md5: Option, + param_sha1: Option, + param_sha256: Option, + param_hide: Option, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_sha1 = format!("sha1={sha1}&", sha1 = param_sha1.to_string()); + let query_md5 = param_md5.map_or_else(String::new, |query| format!("md5={md5}&", md5 = query.to_string())); + let query_sha1 = param_sha1.map_or_else(String::new, |query| format!("sha1={sha1}&", sha1 = query.to_string())); + let query_sha256 = param_sha256.map_or_else(String::new, |query| format!("sha256={sha256}&", sha256 = query.to_string())); let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/file/lookup?{sha1}{hide}", + "{}/v0/file/lookup?{md5}{sha1}{sha256}{hide}", self.base_path, + md5 = utf8_percent_encode(&query_md5, QUERY_ENCODE_SET), sha1 = utf8_percent_encode(&query_sha1, QUERY_ENCODE_SET), + sha256 = utf8_percent_encode(&query_sha256, QUERY_ENCODE_SET), hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); @@ -2474,6 +3294,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn delete_release_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/release/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Delete, &url); + let mut custom_headers = hyper::header::Headers::new(); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteReleaseEditResponse::DeletedEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteReleaseEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteReleaseEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteReleaseEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_release(&self, param_id: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); @@ -2544,6 +3428,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_release_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/release/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseEditResponse::FoundEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_release_files(&self, param_id: String, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); @@ -2564,35 +3512,163 @@ impl Api for Client { let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { + match response.status.to_u16() { + 200 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetReleaseFilesResponse::Found(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseFilesResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseFilesResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseFilesResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_release_history(&self, param_id: String, param_limit: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); + + let url = format!( + "{}/v0/release/{id}/history?{limit}", + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), + limit = utf8_percent_encode(&query_limit, 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetReleaseHistoryResponse::FoundEntityHistory(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseHistoryResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseHistoryResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetReleaseHistoryResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + + fn get_release_redirects(&self, param_id: String, context: &Context) -> Box + Send> { + let url = format!("{}/v0/release/{id}/redirects", 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()))); + + 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 { 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)))?; - let body = serde_json::from_str::>(&buf)?; + let body = serde_json::from_str::>(&buf)?; - Ok(GetReleaseFilesResponse::Found(body)) + Ok(GetReleaseRedirectsResponse::FoundEntityRedirects(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetReleaseFilesResponse::BadRequest(body)) + Ok(GetReleaseRedirectsResponse::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)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetReleaseFilesResponse::NotFound(body)) + Ok(GetReleaseRedirectsResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetReleaseFilesResponse::GenericError(body)) + Ok(GetReleaseRedirectsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2612,15 +3688,23 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_release_history(&self, param_id: String, param_limit: Option, context: &Context) -> Box + Send> { + fn get_release_revision( + &self, + param_id: String, + param_expand: Option, + param_hide: Option, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); + let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); + let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/release/{id}/history?{limit}", + "{}/v0/release/rev/{id}?{expand}{hide}", self.base_path, id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), - limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET) + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), + hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); @@ -2632,35 +3716,35 @@ impl Api for Client { let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; - let body = serde_json::from_str::>(&buf)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetReleaseHistoryResponse::FoundEntityHistory(body)) + Ok(GetReleaseRevisionResponse::FoundEntityRevision(body)) } 400 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetReleaseHistoryResponse::BadRequest(body)) + Ok(GetReleaseRevisionResponse::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)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetReleaseHistoryResponse::NotFound(body)) + Ok(GetReleaseRevisionResponse::NotFound(body)) } 500 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(GetReleaseHistoryResponse::GenericError(body)) + Ok(GetReleaseRevisionResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2680,15 +3764,32 @@ impl Api for Client { Box::new(futures::done(result)) } - fn lookup_release(&self, param_doi: String, param_hide: Option, context: &Context) -> Box + Send> { + fn lookup_release( + &self, + param_doi: Option, + param_wikidata_qid: Option, + param_isbn13: Option, + param_pmid: Option, + param_pmcid: Option, + param_hide: Option, + context: &Context, + ) -> Box + Send> { // Query parameters - let query_doi = format!("doi={doi}&", doi = param_doi.to_string()); + let query_doi = param_doi.map_or_else(String::new, |query| format!("doi={doi}&", doi = query.to_string())); + let query_wikidata_qid = param_wikidata_qid.map_or_else(String::new, |query| format!("wikidata_qid={wikidata_qid}&", wikidata_qid = query.to_string())); + let query_isbn13 = param_isbn13.map_or_else(String::new, |query| format!("isbn13={isbn13}&", isbn13 = query.to_string())); + let query_pmid = param_pmid.map_or_else(String::new, |query| format!("pmid={pmid}&", pmid = query.to_string())); + let query_pmcid = param_pmcid.map_or_else(String::new, |query| format!("pmcid={pmcid}&", pmcid = query.to_string())); let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); let url = format!( - "{}/v0/release/lookup?{doi}{hide}", + "{}/v0/release/lookup?{doi}{wikidata_qid}{isbn13}{pmid}{pmcid}{hide}", self.base_path, doi = utf8_percent_encode(&query_doi, QUERY_ENCODE_SET), + wikidata_qid = utf8_percent_encode(&query_wikidata_qid, QUERY_ENCODE_SET), + isbn13 = utf8_percent_encode(&query_isbn13, QUERY_ENCODE_SET), + pmid = utf8_percent_encode(&query_pmid, QUERY_ENCODE_SET), + pmcid = utf8_percent_encode(&query_pmcid, QUERY_ENCODE_SET), hide = utf8_percent_encode(&query_hide, QUERY_ENCODE_SET) ); @@ -2976,6 +4077,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn delete_work_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/work/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Delete, &url); + let mut custom_headers = hyper::header::Headers::new(); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteWorkEditResponse::DeletedEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteWorkEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteWorkEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(DeleteWorkEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_work(&self, param_id: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); @@ -3046,6 +4211,70 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_work_edit(&self, param_edit_id: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/work/edit/{edit_id}", + self.base_path, + edit_id = utf8_percent_encode(¶m_edit_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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkEditResponse::FoundEdit(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkEditResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkEditResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkEditResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_work_history(&self, param_id: String, param_limit: Option, context: &Context) -> Box + Send> { // Query parameters let query_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); @@ -3114,6 +4343,66 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_work_redirects(&self, param_id: String, context: &Context) -> Box + Send> { + let url = format!("{}/v0/work/{id}/redirects", 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::>(&buf)?; + + Ok(GetWorkRedirectsResponse::FoundEntityRedirects(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkRedirectsResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkRedirectsResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkRedirectsResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn get_work_releases(&self, param_id: String, param_hide: Option, context: &Context) -> Box + Send> { // Query parameters let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); @@ -3182,6 +4471,76 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_work_revision(&self, param_id: String, param_expand: Option, param_hide: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_expand = param_expand.map_or_else(String::new, |query| format!("expand={expand}&", expand = query.to_string())); + let query_hide = param_hide.map_or_else(String::new, |query| format!("hide={hide}&", hide = query.to_string())); + + let url = format!( + "{}/v0/work/rev/{id}?{expand}{hide}", + self.base_path, + id = utf8_percent_encode(¶m_id.to_string(), PATH_SEGMENT_ENCODE_SET), + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), + hide = utf8_percent_encode(&query_hide, 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()))); + + 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 { + 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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkRevisionResponse::FoundEntityRevision(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkRevisionResponse::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)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkRevisionResponse::NotFound(body)) + } + 500 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(GetWorkRevisionResponse::GenericError(body)) + } + code => { + let mut buf = [0; 100]; + let debug_body = match response.read(&mut buf) { + Ok(len) => match str::from_utf8(&buf[..len]) { + Ok(body) => Cow::from(body), + Err(_) => Cow::from(format!("", &buf[..len].to_vec())), + }, + Err(e) => Cow::from(format!("", e)), + }; + 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); + Box::new(futures::done(result)) + } + fn update_work(&self, param_id: String, param_entity: models::WorkEntity, param_editgroup: Option, context: &Context) -> Box + Send> { // Query parameters let query_editgroup = param_editgroup.map_or_else(String::new, |query| format!("editgroup={editgroup}&", editgroup = query.to_string())); diff --git a/rust/fatcat-api-spec/src/lib.rs b/rust/fatcat-api-spec/src/lib.rs index 1650fbe6..dcc6e813 100644 --- a/rust/fatcat-api-spec/src/lib.rs +++ b/rust/fatcat-api-spec/src/lib.rs @@ -68,6 +68,18 @@ pub enum DeleteContainerResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum DeleteContainerEditResponse { + /// Deleted Edit + DeletedEdit(models::Success), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetContainerResponse { /// Found Entity @@ -80,6 +92,18 @@ pub enum GetContainerResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetContainerEditResponse { + /// Found Edit + FoundEdit(models::EntityEdit), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetContainerHistoryResponse { /// Found Entity History @@ -92,6 +116,30 @@ pub enum GetContainerHistoryResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetContainerRedirectsResponse { + /// Found Entity Redirects + FoundEntityRedirects(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum GetContainerRevisionResponse { + /// Found Entity Revision + FoundEntityRevision(models::ContainerEntity), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum LookupContainerResponse { /// Found Entity @@ -152,6 +200,18 @@ pub enum DeleteCreatorResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum DeleteCreatorEditResponse { + /// Deleted Edit + DeletedEdit(models::Success), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetCreatorResponse { /// Found Entity @@ -164,6 +224,18 @@ pub enum GetCreatorResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetCreatorEditResponse { + /// Found Edit + FoundEdit(models::EntityEdit), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetCreatorHistoryResponse { /// Found Entity History @@ -176,6 +248,18 @@ pub enum GetCreatorHistoryResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetCreatorRedirectsResponse { + /// Found Entity Redirects + FoundEntityRedirects(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetCreatorReleasesResponse { /// Found @@ -188,6 +272,18 @@ pub enum GetCreatorReleasesResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetCreatorRevisionResponse { + /// Found Entity Revision + FoundEntityRevision(models::CreatorEntity), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum LookupCreatorResponse { /// Found Entity @@ -334,6 +430,18 @@ pub enum DeleteFileResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum DeleteFileEditResponse { + /// Deleted Edit + DeletedEdit(models::Success), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetFileResponse { /// Found Entity @@ -346,6 +454,18 @@ pub enum GetFileResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetFileEditResponse { + /// Found Edit + FoundEdit(models::EntityEdit), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetFileHistoryResponse { /// Found Entity History @@ -358,6 +478,30 @@ pub enum GetFileHistoryResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetFileRedirectsResponse { + /// Found Entity Redirects + FoundEntityRedirects(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum GetFileRevisionResponse { + /// Found Entity Revision + FoundEntityRevision(models::FileEntity), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum LookupFileResponse { /// Found Entity @@ -430,6 +574,18 @@ pub enum DeleteReleaseResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum DeleteReleaseEditResponse { + /// Deleted Edit + DeletedEdit(models::Success), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetReleaseResponse { /// Found Entity @@ -442,6 +598,18 @@ pub enum GetReleaseResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetReleaseEditResponse { + /// Found Edit + FoundEdit(models::EntityEdit), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetReleaseFilesResponse { /// Found @@ -466,6 +634,30 @@ pub enum GetReleaseHistoryResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetReleaseRedirectsResponse { + /// Found Entity Redirects + FoundEntityRedirects(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum GetReleaseRevisionResponse { + /// Found Entity Revision + FoundEntityRevision(models::ReleaseEntity), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum LookupReleaseResponse { /// Found Entity @@ -514,6 +706,18 @@ pub enum DeleteWorkResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum DeleteWorkEditResponse { + /// Deleted Edit + DeletedEdit(models::Success), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetWorkResponse { /// Found Entity @@ -526,6 +730,18 @@ pub enum GetWorkResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetWorkEditResponse { + /// Found Edit + FoundEdit(models::EntityEdit), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetWorkHistoryResponse { /// Found Entity History @@ -538,6 +754,18 @@ pub enum GetWorkHistoryResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetWorkRedirectsResponse { + /// Found Entity Redirects + FoundEntityRedirects(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetWorkReleasesResponse { /// Found @@ -550,6 +778,18 @@ pub enum GetWorkReleasesResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetWorkRevisionResponse { + /// Found Entity Revision + FoundEntityRevision(models::WorkEntity), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum UpdateWorkResponse { /// Updated Entity @@ -576,11 +816,19 @@ pub trait Api { fn delete_container(&self, id: String, editgroup: Option, context: &Context) -> Box + Send>; + fn delete_container_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_container(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + fn get_container_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_container_history(&self, id: String, limit: Option, context: &Context) -> Box + Send>; - fn lookup_container(&self, issnl: String, hide: Option, context: &Context) -> Box + Send>; + fn get_container_redirects(&self, id: String, context: &Context) -> Box + Send>; + + fn get_container_revision(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + + fn lookup_container(&self, issnl: Option, wikidata_qid: Option, hide: Option, context: &Context) -> Box + Send>; fn update_container(&self, id: String, entity: models::ContainerEntity, editgroup: Option, context: &Context) -> Box + Send>; @@ -596,13 +844,21 @@ pub trait Api { fn delete_creator(&self, id: String, editgroup: Option, context: &Context) -> Box + Send>; + fn delete_creator_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_creator(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + fn get_creator_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_creator_history(&self, id: String, limit: Option, context: &Context) -> Box + Send>; + fn get_creator_redirects(&self, id: String, context: &Context) -> Box + Send>; + fn get_creator_releases(&self, id: String, hide: Option, context: &Context) -> Box + Send>; - fn lookup_creator(&self, orcid: String, hide: Option, context: &Context) -> Box + Send>; + fn get_creator_revision(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + + fn lookup_creator(&self, orcid: Option, wikidata_qid: Option, hide: Option, context: &Context) -> Box + Send>; fn update_creator(&self, id: String, entity: models::CreatorEntity, editgroup: Option, context: &Context) -> Box + Send>; @@ -634,11 +890,26 @@ pub trait Api { fn delete_file(&self, id: String, editgroup: Option, context: &Context) -> Box + Send>; + fn delete_file_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_file(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + fn get_file_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_file_history(&self, id: String, limit: Option, context: &Context) -> Box + Send>; - fn lookup_file(&self, sha1: String, hide: Option, context: &Context) -> Box + Send>; + fn get_file_redirects(&self, id: String, context: &Context) -> Box + Send>; + + fn get_file_revision(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + + fn lookup_file( + &self, + md5: Option, + sha1: Option, + sha256: Option, + hide: Option, + context: &Context, + ) -> Box + Send>; fn update_file(&self, id: String, entity: models::FileEntity, editgroup: Option, context: &Context) -> Box + Send>; @@ -656,13 +927,30 @@ pub trait Api { fn delete_release(&self, id: String, editgroup: Option, context: &Context) -> Box + Send>; + fn delete_release_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_release(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + fn get_release_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_release_files(&self, id: String, hide: Option, context: &Context) -> Box + Send>; fn get_release_history(&self, id: String, limit: Option, context: &Context) -> Box + Send>; - fn lookup_release(&self, doi: String, hide: Option, context: &Context) -> Box + Send>; + fn get_release_redirects(&self, id: String, context: &Context) -> Box + Send>; + + fn get_release_revision(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + + fn lookup_release( + &self, + doi: Option, + wikidata_qid: Option, + isbn13: Option, + pmid: Option, + pmcid: Option, + hide: Option, + context: &Context, + ) -> Box + Send>; fn update_release(&self, id: String, entity: models::ReleaseEntity, editgroup: Option, context: &Context) -> Box + Send>; @@ -676,12 +964,20 @@ pub trait Api { fn delete_work(&self, id: String, editgroup: Option, context: &Context) -> Box + Send>; + fn delete_work_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_work(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + fn get_work_edit(&self, edit_id: i64, context: &Context) -> Box + Send>; + fn get_work_history(&self, id: String, limit: Option, context: &Context) -> Box + Send>; + fn get_work_redirects(&self, id: String, context: &Context) -> Box + Send>; + fn get_work_releases(&self, id: String, hide: Option, context: &Context) -> Box + Send>; + fn get_work_revision(&self, id: String, expand: Option, hide: Option, context: &Context) -> Box + Send>; + fn update_work(&self, id: String, entity: models::WorkEntity, editgroup: Option, context: &Context) -> Box + Send>; } @@ -698,11 +994,19 @@ pub trait ApiNoContext { fn delete_container(&self, id: String, editgroup: Option) -> Box + Send>; + fn delete_container_edit(&self, edit_id: i64) -> Box + Send>; + fn get_container(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + fn get_container_edit(&self, edit_id: i64) -> Box + Send>; + fn get_container_history(&self, id: String, limit: Option) -> Box + Send>; - fn lookup_container(&self, issnl: String, hide: Option) -> Box + Send>; + fn get_container_redirects(&self, id: String) -> Box + Send>; + + fn get_container_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + + fn lookup_container(&self, issnl: Option, wikidata_qid: Option, hide: Option) -> Box + Send>; fn update_container(&self, id: String, entity: models::ContainerEntity, editgroup: Option) -> Box + Send>; @@ -717,13 +1021,21 @@ pub trait ApiNoContext { fn delete_creator(&self, id: String, editgroup: Option) -> Box + Send>; + fn delete_creator_edit(&self, edit_id: i64) -> Box + Send>; + fn get_creator(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + fn get_creator_edit(&self, edit_id: i64) -> Box + Send>; + fn get_creator_history(&self, id: String, limit: Option) -> Box + Send>; + fn get_creator_redirects(&self, id: String) -> Box + Send>; + fn get_creator_releases(&self, id: String, hide: Option) -> Box + Send>; - fn lookup_creator(&self, orcid: String, hide: Option) -> Box + Send>; + fn get_creator_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + + fn lookup_creator(&self, orcid: Option, wikidata_qid: Option, hide: Option) -> Box + Send>; fn update_creator(&self, id: String, entity: models::CreatorEntity, editgroup: Option) -> Box + Send>; @@ -749,11 +1061,19 @@ pub trait ApiNoContext { fn delete_file(&self, id: String, editgroup: Option) -> Box + Send>; + fn delete_file_edit(&self, edit_id: i64) -> Box + Send>; + fn get_file(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + fn get_file_edit(&self, edit_id: i64) -> Box + Send>; + fn get_file_history(&self, id: String, limit: Option) -> Box + Send>; - fn lookup_file(&self, sha1: String, hide: Option) -> Box + Send>; + fn get_file_redirects(&self, id: String) -> Box + Send>; + + fn get_file_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + + fn lookup_file(&self, md5: Option, sha1: Option, sha256: Option, hide: Option) -> Box + Send>; fn update_file(&self, id: String, entity: models::FileEntity, editgroup: Option) -> Box + Send>; @@ -770,13 +1090,29 @@ pub trait ApiNoContext { fn delete_release(&self, id: String, editgroup: Option) -> Box + Send>; + fn delete_release_edit(&self, edit_id: i64) -> Box + Send>; + fn get_release(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + fn get_release_edit(&self, edit_id: i64) -> Box + Send>; + fn get_release_files(&self, id: String, hide: Option) -> Box + Send>; fn get_release_history(&self, id: String, limit: Option) -> Box + Send>; - fn lookup_release(&self, doi: String, hide: Option) -> Box + Send>; + fn get_release_redirects(&self, id: String) -> Box + Send>; + + fn get_release_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + + fn lookup_release( + &self, + doi: Option, + wikidata_qid: Option, + isbn13: Option, + pmid: Option, + pmcid: Option, + hide: Option, + ) -> Box + Send>; fn update_release(&self, id: String, entity: models::ReleaseEntity, editgroup: Option) -> Box + Send>; @@ -784,12 +1120,20 @@ pub trait ApiNoContext { fn delete_work(&self, id: String, editgroup: Option) -> Box + Send>; + fn delete_work_edit(&self, edit_id: i64) -> Box + Send>; + fn get_work(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + fn get_work_edit(&self, edit_id: i64) -> Box + Send>; + fn get_work_history(&self, id: String, limit: Option) -> Box + Send>; + fn get_work_redirects(&self, id: String) -> Box + Send>; + fn get_work_releases(&self, id: String, hide: Option) -> Box + Send>; + fn get_work_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send>; + fn update_work(&self, id: String, entity: models::WorkEntity, editgroup: Option) -> Box + Send>; } @@ -826,16 +1170,32 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().delete_container(id, editgroup, &self.context()) } + fn delete_container_edit(&self, edit_id: i64) -> Box + Send> { + self.api().delete_container_edit(edit_id, &self.context()) + } + fn get_container(&self, id: String, expand: Option, hide: Option) -> Box + Send> { self.api().get_container(id, expand, hide, &self.context()) } + fn get_container_edit(&self, edit_id: i64) -> Box + Send> { + self.api().get_container_edit(edit_id, &self.context()) + } + fn get_container_history(&self, id: String, limit: Option) -> Box + Send> { self.api().get_container_history(id, limit, &self.context()) } - fn lookup_container(&self, issnl: String, hide: Option) -> Box + Send> { - self.api().lookup_container(issnl, hide, &self.context()) + fn get_container_redirects(&self, id: String) -> Box + Send> { + self.api().get_container_redirects(id, &self.context()) + } + + fn get_container_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send> { + self.api().get_container_revision(id, expand, hide, &self.context()) + } + + fn lookup_container(&self, issnl: Option, wikidata_qid: Option, hide: Option) -> Box + Send> { + self.api().lookup_container(issnl, wikidata_qid, hide, &self.context()) } fn update_container(&self, id: String, entity: models::ContainerEntity, editgroup: Option) -> Box + Send> { @@ -859,20 +1219,36 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().delete_creator(id, editgroup, &self.context()) } + fn delete_creator_edit(&self, edit_id: i64) -> Box + Send> { + self.api().delete_creator_edit(edit_id, &self.context()) + } + fn get_creator(&self, id: String, expand: Option, hide: Option) -> Box + Send> { self.api().get_creator(id, expand, hide, &self.context()) } + fn get_creator_edit(&self, edit_id: i64) -> Box + Send> { + self.api().get_creator_edit(edit_id, &self.context()) + } + fn get_creator_history(&self, id: String, limit: Option) -> Box + Send> { self.api().get_creator_history(id, limit, &self.context()) } + fn get_creator_redirects(&self, id: String) -> Box + Send> { + self.api().get_creator_redirects(id, &self.context()) + } + fn get_creator_releases(&self, id: String, hide: Option) -> Box + Send> { self.api().get_creator_releases(id, hide, &self.context()) } - fn lookup_creator(&self, orcid: String, hide: Option) -> Box + Send> { - self.api().lookup_creator(orcid, hide, &self.context()) + fn get_creator_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send> { + self.api().get_creator_revision(id, expand, hide, &self.context()) + } + + fn lookup_creator(&self, orcid: Option, wikidata_qid: Option, hide: Option) -> Box + Send> { + self.api().lookup_creator(orcid, wikidata_qid, hide, &self.context()) } fn update_creator(&self, id: String, entity: models::CreatorEntity, editgroup: Option) -> Box + Send> { @@ -923,16 +1299,32 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().delete_file(id, editgroup, &self.context()) } + fn delete_file_edit(&self, edit_id: i64) -> Box + Send> { + self.api().delete_file_edit(edit_id, &self.context()) + } + fn get_file(&self, id: String, expand: Option, hide: Option) -> Box + Send> { self.api().get_file(id, expand, hide, &self.context()) } + fn get_file_edit(&self, edit_id: i64) -> Box + Send> { + self.api().get_file_edit(edit_id, &self.context()) + } + fn get_file_history(&self, id: String, limit: Option) -> Box + Send> { self.api().get_file_history(id, limit, &self.context()) } - fn lookup_file(&self, sha1: String, hide: Option) -> Box + Send> { - self.api().lookup_file(sha1, hide, &self.context()) + fn get_file_redirects(&self, id: String) -> Box + Send> { + self.api().get_file_redirects(id, &self.context()) + } + + fn get_file_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send> { + self.api().get_file_revision(id, expand, hide, &self.context()) + } + + fn lookup_file(&self, md5: Option, sha1: Option, sha256: Option, hide: Option) -> Box + Send> { + self.api().lookup_file(md5, sha1, sha256, hide, &self.context()) } fn update_file(&self, id: String, entity: models::FileEntity, editgroup: Option) -> Box + Send> { @@ -960,10 +1352,18 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().delete_release(id, editgroup, &self.context()) } + fn delete_release_edit(&self, edit_id: i64) -> Box + Send> { + self.api().delete_release_edit(edit_id, &self.context()) + } + fn get_release(&self, id: String, expand: Option, hide: Option) -> Box + Send> { self.api().get_release(id, expand, hide, &self.context()) } + fn get_release_edit(&self, edit_id: i64) -> Box + Send> { + self.api().get_release_edit(edit_id, &self.context()) + } + fn get_release_files(&self, id: String, hide: Option) -> Box + Send> { self.api().get_release_files(id, hide, &self.context()) } @@ -972,8 +1372,24 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().get_release_history(id, limit, &self.context()) } - fn lookup_release(&self, doi: String, hide: Option) -> Box + Send> { - self.api().lookup_release(doi, hide, &self.context()) + fn get_release_redirects(&self, id: String) -> Box + Send> { + self.api().get_release_redirects(id, &self.context()) + } + + fn get_release_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send> { + self.api().get_release_revision(id, expand, hide, &self.context()) + } + + fn lookup_release( + &self, + doi: Option, + wikidata_qid: Option, + isbn13: Option, + pmid: Option, + pmcid: Option, + hide: Option, + ) -> Box + Send> { + self.api().lookup_release(doi, wikidata_qid, isbn13, pmid, pmcid, hide, &self.context()) } fn update_release(&self, id: String, entity: models::ReleaseEntity, editgroup: Option) -> Box + Send> { @@ -988,18 +1404,34 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().delete_work(id, editgroup, &self.context()) } + fn delete_work_edit(&self, edit_id: i64) -> Box + Send> { + self.api().delete_work_edit(edit_id, &self.context()) + } + fn get_work(&self, id: String, expand: Option, hide: Option) -> Box + Send> { self.api().get_work(id, expand, hide, &self.context()) } + fn get_work_edit(&self, edit_id: i64) -> Box + Send> { + self.api().get_work_edit(edit_id, &self.context()) + } + fn get_work_history(&self, id: String, limit: Option) -> Box + Send> { self.api().get_work_history(id, limit, &self.context()) } + fn get_work_redirects(&self, id: String) -> Box + Send> { + self.api().get_work_redirects(id, &self.context()) + } + fn get_work_releases(&self, id: String, hide: Option) -> Box + Send> { self.api().get_work_releases(id, hide, &self.context()) } + fn get_work_revision(&self, id: String, expand: Option, hide: Option) -> Box + Send> { + self.api().get_work_revision(id, expand, hide, &self.context()) + } + fn update_work(&self, id: String, entity: models::WorkEntity, editgroup: Option) -> Box + Send> { self.api().update_work(id, entity, editgroup, &self.context()) } diff --git a/rust/fatcat-api-spec/src/mimetypes.rs b/rust/fatcat-api-spec/src/mimetypes.rs index dcf13f7a..b94aa6f6 100644 --- a/rust/fatcat-api-spec/src/mimetypes.rs +++ b/rust/fatcat-api-spec/src/mimetypes.rs @@ -52,6 +52,22 @@ pub mod responses { lazy_static! { pub static ref DELETE_CONTAINER_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for DeleteContainerEdit + lazy_static! { + pub static ref DELETE_CONTAINER_EDIT_DELETED_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteContainerEdit + lazy_static! { + pub static ref DELETE_CONTAINER_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteContainerEdit + lazy_static! { + pub static ref DELETE_CONTAINER_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteContainerEdit + lazy_static! { + pub static ref DELETE_CONTAINER_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetContainer lazy_static! { pub static ref GET_CONTAINER_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -68,6 +84,22 @@ pub mod responses { lazy_static! { pub static ref GET_CONTAINER_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetContainerEdit + lazy_static! { + pub static ref GET_CONTAINER_EDIT_FOUND_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerEdit + lazy_static! { + pub static ref GET_CONTAINER_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerEdit + lazy_static! { + pub static ref GET_CONTAINER_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerEdit + lazy_static! { + pub static ref GET_CONTAINER_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetContainerHistory lazy_static! { pub static ref GET_CONTAINER_HISTORY_FOUND_ENTITY_HISTORY: Mime = mime!(Application / Json); @@ -84,6 +116,38 @@ pub mod responses { lazy_static! { pub static ref GET_CONTAINER_HISTORY_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetContainerRedirects + lazy_static! { + pub static ref GET_CONTAINER_REDIRECTS_FOUND_ENTITY_REDIRECTS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerRedirects + lazy_static! { + pub static ref GET_CONTAINER_REDIRECTS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerRedirects + lazy_static! { + pub static ref GET_CONTAINER_REDIRECTS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerRedirects + lazy_static! { + pub static ref GET_CONTAINER_REDIRECTS_GENERIC_ERROR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerRevision + lazy_static! { + pub static ref GET_CONTAINER_REVISION_FOUND_ENTITY_REVISION: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerRevision + lazy_static! { + pub static ref GET_CONTAINER_REVISION_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerRevision + lazy_static! { + pub static ref GET_CONTAINER_REVISION_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetContainerRevision + lazy_static! { + pub static ref GET_CONTAINER_REVISION_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for LookupContainer lazy_static! { pub static ref LOOKUP_CONTAINER_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -164,6 +228,22 @@ pub mod responses { lazy_static! { pub static ref DELETE_CREATOR_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for DeleteCreatorEdit + lazy_static! { + pub static ref DELETE_CREATOR_EDIT_DELETED_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteCreatorEdit + lazy_static! { + pub static ref DELETE_CREATOR_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteCreatorEdit + lazy_static! { + pub static ref DELETE_CREATOR_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteCreatorEdit + lazy_static! { + pub static ref DELETE_CREATOR_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetCreator lazy_static! { pub static ref GET_CREATOR_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -180,6 +260,22 @@ pub mod responses { lazy_static! { pub static ref GET_CREATOR_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetCreatorEdit + lazy_static! { + pub static ref GET_CREATOR_EDIT_FOUND_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorEdit + lazy_static! { + pub static ref GET_CREATOR_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorEdit + lazy_static! { + pub static ref GET_CREATOR_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorEdit + lazy_static! { + pub static ref GET_CREATOR_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetCreatorHistory lazy_static! { pub static ref GET_CREATOR_HISTORY_FOUND_ENTITY_HISTORY: Mime = mime!(Application / Json); @@ -196,6 +292,22 @@ pub mod responses { lazy_static! { pub static ref GET_CREATOR_HISTORY_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetCreatorRedirects + lazy_static! { + pub static ref GET_CREATOR_REDIRECTS_FOUND_ENTITY_REDIRECTS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorRedirects + lazy_static! { + pub static ref GET_CREATOR_REDIRECTS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorRedirects + lazy_static! { + pub static ref GET_CREATOR_REDIRECTS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorRedirects + lazy_static! { + pub static ref GET_CREATOR_REDIRECTS_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetCreatorReleases lazy_static! { pub static ref GET_CREATOR_RELEASES_FOUND: Mime = mime!(Application / Json); @@ -212,6 +324,22 @@ pub mod responses { lazy_static! { pub static ref GET_CREATOR_RELEASES_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetCreatorRevision + lazy_static! { + pub static ref GET_CREATOR_REVISION_FOUND_ENTITY_REVISION: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorRevision + lazy_static! { + pub static ref GET_CREATOR_REVISION_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorRevision + lazy_static! { + pub static ref GET_CREATOR_REVISION_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetCreatorRevision + lazy_static! { + pub static ref GET_CREATOR_REVISION_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for LookupCreator lazy_static! { pub static ref LOOKUP_CREATOR_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -400,6 +528,22 @@ pub mod responses { lazy_static! { pub static ref DELETE_FILE_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for DeleteFileEdit + lazy_static! { + pub static ref DELETE_FILE_EDIT_DELETED_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteFileEdit + lazy_static! { + pub static ref DELETE_FILE_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteFileEdit + lazy_static! { + pub static ref DELETE_FILE_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteFileEdit + lazy_static! { + pub static ref DELETE_FILE_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetFile lazy_static! { pub static ref GET_FILE_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -416,6 +560,22 @@ pub mod responses { lazy_static! { pub static ref GET_FILE_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetFileEdit + lazy_static! { + pub static ref GET_FILE_EDIT_FOUND_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileEdit + lazy_static! { + pub static ref GET_FILE_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileEdit + lazy_static! { + pub static ref GET_FILE_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileEdit + lazy_static! { + pub static ref GET_FILE_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetFileHistory lazy_static! { pub static ref GET_FILE_HISTORY_FOUND_ENTITY_HISTORY: Mime = mime!(Application / Json); @@ -432,6 +592,38 @@ pub mod responses { lazy_static! { pub static ref GET_FILE_HISTORY_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetFileRedirects + lazy_static! { + pub static ref GET_FILE_REDIRECTS_FOUND_ENTITY_REDIRECTS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileRedirects + lazy_static! { + pub static ref GET_FILE_REDIRECTS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileRedirects + lazy_static! { + pub static ref GET_FILE_REDIRECTS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileRedirects + lazy_static! { + pub static ref GET_FILE_REDIRECTS_GENERIC_ERROR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileRevision + lazy_static! { + pub static ref GET_FILE_REVISION_FOUND_ENTITY_REVISION: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileRevision + lazy_static! { + pub static ref GET_FILE_REVISION_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileRevision + lazy_static! { + pub static ref GET_FILE_REVISION_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetFileRevision + lazy_static! { + pub static ref GET_FILE_REVISION_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for LookupFile lazy_static! { pub static ref LOOKUP_FILE_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -528,6 +720,22 @@ pub mod responses { lazy_static! { pub static ref DELETE_RELEASE_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for DeleteReleaseEdit + lazy_static! { + pub static ref DELETE_RELEASE_EDIT_DELETED_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteReleaseEdit + lazy_static! { + pub static ref DELETE_RELEASE_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteReleaseEdit + lazy_static! { + pub static ref DELETE_RELEASE_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteReleaseEdit + lazy_static! { + pub static ref DELETE_RELEASE_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetRelease lazy_static! { pub static ref GET_RELEASE_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -544,6 +752,22 @@ pub mod responses { lazy_static! { pub static ref GET_RELEASE_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetReleaseEdit + lazy_static! { + pub static ref GET_RELEASE_EDIT_FOUND_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseEdit + lazy_static! { + pub static ref GET_RELEASE_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseEdit + lazy_static! { + pub static ref GET_RELEASE_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseEdit + lazy_static! { + pub static ref GET_RELEASE_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetReleaseFiles lazy_static! { pub static ref GET_RELEASE_FILES_FOUND: Mime = mime!(Application / Json); @@ -576,6 +800,38 @@ pub mod responses { lazy_static! { pub static ref GET_RELEASE_HISTORY_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetReleaseRedirects + lazy_static! { + pub static ref GET_RELEASE_REDIRECTS_FOUND_ENTITY_REDIRECTS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseRedirects + lazy_static! { + pub static ref GET_RELEASE_REDIRECTS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseRedirects + lazy_static! { + pub static ref GET_RELEASE_REDIRECTS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseRedirects + lazy_static! { + pub static ref GET_RELEASE_REDIRECTS_GENERIC_ERROR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseRevision + lazy_static! { + pub static ref GET_RELEASE_REVISION_FOUND_ENTITY_REVISION: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseRevision + lazy_static! { + pub static ref GET_RELEASE_REVISION_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseRevision + lazy_static! { + pub static ref GET_RELEASE_REVISION_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetReleaseRevision + lazy_static! { + pub static ref GET_RELEASE_REVISION_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for LookupRelease lazy_static! { pub static ref LOOKUP_RELEASE_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -640,6 +896,22 @@ pub mod responses { lazy_static! { pub static ref DELETE_WORK_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for DeleteWorkEdit + lazy_static! { + pub static ref DELETE_WORK_EDIT_DELETED_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteWorkEdit + lazy_static! { + pub static ref DELETE_WORK_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteWorkEdit + lazy_static! { + pub static ref DELETE_WORK_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for DeleteWorkEdit + lazy_static! { + pub static ref DELETE_WORK_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetWork lazy_static! { pub static ref GET_WORK_FOUND_ENTITY: Mime = mime!(Application / Json); @@ -656,6 +928,22 @@ pub mod responses { lazy_static! { pub static ref GET_WORK_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetWorkEdit + lazy_static! { + pub static ref GET_WORK_EDIT_FOUND_EDIT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkEdit + lazy_static! { + pub static ref GET_WORK_EDIT_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkEdit + lazy_static! { + pub static ref GET_WORK_EDIT_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkEdit + lazy_static! { + pub static ref GET_WORK_EDIT_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetWorkHistory lazy_static! { pub static ref GET_WORK_HISTORY_FOUND_ENTITY_HISTORY: Mime = mime!(Application / Json); @@ -672,6 +960,22 @@ pub mod responses { lazy_static! { pub static ref GET_WORK_HISTORY_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetWorkRedirects + lazy_static! { + pub static ref GET_WORK_REDIRECTS_FOUND_ENTITY_REDIRECTS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkRedirects + lazy_static! { + pub static ref GET_WORK_REDIRECTS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkRedirects + lazy_static! { + pub static ref GET_WORK_REDIRECTS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkRedirects + lazy_static! { + pub static ref GET_WORK_REDIRECTS_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetWorkReleases lazy_static! { pub static ref GET_WORK_RELEASES_FOUND: Mime = mime!(Application / Json); @@ -688,6 +992,22 @@ pub mod responses { lazy_static! { pub static ref GET_WORK_RELEASES_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetWorkRevision + lazy_static! { + pub static ref GET_WORK_REVISION_FOUND_ENTITY_REVISION: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkRevision + lazy_static! { + pub static ref GET_WORK_REVISION_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkRevision + lazy_static! { + pub static ref GET_WORK_REVISION_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetWorkRevision + lazy_static! { + pub static ref GET_WORK_REVISION_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for UpdateWork lazy_static! { pub static ref UPDATE_WORK_UPDATED_ENTITY: Mime = mime!(Application / Json); diff --git a/rust/fatcat-api-spec/src/models.rs b/rust/fatcat-api-spec/src/models.rs index 73418c45..6e374746 100644 --- a/rust/fatcat-api-spec/src/models.rs +++ b/rust/fatcat-api-spec/src/models.rs @@ -58,8 +58,10 @@ pub struct ContainerEntity { #[serde(skip_serializing_if = "Option::is_none")] pub publisher: Option, + /// Required for valid entities #[serde(rename = "name")] - pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] @@ -91,14 +93,14 @@ pub struct ContainerEntity { } impl ContainerEntity { - pub fn new(name: String) -> ContainerEntity { + pub fn new() -> ContainerEntity { ContainerEntity { coden: None, abbrev: None, wikidata_qid: None, issnl: None, publisher: None, - name: name, + name: None, edit_extra: None, extra: None, redirect: None, @@ -127,8 +129,10 @@ pub struct CreatorEntity { #[serde(skip_serializing_if = "Option::is_none")] pub given_name: Option, + /// Required for valid entities #[serde(rename = "display_name")] - pub display_name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub display_name: Option, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] @@ -160,13 +164,13 @@ pub struct CreatorEntity { } impl CreatorEntity { - pub fn new(display_name: String) -> CreatorEntity { + pub fn new() -> CreatorEntity { CreatorEntity { wikidata_qid: None, orcid: None, surname: None, given_name: None, - display_name: display_name, + display_name: None, state: None, ident: None, revision: None, @@ -358,14 +362,14 @@ pub struct FileEntity { #[serde(skip_serializing_if = "Option::is_none")] pub sha256: Option, - #[serde(rename = "md5")] - #[serde(skip_serializing_if = "Option::is_none")] - pub md5: Option, - #[serde(rename = "sha1")] #[serde(skip_serializing_if = "Option::is_none")] pub sha1: Option, + #[serde(rename = "md5")] + #[serde(skip_serializing_if = "Option::is_none")] + pub md5: Option, + #[serde(rename = "size")] #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, @@ -406,8 +410,8 @@ impl FileEntity { mimetype: None, urls: None, sha256: None, - md5: None, sha1: None, + md5: None, size: None, edit_extra: None, extra: None, @@ -564,8 +568,10 @@ pub struct ReleaseEntity { #[serde(skip_serializing_if = "Option::is_none")] pub work_id: Option, + /// Required for valid entities #[serde(rename = "title")] - pub title: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub title: Option, // Note: inline enums are not fully supported by swagger-codegen #[serde(rename = "state")] @@ -597,7 +603,7 @@ pub struct ReleaseEntity { } impl ReleaseEntity { - pub fn new(title: String) -> ReleaseEntity { + pub fn new() -> ReleaseEntity { ReleaseEntity { abstracts: None, refs: None, @@ -620,7 +626,7 @@ impl ReleaseEntity { files: None, container: None, work_id: None, - title: title, + title: None, state: None, ident: None, revision: None, diff --git a/rust/fatcat-api-spec/src/server.rs b/rust/fatcat-api-spec/src/server.rs index c4f491de..e8d8e1eb 100644 --- a/rust/fatcat-api-spec/src/server.rs +++ b/rust/fatcat-api-spec/src/server.rs @@ -38,11 +38,14 @@ use swagger::{ApiError, Context, XSpanId}; use models; use { AcceptEditgroupResponse, Api, CreateContainerBatchResponse, CreateContainerResponse, CreateCreatorBatchResponse, CreateCreatorResponse, CreateEditgroupResponse, CreateFileBatchResponse, - CreateFileResponse, CreateReleaseBatchResponse, CreateReleaseResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerResponse, DeleteCreatorResponse, DeleteFileResponse, - DeleteReleaseResponse, DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, GetContainerHistoryResponse, GetContainerResponse, GetCreatorHistoryResponse, - GetCreatorReleasesResponse, GetCreatorResponse, GetEditgroupResponse, GetEditorChangelogResponse, GetEditorResponse, GetFileHistoryResponse, GetFileResponse, GetReleaseFilesResponse, - GetReleaseHistoryResponse, GetReleaseResponse, GetStatsResponse, GetWorkHistoryResponse, GetWorkReleasesResponse, GetWorkResponse, LookupContainerResponse, LookupCreatorResponse, - LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateFileResponse, UpdateReleaseResponse, UpdateWorkResponse, + CreateFileResponse, CreateReleaseBatchResponse, CreateReleaseResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, + DeleteCreatorEditResponse, DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, DeleteWorkEditResponse, DeleteWorkResponse, + GetChangelogEntryResponse, GetChangelogResponse, GetContainerEditResponse, GetContainerHistoryResponse, GetContainerRedirectsResponse, GetContainerResponse, GetContainerRevisionResponse, + GetCreatorEditResponse, GetCreatorHistoryResponse, GetCreatorRedirectsResponse, GetCreatorReleasesResponse, GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupResponse, + GetEditorChangelogResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetReleaseEditResponse, + GetReleaseFilesResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, GetStatsResponse, GetWorkEditResponse, GetWorkHistoryResponse, + GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, + UpdateContainerResponse, UpdateCreatorResponse, UpdateFileResponse, UpdateReleaseResponse, UpdateWorkResponse, }; header! { (Warning, "Warning") => [String] } @@ -405,8 +408,8 @@ where ); let api_clone = api.clone(); - router.get( - "/v0/container/:id", + router.delete( + "/v0/container/edit/:edit_id", move |req: &mut Request| { let mut context = Context::default(); @@ -420,62 +423,57 @@ where context.authorization = req.extensions.remove::(); // Path parameters - let param_id = { + let param_edit_id = { let param = req .extensions .get::() .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; percent_decode(param.as_bytes()) .decode_utf8() .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - match api.get_container(param_id, param_expand, param_hide, context).wait() { + match api.delete_container_edit(param_edit_id, context).wait() { Ok(rsp) => match rsp { - GetContainerResponse::FoundEntity(body) => { + DeleteContainerEditResponse::DeletedEdit(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::GET_CONTAINER_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CONTAINER_EDIT_DELETED_EDIT.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetContainerResponse::BadRequest(body) => { + DeleteContainerEditResponse::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::GET_CONTAINER_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CONTAINER_EDIT_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetContainerResponse::NotFound(body) => { + DeleteContainerEditResponse::NotFound(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::GET_CONTAINER_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CONTAINER_EDIT_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetContainerResponse::GenericError(body) => { + DeleteContainerEditResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CONTAINER_EDIT_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -495,12 +493,12 @@ where Ok(response) }) }, - "GetContainer", + "DeleteContainerEdit", ); let api_clone = api.clone(); router.get( - "/v0/container/:id/history", + "/v0/container/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -530,45 +528,46 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_container_history(param_id, param_limit, context).wait() { + match api.get_container(param_id, param_expand, param_hide, context).wait() { Ok(rsp) => match rsp { - GetContainerHistoryResponse::FoundEntityHistory(body) => { + GetContainerResponse::FoundEntity(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::GET_CONTAINER_HISTORY_FOUND_ENTITY_HISTORY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetContainerHistoryResponse::BadRequest(body) => { + GetContainerResponse::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::GET_CONTAINER_HISTORY_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetContainerHistoryResponse::NotFound(body) => { + GetContainerResponse::NotFound(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::GET_CONTAINER_HISTORY_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetContainerHistoryResponse::GenericError(body) => { + GetContainerResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_HISTORY_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -588,12 +587,12 @@ where Ok(response) }) }, - "GetContainerHistory", + "GetContainer", ); let api_clone = api.clone(); router.get( - "/v0/container/lookup", + "/v0/container/edit/:edit_id", move |req: &mut Request| { let mut context = Context::default(); @@ -606,54 +605,58 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_issnl = query_params - .get("issnl") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter issnl".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issnl was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter issnl - doesn't match schema: {}", e))))?; - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + // Path parameters + let param_edit_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? + }; - match api.lookup_container(param_issnl, param_hide, context).wait() { + match api.get_container_edit(param_edit_id, context).wait() { Ok(rsp) => match rsp { - LookupContainerResponse::FoundEntity(body) => { + GetContainerEditResponse::FoundEdit(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::LOOKUP_CONTAINER_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_EDIT_FOUND_EDIT.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupContainerResponse::BadRequest(body) => { + GetContainerEditResponse::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::LOOKUP_CONTAINER_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_EDIT_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupContainerResponse::NotFound(body) => { + GetContainerEditResponse::NotFound(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::LOOKUP_CONTAINER_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_EDIT_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupContainerResponse::GenericError(body) => { + GetContainerEditResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_EDIT_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -673,12 +676,12 @@ where Ok(response) }) }, - "LookupContainer", + "GetContainerEdit", ); let api_clone = api.clone(); - router.put( - "/v0/container/:id", + router.get( + "/v0/container/:id/history", move |req: &mut Request| { let mut context = Context::default(); @@ -708,80 +711,48 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - - param_entity - } else { - None - }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.update_container(param_id, param_entity, param_editgroup, context).wait() { + match api.get_container_history(param_id, param_limit, context).wait() { Ok(rsp) => match rsp { - UpdateContainerResponse::UpdatedEntity(body) => { + GetContainerHistoryResponse::FoundEntityHistory(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::UPDATE_CONTAINER_UPDATED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_HISTORY_FOUND_ENTITY_HISTORY.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))); - } + Ok(response) } - UpdateContainerResponse::BadRequest(body) => { + GetContainerHistoryResponse::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::UPDATE_CONTAINER_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_HISTORY_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))); - } + Ok(response) } - UpdateContainerResponse::NotFound(body) => { + GetContainerHistoryResponse::NotFound(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::UPDATE_CONTAINER_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_HISTORY_NOT_FOUND.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))); - } + Ok(response) } - UpdateContainerResponse::GenericError(body) => { + GetContainerHistoryResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::UPDATE_CONTAINER_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_HISTORY_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -798,12 +769,12 @@ where Ok(response) }) }, - "UpdateContainer", + "GetContainerHistory", ); let api_clone = api.clone(); - router.post( - "/v0/creator", + router.get( + "/v0/container/:id/redirects", move |req: &mut Request| { let mut context = Context::default(); @@ -816,82 +787,61 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - - param_entity - } else { - None + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.create_creator(param_entity, param_editgroup, context).wait() { + match api.get_container_redirects(param_id, context).wait() { Ok(rsp) => match rsp { - CreateCreatorResponse::CreatedEntity(body) => { + GetContainerRedirectsResponse::FoundEntityRedirects(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::CREATE_CREATOR_CREATED_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REDIRECTS_FOUND_ENTITY_REDIRECTS.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))); - } + Ok(response) } - CreateCreatorResponse::BadRequest(body) => { + GetContainerRedirectsResponse::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::CREATE_CREATOR_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REDIRECTS_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))); - } + Ok(response) } - CreateCreatorResponse::NotFound(body) => { + GetContainerRedirectsResponse::NotFound(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::CREATE_CREATOR_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REDIRECTS_NOT_FOUND.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))); - } + Ok(response) } - CreateCreatorResponse::GenericError(body) => { + GetContainerRedirectsResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REDIRECTS_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -908,12 +858,12 @@ where Ok(response) }) }, - "CreateCreator", + "GetContainerRedirects", ); let api_clone = api.clone(); - router.post( - "/v0/creator/batch", + router.get( + "/v0/container/rev/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -926,83 +876,66 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. + match api.get_container_revision(param_id, param_expand, param_hide, context).wait() { + Ok(rsp) => match rsp { + GetContainerRevisionResponse::FoundEntityRevision(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let param_entity_list = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REVISION_FOUND_ENTITY_REVISION.clone())); - let mut unused_elements = Vec::new(); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); + Ok(response) + } + GetContainerRevisionResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + let mut response = Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REVISION_BAD_REQUEST.clone())); - param_entity_list - } else { - None - }; - let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - match api.create_creator_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { - Ok(rsp) => match rsp { - CreateCreatorBatchResponse::CreatedEntities(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::CREATE_CREATOR_BATCH_CREATED_ENTITIES.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))); - } - Ok(response) - } - CreateCreatorBatchResponse::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::CREATE_CREATOR_BATCH_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))); - } Ok(response) } - CreateCreatorBatchResponse::NotFound(body) => { + GetContainerRevisionResponse::NotFound(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::CREATE_CREATOR_BATCH_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REVISION_NOT_FOUND.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))); - } + Ok(response) } - CreateCreatorBatchResponse::GenericError(body) => { + GetContainerRevisionResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_REVISION_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -1019,12 +952,12 @@ where Ok(response) }) }, - "CreateCreatorBatch", + "GetContainerRevision", ); let api_clone = api.clone(); - router.delete( - "/v0/creator/:id", + router.get( + "/v0/container/lookup", move |req: &mut Request| { let mut context = Context::default(); @@ -1037,62 +970,49 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_issnl = query_params.get("issnl").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_wikidata_qid = query_params.get("wikidata_qid").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.delete_creator(param_id, param_editgroup, context).wait() { + match api.lookup_container(param_issnl, param_wikidata_qid, param_hide, context).wait() { Ok(rsp) => match rsp { - DeleteCreatorResponse::DeletedEntity(body) => { + LookupContainerResponse::FoundEntity(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::DELETE_CREATOR_DELETED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteCreatorResponse::BadRequest(body) => { + LookupContainerResponse::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::DELETE_CREATOR_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteCreatorResponse::NotFound(body) => { + LookupContainerResponse::NotFound(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::DELETE_CREATOR_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteCreatorResponse::GenericError(body) => { + LookupContainerResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1112,12 +1032,12 @@ where Ok(response) }) }, - "DeleteCreator", + "LookupContainer", ); let api_clone = api.clone(); - router.get( - "/v0/creator/:id", + router.put( + "/v0/container/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -1147,49 +1067,80 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_creator(param_id, param_expand, param_hide, context).wait() { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + + param_entity + } else { + None + }; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + + match api.update_container(param_id, param_entity, param_editgroup, context).wait() { Ok(rsp) => match rsp { - GetCreatorResponse::FoundEntity(body) => { + UpdateContainerResponse::UpdatedEntity(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::GET_CREATOR_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CONTAINER_UPDATED_ENTITY.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))); + } Ok(response) } - GetCreatorResponse::BadRequest(body) => { + UpdateContainerResponse::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::GET_CREATOR_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CONTAINER_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))); + } Ok(response) } - GetCreatorResponse::NotFound(body) => { + UpdateContainerResponse::NotFound(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::GET_CREATOR_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CONTAINER_NOT_FOUND.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))); + } Ok(response) } - GetCreatorResponse::GenericError(body) => { + UpdateContainerResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CONTAINER_GENERIC_ERROR.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))); + } Ok(response) } }, @@ -1206,12 +1157,12 @@ where Ok(response) }) }, - "GetCreator", + "UpdateContainer", ); let api_clone = api.clone(); - router.get( - "/v0/creator/:id/history", + router.post( + "/v0/creator", move |req: &mut Request| { let mut context = Context::default(); @@ -1224,65 +1175,82 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_creator_history(param_id, param_limit, context).wait() { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + + param_entity + } else { + None + }; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + + match api.create_creator(param_entity, param_editgroup, context).wait() { Ok(rsp) => match rsp { - GetCreatorHistoryResponse::FoundEntityHistory(body) => { + CreateCreatorResponse::CreatedEntity(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::GET_CREATOR_HISTORY_FOUND_ENTITY_HISTORY.clone())); + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_CREATED_ENTITY.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))); + } Ok(response) } - GetCreatorHistoryResponse::BadRequest(body) => { + CreateCreatorResponse::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::GET_CREATOR_HISTORY_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_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))); + } Ok(response) } - GetCreatorHistoryResponse::NotFound(body) => { + CreateCreatorResponse::NotFound(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::GET_CREATOR_HISTORY_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_NOT_FOUND.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))); + } Ok(response) } - GetCreatorHistoryResponse::GenericError(body) => { + CreateCreatorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_HISTORY_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_GENERIC_ERROR.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))); + } Ok(response) } }, @@ -1299,12 +1267,12 @@ where Ok(response) }) }, - "GetCreatorHistory", + "CreateCreator", ); let api_clone = api.clone(); - router.get( - "/v0/creator/:id/releases", + router.post( + "/v0/creator/batch", move |req: &mut Request| { let mut context = Context::default(); @@ -1317,65 +1285,83 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_creator_releases(param_id, param_hide, context).wait() { - Ok(rsp) => match rsp { - GetCreatorReleasesResponse::Found(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_RELEASES_FOUND.clone())); + let param_entity_list = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let mut unused_elements = Vec::new(); + + let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); + + let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + + param_entity_list + } else { + None + }; + let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; + + match api.create_creator_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + CreateCreatorBatchResponse::CreatedEntities(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::CREATE_CREATOR_BATCH_CREATED_ENTITIES.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))); + } Ok(response) } - GetCreatorReleasesResponse::BadRequest(body) => { + CreateCreatorBatchResponse::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::GET_CREATOR_RELEASES_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_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))); + } Ok(response) } - GetCreatorReleasesResponse::NotFound(body) => { + CreateCreatorBatchResponse::NotFound(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::GET_CREATOR_RELEASES_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_NOT_FOUND.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))); + } Ok(response) } - GetCreatorReleasesResponse::GenericError(body) => { + CreateCreatorBatchResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_RELEASES_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_GENERIC_ERROR.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))); + } Ok(response) } }, @@ -1392,12 +1378,12 @@ where Ok(response) }) }, - "GetCreatorReleases", + "CreateCreatorBatch", ); let api_clone = api.clone(); - router.get( - "/v0/creator/lookup", + router.delete( + "/v0/creator/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -1410,54 +1396,62 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_orcid = query_params - .get("orcid") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter orcid".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter orcid was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter orcid - doesn't match schema: {}", e))))?; - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.lookup_creator(param_orcid, param_hide, context).wait() { + match api.delete_creator(param_id, param_editgroup, context).wait() { Ok(rsp) => match rsp { - LookupCreatorResponse::FoundEntity(body) => { + DeleteCreatorResponse::DeletedEntity(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::LOOKUP_CREATOR_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_DELETED_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupCreatorResponse::BadRequest(body) => { + DeleteCreatorResponse::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::LOOKUP_CREATOR_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupCreatorResponse::NotFound(body) => { + DeleteCreatorResponse::NotFound(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::LOOKUP_CREATOR_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupCreatorResponse::GenericError(body) => { + DeleteCreatorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::LOOKUP_CREATOR_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1477,12 +1471,12 @@ where Ok(response) }) }, - "LookupCreator", + "DeleteCreator", ); let api_clone = api.clone(); - router.put( - "/v0/creator/:id", + router.delete( + "/v0/creator/edit/:edit_id", move |req: &mut Request| { let mut context = Context::default(); @@ -1496,96 +1490,60 @@ where context.authorization = req.extensions.remove::(); // Path parameters - let param_id = { + let param_edit_id = { let param = req .extensions .get::() .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; percent_decode(param.as_bytes()) .decode_utf8() .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; - - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - - param_entity - } else { - None + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.update_creator(param_id, param_entity, param_editgroup, context).wait() { + match api.delete_creator_edit(param_edit_id, context).wait() { Ok(rsp) => match rsp { - UpdateCreatorResponse::UpdatedEntity(body) => { + DeleteCreatorEditResponse::DeletedEdit(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::UPDATE_CREATOR_UPDATED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_EDIT_DELETED_EDIT.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))); - } + Ok(response) } - UpdateCreatorResponse::BadRequest(body) => { + DeleteCreatorEditResponse::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::UPDATE_CREATOR_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_EDIT_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))); - } + Ok(response) } - UpdateCreatorResponse::NotFound(body) => { + DeleteCreatorEditResponse::NotFound(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::UPDATE_CREATOR_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_EDIT_NOT_FOUND.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))); - } + Ok(response) } - UpdateCreatorResponse::GenericError(body) => { + DeleteCreatorEditResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::UPDATE_CREATOR_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_CREATOR_EDIT_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -1602,12 +1560,12 @@ where Ok(response) }) }, - "UpdateCreator", + "DeleteCreatorEdit", ); let api_clone = api.clone(); router.get( - "/v0/editor/:id", + "/v0/creator/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -1635,43 +1593,48 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - match api.get_editor(param_id, context).wait() { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_creator(param_id, param_expand, param_hide, context).wait() { Ok(rsp) => match rsp { - GetEditorResponse::Found(body) => { + GetCreatorResponse::FoundEntity(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::GET_EDITOR_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorResponse::BadRequest(body) => { + GetCreatorResponse::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::GET_EDITOR_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorResponse::NotFound(body) => { + GetCreatorResponse::NotFound(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::GET_EDITOR_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorResponse::GenericError(body) => { + GetCreatorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1691,12 +1654,12 @@ where Ok(response) }) }, - "GetEditor", + "GetCreator", ); let api_clone = api.clone(); router.get( - "/v0/editor/:id/changelog", + "/v0/creator/edit/:edit_id", move |req: &mut Request| { let mut context = Context::default(); @@ -1710,57 +1673,57 @@ where context.authorization = req.extensions.remove::(); // Path parameters - let param_id = { + let param_edit_id = { let param = req .extensions .get::() .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; percent_decode(param.as_bytes()) .decode_utf8() .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? }; - match api.get_editor_changelog(param_id, context).wait() { + match api.get_creator_edit(param_edit_id, context).wait() { Ok(rsp) => match rsp { - GetEditorChangelogResponse::Found(body) => { + GetCreatorEditResponse::FoundEdit(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::GET_EDITOR_CHANGELOG_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_EDIT_FOUND_EDIT.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorChangelogResponse::BadRequest(body) => { + GetCreatorEditResponse::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::GET_EDITOR_CHANGELOG_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_EDIT_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorChangelogResponse::NotFound(body) => { + GetCreatorEditResponse::NotFound(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::GET_EDITOR_CHANGELOG_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_EDIT_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorChangelogResponse::GenericError(body) => { + GetCreatorEditResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_EDIT_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1780,12 +1743,12 @@ where Ok(response) }) }, - "GetEditorChangelog", + "GetCreatorEdit", ); let api_clone = api.clone(); router.get( - "/v0/stats", + "/v0/creator/:id/history", move |req: &mut Request| { let mut context = Context::default(); @@ -1798,27 +1761,62 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_more = query_params.get("more").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_stats(param_more, context).wait() { + match api.get_creator_history(param_id, param_limit, context).wait() { Ok(rsp) => match rsp { - GetStatsResponse::Success(body) => { + GetCreatorHistoryResponse::FoundEntityHistory(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::GET_STATS_SUCCESS.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_HISTORY_FOUND_ENTITY_HISTORY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetStatsResponse::GenericError(body) => { + GetCreatorHistoryResponse::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::GET_CREATOR_HISTORY_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetCreatorHistoryResponse::NotFound(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::GET_CREATOR_HISTORY_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetCreatorHistoryResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_STATS_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_HISTORY_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1838,12 +1836,12 @@ where Ok(response) }) }, - "GetStats", + "GetCreatorHistory", ); let api_clone = api.clone(); - router.post( - "/v0/editgroup/:id/accept", + router.get( + "/v0/creator/:id/redirects", move |req: &mut Request| { let mut context = Context::default(); @@ -1871,53 +1869,43 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - match api.accept_editgroup(param_id, context).wait() { + match api.get_creator_redirects(param_id, context).wait() { Ok(rsp) => match rsp { - AcceptEditgroupResponse::MergedSuccessfully(body) => { + GetCreatorRedirectsResponse::FoundEntityRedirects(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::ACCEPT_EDITGROUP_MERGED_SUCCESSFULLY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_REDIRECTS_FOUND_ENTITY_REDIRECTS.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - AcceptEditgroupResponse::BadRequest(body) => { + GetCreatorRedirectsResponse::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::ACCEPT_EDITGROUP_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_REDIRECTS_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - AcceptEditgroupResponse::NotFound(body) => { + GetCreatorRedirectsResponse::NotFound(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::ACCEPT_EDITGROUP_NOT_FOUND.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - AcceptEditgroupResponse::EditConflict(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(409), body_string)); - response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_EDIT_CONFLICT.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_REDIRECTS_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - AcceptEditgroupResponse::GenericError(body) => { + GetCreatorRedirectsResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_REDIRECTS_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1937,12 +1925,12 @@ where Ok(response) }) }, - "AcceptEditgroup", + "GetCreatorRedirects", ); let api_clone = api.clone(); - router.post( - "/v0/editgroup", + router.get( + "/v0/creator/:id/releases", move |req: &mut Request| { let mut context = Context::default(); @@ -1955,121 +1943,62 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_editgroup = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editgroup - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_editgroup = if let Some(param_editgroup_raw) = param_editgroup { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_editgroup_raw); - - let param_editgroup: Option = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editgroup - doesn't match schema: {}", e))))?; - - param_editgroup - } else { - None + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_editgroup = param_editgroup.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter editgroup".to_string())))?; - match api.create_editgroup(param_editgroup, context).wait() { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_creator_releases(param_id, param_hide, context).wait() { Ok(rsp) => match rsp { - CreateEditgroupResponse::SuccessfullyCreated(body) => { + GetCreatorReleasesResponse::Found(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::CREATE_EDITGROUP_SUCCESSFULLY_CREATED.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_RELEASES_FOUND.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))); - } + Ok(response) } - CreateEditgroupResponse::BadRequest(body) => { + GetCreatorReleasesResponse::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::CREATE_EDITGROUP_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_RELEASES_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))); - } - Ok(response) - } - CreateEditgroupResponse::GenericError(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_GENERIC_ERROR.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))); - } 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()))) - } - } - } - - 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()))); - Ok(response) - }) - }, - "CreateEditgroup", - ); - - let api_clone = api.clone(); - router.get( - "/v0/changelog", - move |req: &mut Request| { - let mut context = Context::default(); - - // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result - where - T: Api, - { - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); - context.auth_data = req.extensions.remove::(); - context.authorization = req.extensions.remove::(); - - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - match api.get_changelog(param_limit, context).wait() { - Ok(rsp) => match rsp { - GetChangelogResponse::Success(body) => { + GetCreatorReleasesResponse::NotFound(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::GET_CHANGELOG_SUCCESS.clone())); + let mut response = Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_RELEASES_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetChangelogResponse::GenericError(body) => { + GetCreatorReleasesResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_RELEASES_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -2089,12 +2018,12 @@ where Ok(response) }) }, - "GetChangelog", + "GetCreatorReleases", ); let api_clone = api.clone(); router.get( - "/v0/changelog/:id", + "/v0/creator/rev/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -2122,33 +2051,48 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - match api.get_changelog_entry(param_id, context).wait() { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_creator_revision(param_id, param_expand, param_hide, context).wait() { Ok(rsp) => match rsp { - GetChangelogEntryResponse::FoundChangelogEntry(body) => { + GetCreatorRevisionResponse::FoundEntityRevision(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::GET_CHANGELOG_ENTRY_FOUND_CHANGELOG_ENTRY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_REVISION_FOUND_ENTITY_REVISION.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetChangelogEntryResponse::NotFound(body) => { + GetCreatorRevisionResponse::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::GET_CREATOR_REVISION_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetCreatorRevisionResponse::NotFound(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::GET_CHANGELOG_ENTRY_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_REVISION_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetChangelogEntryResponse::GenericError(body) => { + GetCreatorRevisionResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_ENTRY_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_REVISION_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -2168,12 +2112,12 @@ where Ok(response) }) }, - "GetChangelogEntry", + "GetCreatorRevision", ); let api_clone = api.clone(); router.get( - "/v0/editgroup/:id", + "/v0/creator/lookup", move |req: &mut Request| { let mut context = Context::default(); @@ -2186,58 +2130,49 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_orcid = query_params.get("orcid").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_wikidata_qid = query_params.get("wikidata_qid").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_editgroup(param_id, context).wait() { + match api.lookup_creator(param_orcid, param_wikidata_qid, param_hide, context).wait() { Ok(rsp) => match rsp { - GetEditgroupResponse::Found(body) => { + LookupCreatorResponse::FoundEntity(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::GET_EDITGROUP_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CREATOR_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditgroupResponse::BadRequest(body) => { + LookupCreatorResponse::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::GET_EDITGROUP_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CREATOR_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditgroupResponse::NotFound(body) => { + LookupCreatorResponse::NotFound(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::GET_EDITGROUP_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CREATOR_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditgroupResponse::GenericError(body) => { + LookupCreatorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CREATOR_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -2257,12 +2192,12 @@ where Ok(response) }) }, - "GetEditgroup", + "LookupCreator", ); let api_clone = api.clone(); - router.post( - "/v0/file", + router.put( + "/v0/creator/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -2275,6 +2210,21 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); @@ -2292,7 +2242,7 @@ where let param_entity = if let Some(param_entity_raw) = param_entity { let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; @@ -2303,13 +2253,13 @@ where }; let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.create_file(param_entity, param_editgroup, context).wait() { + match api.update_creator(param_id, param_entity, param_editgroup, context).wait() { Ok(rsp) => match rsp { - CreateFileResponse::CreatedEntity(body) => { + UpdateCreatorResponse::UpdatedEntity(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::CREATE_FILE_CREATED_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CREATOR_UPDATED_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -2317,11 +2267,11 @@ where } Ok(response) } - CreateFileResponse::BadRequest(body) => { + UpdateCreatorResponse::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::CREATE_FILE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CREATOR_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -2329,11 +2279,11 @@ where } Ok(response) } - CreateFileResponse::NotFound(body) => { + UpdateCreatorResponse::NotFound(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::CREATE_FILE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CREATOR_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -2341,11 +2291,11 @@ where } Ok(response) } - CreateFileResponse::GenericError(body) => { + UpdateCreatorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CREATOR_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -2367,12 +2317,12 @@ where Ok(response) }) }, - "CreateFile", + "UpdateCreator", ); let api_clone = api.clone(); - router.post( - "/v0/file/batch", + router.get( + "/v0/editor/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -2385,83 +2335,61 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity_list = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - - let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; - - param_entity_list - } else { - None + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.create_file_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { + match api.get_editor(param_id, context).wait() { Ok(rsp) => match rsp { - CreateFileBatchResponse::CreatedEntities(body) => { + GetEditorResponse::Found(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::CREATE_FILE_BATCH_CREATED_ENTITIES.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_FOUND.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))); - } + Ok(response) } - CreateFileBatchResponse::BadRequest(body) => { + GetEditorResponse::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::CREATE_FILE_BATCH_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_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))); - } + Ok(response) } - CreateFileBatchResponse::NotFound(body) => { + GetEditorResponse::NotFound(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::CREATE_FILE_BATCH_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_NOT_FOUND.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))); - } + Ok(response) } - CreateFileBatchResponse::GenericError(body) => { + GetEditorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -2478,12 +2406,12 @@ where Ok(response) }) }, - "CreateFileBatch", + "GetEditor", ); let api_clone = api.clone(); - router.delete( - "/v0/file/:id", + router.get( + "/v0/editor/:id/changelog", move |req: &mut Request| { let mut context = Context::default(); @@ -2511,47 +2439,43 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - match api.delete_file(param_id, param_editgroup, context).wait() { + match api.get_editor_changelog(param_id, context).wait() { Ok(rsp) => match rsp { - DeleteFileResponse::DeletedEntity(body) => { + GetEditorChangelogResponse::Found(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::DELETE_FILE_DELETED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteFileResponse::BadRequest(body) => { + GetEditorChangelogResponse::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::DELETE_FILE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteFileResponse::NotFound(body) => { + GetEditorChangelogResponse::NotFound(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::DELETE_FILE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteFileResponse::GenericError(body) => { + GetEditorChangelogResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::DELETE_FILE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -2571,12 +2495,12 @@ where Ok(response) }) }, - "DeleteFile", + "GetEditorChangelog", ); let api_clone = api.clone(); router.get( - "/v0/file/:id", + "/v0/stats", move |req: &mut Request| { let mut context = Context::default(); @@ -2589,63 +2513,27 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_more = query_params.get("more").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_file(param_id, param_expand, param_hide, context).wait() { + match api.get_stats(param_more, context).wait() { Ok(rsp) => match rsp { - GetFileResponse::FoundEntity(body) => { + GetStatsResponse::Success(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::GET_FILE_FOUND_ENTITY.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - GetFileResponse::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::GET_FILE_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - GetFileResponse::NotFound(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::GET_FILE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_STATS_SUCCESS.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetFileResponse::GenericError(body) => { + GetStatsResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_FILE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_STATS_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -2665,12 +2553,12 @@ where Ok(response) }) }, - "GetFile", + "GetStats", ); let api_clone = api.clone(); - router.get( - "/v0/file/:id/history", + router.post( + "/v0/editgroup/:id/accept", move |req: &mut Request| { let mut context = Context::default(); @@ -2698,47 +2586,53 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - match api.get_file_history(param_id, param_limit, context).wait() { + match api.accept_editgroup(param_id, context).wait() { Ok(rsp) => match rsp { - GetFileHistoryResponse::FoundEntityHistory(body) => { + AcceptEditgroupResponse::MergedSuccessfully(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::GET_FILE_HISTORY_FOUND_ENTITY_HISTORY.clone())); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_MERGED_SUCCESSFULLY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetFileHistoryResponse::BadRequest(body) => { + AcceptEditgroupResponse::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::GET_FILE_HISTORY_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetFileHistoryResponse::NotFound(body) => { + AcceptEditgroupResponse::NotFound(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::GET_FILE_HISTORY_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetFileHistoryResponse::GenericError(body) => { + AcceptEditgroupResponse::EditConflict(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(409), body_string)); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_EDIT_CONFLICT.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + AcceptEditgroupResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_FILE_HISTORY_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -2758,12 +2652,12 @@ where Ok(response) }) }, - "GetFileHistory", + "AcceptEditgroup", ); let api_clone = api.clone(); - router.get( - "/v0/file/lookup", + router.post( + "/v0/editgroup", move |req: &mut Request| { let mut context = Context::default(); @@ -2776,57 +2670,66 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_sha1 = query_params - .get("sha1") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter sha1".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter sha1 was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter sha1 - doesn't match schema: {}", e))))?; - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. - match api.lookup_file(param_sha1, param_hide, context).wait() { - Ok(rsp) => match rsp { - LookupFileResponse::FoundEntity(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let param_editgroup = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editgroup - not valid UTF-8: {}", e))))?; - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_FOUND_ENTITY.clone())); + let mut unused_elements = Vec::new(); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let param_editgroup = if let Some(param_editgroup_raw) = param_editgroup { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_editgroup_raw); - Ok(response) - } - LookupFileResponse::BadRequest(body) => { + let param_editgroup: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editgroup - doesn't match schema: {}", e))))?; + + param_editgroup + } else { + None + }; + let param_editgroup = param_editgroup.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter editgroup".to_string())))?; + + match api.create_editgroup(param_editgroup, context).wait() { + Ok(rsp) => match rsp { + CreateEditgroupResponse::SuccessfullyCreated(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::LOOKUP_FILE_BAD_REQUEST.clone())); + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_SUCCESSFULLY_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))); + } Ok(response) } - LookupFileResponse::NotFound(body) => { + CreateEditgroupResponse::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(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_NOT_FOUND.clone())); + let mut response = Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_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))); + } Ok(response) } - LookupFileResponse::GenericError(body) => { + CreateEditgroupResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_GENERIC_ERROR.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))); + } Ok(response) } }, @@ -2843,12 +2746,70 @@ where Ok(response) }) }, - "LookupFile", + "CreateEditgroup", ); let api_clone = api.clone(); - router.put( - "/v0/file/:id", + router.get( + "/v0/changelog", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_changelog(param_limit, context).wait() { + Ok(rsp) => match rsp { + GetChangelogResponse::Success(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::GET_CHANGELOG_SUCCESS.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetChangelogResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetChangelog", + ); + + let api_clone = api.clone(); + router.get( + "/v0/changelog/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -2876,82 +2837,125 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + match api.get_changelog_entry(param_id, context).wait() { + Ok(rsp) => match rsp { + GetChangelogEntryResponse::FoundChangelogEntry(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_ENTRY_FOUND_CHANGELOG_ENTRY.clone())); - let param_entity = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - let mut unused_elements = Vec::new(); + Ok(response) + } + GetChangelogEntryResponse::NotFound(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + let mut response = Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_ENTRY_NOT_FOUND.clone())); - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - param_entity - } else { - None + Ok(response) + } + GetChangelogEntryResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_ENTRY_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetChangelogEntry", + ); + + let api_clone = api.clone(); + router.get( + "/v0/editgroup/:id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.update_file(param_id, param_entity, param_editgroup, context).wait() { + match api.get_editgroup(param_id, context).wait() { Ok(rsp) => match rsp { - UpdateFileResponse::UpdatedEntity(body) => { + GetEditgroupResponse::Found(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::UPDATE_FILE_UPDATED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_FOUND.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))); - } + Ok(response) } - UpdateFileResponse::BadRequest(body) => { + GetEditgroupResponse::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::UPDATE_FILE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_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))); - } + Ok(response) } - UpdateFileResponse::NotFound(body) => { + GetEditgroupResponse::NotFound(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::UPDATE_FILE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_NOT_FOUND.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))); - } + Ok(response) } - UpdateFileResponse::GenericError(body) => { + GetEditgroupResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::UPDATE_FILE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -2968,12 +2972,12 @@ where Ok(response) }) }, - "UpdateFile", + "GetEditgroup", ); let api_clone = api.clone(); router.post( - "/v0/release", + "/v0/file", move |req: &mut Request| { let mut context = Context::default(); @@ -3003,7 +3007,7 @@ where let param_entity = if let Some(param_entity_raw) = param_entity { let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; @@ -3014,13 +3018,13 @@ where }; let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.create_release(param_entity, param_editgroup, context).wait() { + match api.create_file(param_entity, param_editgroup, context).wait() { Ok(rsp) => match rsp { - CreateReleaseResponse::CreatedEntity(body) => { + CreateFileResponse::CreatedEntity(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::CREATE_RELEASE_CREATED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_CREATED_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3028,11 +3032,11 @@ where } Ok(response) } - CreateReleaseResponse::BadRequest(body) => { + CreateFileResponse::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::CREATE_RELEASE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3040,11 +3044,11 @@ where } Ok(response) } - CreateReleaseResponse::NotFound(body) => { + CreateFileResponse::NotFound(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::CREATE_RELEASE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3052,11 +3056,11 @@ where } Ok(response) } - CreateReleaseResponse::GenericError(body) => { + CreateFileResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3078,12 +3082,12 @@ where Ok(response) }) }, - "CreateRelease", + "CreateFile", ); let api_clone = api.clone(); router.post( - "/v0/release/batch", + "/v0/file/batch", move |req: &mut Request| { let mut context = Context::default(); @@ -3114,7 +3118,7 @@ where let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { + let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; @@ -3125,13 +3129,13 @@ where }; let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.create_release_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { + match api.create_file_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { Ok(rsp) => match rsp { - CreateReleaseBatchResponse::CreatedEntities(body) => { + CreateFileBatchResponse::CreatedEntities(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::CREATE_RELEASE_BATCH_CREATED_ENTITIES.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_CREATED_ENTITIES.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3139,11 +3143,11 @@ where } Ok(response) } - CreateReleaseBatchResponse::BadRequest(body) => { + CreateFileBatchResponse::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::CREATE_RELEASE_BATCH_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3151,11 +3155,11 @@ where } Ok(response) } - CreateReleaseBatchResponse::NotFound(body) => { + CreateFileBatchResponse::NotFound(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::CREATE_RELEASE_BATCH_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3163,11 +3167,11 @@ where } Ok(response) } - CreateReleaseBatchResponse::GenericError(body) => { + CreateFileBatchResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_BATCH_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -3189,12 +3193,1080 @@ where Ok(response) }) }, - "CreateReleaseBatch", + "CreateFileBatch", ); let api_clone = api.clone(); - router.post( - "/v0/work", + router.delete( + "/v0/file/:id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.delete_file(param_id, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + DeleteFileResponse::DeletedEntity(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::DELETE_FILE_DELETED_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteFileResponse::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::DELETE_FILE_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteFileResponse::NotFound(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::DELETE_FILE_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteFileResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::DELETE_FILE_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "DeleteFile", + ); + + let api_clone = api.clone(); + router.delete( + "/v0/file/edit/:edit_id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_edit_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? + }; + + match api.delete_file_edit(param_edit_id, context).wait() { + Ok(rsp) => match rsp { + DeleteFileEditResponse::DeletedEdit(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::DELETE_FILE_EDIT_DELETED_EDIT.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteFileEditResponse::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::DELETE_FILE_EDIT_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteFileEditResponse::NotFound(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::DELETE_FILE_EDIT_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteFileEditResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::DELETE_FILE_EDIT_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "DeleteFileEdit", + ); + + let api_clone = api.clone(); + router.get( + "/v0/file/:id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_file(param_id, param_expand, param_hide, context).wait() { + Ok(rsp) => match rsp { + GetFileResponse::FoundEntity(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::GET_FILE_FOUND_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileResponse::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::GET_FILE_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileResponse::NotFound(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::GET_FILE_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetFile", + ); + + let api_clone = api.clone(); + router.get( + "/v0/file/edit/:edit_id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_edit_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? + }; + + match api.get_file_edit(param_edit_id, context).wait() { + Ok(rsp) => match rsp { + GetFileEditResponse::FoundEdit(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::GET_FILE_EDIT_FOUND_EDIT.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileEditResponse::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::GET_FILE_EDIT_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileEditResponse::NotFound(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::GET_FILE_EDIT_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileEditResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_EDIT_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetFileEdit", + ); + + let api_clone = api.clone(); + router.get( + "/v0/file/:id/history", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_file_history(param_id, param_limit, context).wait() { + Ok(rsp) => match rsp { + GetFileHistoryResponse::FoundEntityHistory(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::GET_FILE_HISTORY_FOUND_ENTITY_HISTORY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileHistoryResponse::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::GET_FILE_HISTORY_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileHistoryResponse::NotFound(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::GET_FILE_HISTORY_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileHistoryResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_HISTORY_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetFileHistory", + ); + + let api_clone = api.clone(); + router.get( + "/v0/file/:id/redirects", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + match api.get_file_redirects(param_id, context).wait() { + Ok(rsp) => match rsp { + GetFileRedirectsResponse::FoundEntityRedirects(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::GET_FILE_REDIRECTS_FOUND_ENTITY_REDIRECTS.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileRedirectsResponse::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::GET_FILE_REDIRECTS_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileRedirectsResponse::NotFound(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::GET_FILE_REDIRECTS_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileRedirectsResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_REDIRECTS_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetFileRedirects", + ); + + let api_clone = api.clone(); + router.get( + "/v0/file/rev/:id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_file_revision(param_id, param_expand, param_hide, context).wait() { + Ok(rsp) => match rsp { + GetFileRevisionResponse::FoundEntityRevision(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::GET_FILE_REVISION_FOUND_ENTITY_REVISION.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileRevisionResponse::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::GET_FILE_REVISION_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileRevisionResponse::NotFound(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::GET_FILE_REVISION_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetFileRevisionResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_REVISION_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetFileRevision", + ); + + let api_clone = api.clone(); + router.get( + "/v0/file/lookup", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_md5 = query_params.get("md5").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_sha1 = query_params.get("sha1").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_sha256 = query_params.get("sha256").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.lookup_file(param_md5, param_sha1, param_sha256, param_hide, context).wait() { + Ok(rsp) => match rsp { + LookupFileResponse::FoundEntity(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::LOOKUP_FILE_FOUND_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + LookupFileResponse::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::LOOKUP_FILE_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + LookupFileResponse::NotFound(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::LOOKUP_FILE_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + LookupFileResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "LookupFile", + ); + + let api_clone = api.clone(); + router.put( + "/v0/file/:id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + + param_entity + } else { + None + }; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + + match api.update_file(param_id, param_entity, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + UpdateFileResponse::UpdatedEntity(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::UPDATE_FILE_UPDATED_ENTITY.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))); + } + Ok(response) + } + UpdateFileResponse::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::UPDATE_FILE_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))); + } + Ok(response) + } + UpdateFileResponse::NotFound(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::UPDATE_FILE_NOT_FOUND.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))); + } + Ok(response) + } + UpdateFileResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::UPDATE_FILE_GENERIC_ERROR.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))); + } + 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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "UpdateFile", + ); + + let api_clone = api.clone(); + router.post( + "/v0/release", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + + param_entity + } else { + None + }; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + + match api.create_release(param_entity, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + CreateReleaseResponse::CreatedEntity(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::CREATE_RELEASE_CREATED_ENTITY.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))); + } + Ok(response) + } + CreateReleaseResponse::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::CREATE_RELEASE_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))); + } + Ok(response) + } + CreateReleaseResponse::NotFound(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::CREATE_RELEASE_NOT_FOUND.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))); + } + Ok(response) + } + CreateReleaseResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_GENERIC_ERROR.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))); + } + 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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "CreateRelease", + ); + + let api_clone = api.clone(); + router.post( + "/v0/release/batch", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity_list = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); + + let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + + param_entity_list + } else { + None + }; + let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; + + match api.create_release_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + CreateReleaseBatchResponse::CreatedEntities(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::CREATE_RELEASE_BATCH_CREATED_ENTITIES.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))); + } + Ok(response) + } + CreateReleaseBatchResponse::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::CREATE_RELEASE_BATCH_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))); + } + Ok(response) + } + CreateReleaseBatchResponse::NotFound(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::CREATE_RELEASE_BATCH_NOT_FOUND.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))); + } + Ok(response) + } + CreateReleaseBatchResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_BATCH_GENERIC_ERROR.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))); + } + 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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "CreateReleaseBatch", + ); + + let api_clone = api.clone(); + router.post( + "/v0/work", move |req: &mut Request| { let mut context = Context::default(); @@ -3215,74 +4287,714 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_entity = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + let param_entity = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + + param_entity + } else { + None + }; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + + match api.create_work(param_entity, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + CreateWorkResponse::CreatedEntity(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::CREATE_WORK_CREATED_ENTITY.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))); + } + Ok(response) + } + CreateWorkResponse::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::CREATE_WORK_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))); + } + Ok(response) + } + CreateWorkResponse::NotFound(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::CREATE_WORK_NOT_FOUND.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))); + } + Ok(response) + } + CreateWorkResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_GENERIC_ERROR.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))); + } + 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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "CreateWork", + ); + + let api_clone = api.clone(); + router.delete( + "/v0/release/:id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.delete_release(param_id, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + DeleteReleaseResponse::DeletedEntity(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::DELETE_RELEASE_DELETED_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteReleaseResponse::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::DELETE_RELEASE_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteReleaseResponse::NotFound(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::DELETE_RELEASE_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteReleaseResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::DELETE_RELEASE_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "DeleteRelease", + ); + + let api_clone = api.clone(); + router.delete( + "/v0/release/edit/:edit_id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_edit_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? + }; + + match api.delete_release_edit(param_edit_id, context).wait() { + Ok(rsp) => match rsp { + DeleteReleaseEditResponse::DeletedEdit(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::DELETE_RELEASE_EDIT_DELETED_EDIT.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteReleaseEditResponse::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::DELETE_RELEASE_EDIT_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteReleaseEditResponse::NotFound(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::DELETE_RELEASE_EDIT_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteReleaseEditResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::DELETE_RELEASE_EDIT_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "DeleteReleaseEdit", + ); + + let api_clone = api.clone(); + router.get( + "/v0/release/:id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_release(param_id, param_expand, param_hide, context).wait() { + Ok(rsp) => match rsp { + GetReleaseResponse::FoundEntity(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::GET_RELEASE_FOUND_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseResponse::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::GET_RELEASE_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseResponse::NotFound(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::GET_RELEASE_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetRelease", + ); + + let api_clone = api.clone(); + router.get( + "/v0/release/edit/:edit_id", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_edit_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? + }; + + match api.get_release_edit(param_edit_id, context).wait() { + Ok(rsp) => match rsp { + GetReleaseEditResponse::FoundEdit(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::GET_RELEASE_EDIT_FOUND_EDIT.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseEditResponse::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::GET_RELEASE_EDIT_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseEditResponse::NotFound(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::GET_RELEASE_EDIT_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseEditResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut unused_elements = Vec::new(); + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_EDIT_GENERIC_ERROR.clone())); - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + 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()))) + } + } + } - param_entity - } else { - None + 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()))); + Ok(response) + }) + }, + "GetReleaseEdit", + ); + + let api_clone = api.clone(); + router.get( + "/v0/release/:id/files", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.create_work(param_entity, param_editgroup, context).wait() { + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_release_files(param_id, param_hide, context).wait() { Ok(rsp) => match rsp { - CreateWorkResponse::CreatedEntity(body) => { + GetReleaseFilesResponse::Found(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::CREATE_WORK_CREATED_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_FILES_FOUND.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))); - } + + Ok(response) + } + GetReleaseFilesResponse::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::GET_RELEASE_FILES_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseFilesResponse::NotFound(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::GET_RELEASE_FILES_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseFilesResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_FILES_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetReleaseFiles", + ); + + let api_clone = api.clone(); + router.get( + "/v0/release/:id/history", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + match api.get_release_history(param_id, param_limit, context).wait() { + Ok(rsp) => match rsp { + GetReleaseHistoryResponse::FoundEntityHistory(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::GET_RELEASE_HISTORY_FOUND_ENTITY_HISTORY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseHistoryResponse::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::GET_RELEASE_HISTORY_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseHistoryResponse::NotFound(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::GET_RELEASE_HISTORY_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetReleaseHistoryResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_HISTORY_GENERIC_ERROR.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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "GetReleaseHistory", + ); + + let api_clone = api.clone(); + router.get( + "/v0/release/:id/redirects", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; + + match api.get_release_redirects(param_id, context).wait() { + Ok(rsp) => match rsp { + GetReleaseRedirectsResponse::FoundEntityRedirects(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::GET_RELEASE_REDIRECTS_FOUND_ENTITY_REDIRECTS.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + Ok(response) } - CreateWorkResponse::BadRequest(body) => { + GetReleaseRedirectsResponse::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::CREATE_WORK_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_REDIRECTS_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))); - } + Ok(response) } - CreateWorkResponse::NotFound(body) => { + GetReleaseRedirectsResponse::NotFound(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::CREATE_WORK_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_REDIRECTS_NOT_FOUND.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))); - } + Ok(response) } - CreateWorkResponse::GenericError(body) => { + GetReleaseRedirectsResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_REDIRECTS_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -3299,12 +5011,12 @@ where Ok(response) }) }, - "CreateWork", + "GetReleaseRedirects", ); let api_clone = api.clone(); - router.delete( - "/v0/release/:id", + router.get( + "/v0/release/rev/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -3334,45 +5046,46 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.delete_release(param_id, param_editgroup, context).wait() { + match api.get_release_revision(param_id, param_expand, param_hide, context).wait() { Ok(rsp) => match rsp { - DeleteReleaseResponse::DeletedEntity(body) => { + GetReleaseRevisionResponse::FoundEntityRevision(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::DELETE_RELEASE_DELETED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_REVISION_FOUND_ENTITY_REVISION.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteReleaseResponse::BadRequest(body) => { + GetReleaseRevisionResponse::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::DELETE_RELEASE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_REVISION_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteReleaseResponse::NotFound(body) => { + GetReleaseRevisionResponse::NotFound(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::DELETE_RELEASE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_REVISION_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteReleaseResponse::GenericError(body) => { + GetReleaseRevisionResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::DELETE_RELEASE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_REVISION_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -3392,12 +5105,12 @@ where Ok(response) }) }, - "DeleteRelease", + "GetReleaseRevision", ); let api_clone = api.clone(); router.get( - "/v0/release/:id", + "/v0/release/lookup", move |req: &mut Request| { let mut context = Context::default(); @@ -3410,63 +5123,52 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_doi = query_params.get("doi").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_wikidata_qid = query_params.get("wikidata_qid").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_isbn13 = query_params.get("isbn13").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_pmid = query_params.get("pmid").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_pmcid = query_params.get("pmcid").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_release(param_id, param_expand, param_hide, context).wait() { + match api.lookup_release(param_doi, param_wikidata_qid, param_isbn13, param_pmid, param_pmcid, param_hide, context).wait() { Ok(rsp) => match rsp { - GetReleaseResponse::FoundEntity(body) => { + LookupReleaseResponse::FoundEntity(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::GET_RELEASE_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetReleaseResponse::BadRequest(body) => { + LookupReleaseResponse::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::GET_RELEASE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetReleaseResponse::NotFound(body) => { + LookupReleaseResponse::NotFound(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::GET_RELEASE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetReleaseResponse::GenericError(body) => { + LookupReleaseResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -3486,12 +5188,12 @@ where Ok(response) }) }, - "GetRelease", + "LookupRelease", ); let api_clone = api.clone(); - router.get( - "/v0/release/:id/files", + router.put( + "/v0/release/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -3521,48 +5223,191 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_release_files(param_id, param_hide, context).wait() { + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + + param_entity + } else { + None + }; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + + match api.update_release(param_id, param_entity, param_editgroup, context).wait() { Ok(rsp) => match rsp { - GetReleaseFilesResponse::Found(body) => { + UpdateReleaseResponse::UpdatedEntity(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::GET_RELEASE_FILES_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_RELEASE_UPDATED_ENTITY.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))); + } Ok(response) } - GetReleaseFilesResponse::BadRequest(body) => { + UpdateReleaseResponse::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::GET_RELEASE_FILES_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_RELEASE_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))); + } Ok(response) } - GetReleaseFilesResponse::NotFound(body) => { + UpdateReleaseResponse::NotFound(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::GET_RELEASE_FILES_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_RELEASE_NOT_FOUND.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))); + } Ok(response) } - GetReleaseFilesResponse::GenericError(body) => { + UpdateReleaseResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_FILES_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_RELEASE_GENERIC_ERROR.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))); + } + 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()))) + } + } + } + + 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()))); + Ok(response) + }) + }, + "UpdateRelease", + ); + + let api_clone = api.clone(); + router.post( + "/v0/work/batch", + move |req: &mut Request| { + let mut context = Context::default(); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity_list = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); + + let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + + param_entity_list + } else { + None + }; + let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; + + match api.create_work_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { + Ok(rsp) => match rsp { + CreateWorkBatchResponse::CreatedEntities(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::CREATE_WORK_BATCH_CREATED_ENTITIES.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))); + } + Ok(response) + } + CreateWorkBatchResponse::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::CREATE_WORK_BATCH_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))); + } + Ok(response) + } + CreateWorkBatchResponse::NotFound(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::CREATE_WORK_BATCH_NOT_FOUND.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))); + } + Ok(response) + } + CreateWorkBatchResponse::GenericError(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let mut response = Response::with((status::Status::from_u16(500), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_BATCH_GENERIC_ERROR.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))); + } Ok(response) } }, @@ -3579,12 +5424,12 @@ where Ok(response) }) }, - "GetReleaseFiles", + "CreateWorkBatch", ); let api_clone = api.clone(); - router.get( - "/v0/release/:id/history", + router.delete( + "/v0/work/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -3614,45 +5459,45 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_release_history(param_id, param_limit, context).wait() { + match api.delete_work(param_id, param_editgroup, context).wait() { Ok(rsp) => match rsp { - GetReleaseHistoryResponse::FoundEntityHistory(body) => { + DeleteWorkResponse::DeletedEntity(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::GET_RELEASE_HISTORY_FOUND_ENTITY_HISTORY.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_DELETED_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetReleaseHistoryResponse::BadRequest(body) => { + DeleteWorkResponse::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::GET_RELEASE_HISTORY_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetReleaseHistoryResponse::NotFound(body) => { + DeleteWorkResponse::NotFound(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::GET_RELEASE_HISTORY_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetReleaseHistoryResponse::GenericError(body) => { + DeleteWorkResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_HISTORY_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -3672,12 +5517,12 @@ where Ok(response) }) }, - "GetReleaseHistory", + "DeleteWork", ); let api_clone = api.clone(); - router.get( - "/v0/release/lookup", + router.delete( + "/v0/work/edit/:edit_id", move |req: &mut Request| { let mut context = Context::default(); @@ -3690,54 +5535,58 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_doi = query_params - .get("doi") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter doi".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter doi was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter doi - doesn't match schema: {}", e))))?; - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + // Path parameters + let param_edit_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? + }; - match api.lookup_release(param_doi, param_hide, context).wait() { + match api.delete_work_edit(param_edit_id, context).wait() { Ok(rsp) => match rsp { - LookupReleaseResponse::FoundEntity(body) => { + DeleteWorkEditResponse::DeletedEdit(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::LOOKUP_RELEASE_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_EDIT_DELETED_EDIT.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupReleaseResponse::BadRequest(body) => { + DeleteWorkEditResponse::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::LOOKUP_RELEASE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_EDIT_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupReleaseResponse::NotFound(body) => { + DeleteWorkEditResponse::NotFound(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::LOOKUP_RELEASE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_EDIT_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - LookupReleaseResponse::GenericError(body) => { + DeleteWorkEditResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_EDIT_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -3757,12 +5606,12 @@ where Ok(response) }) }, - "LookupRelease", + "DeleteWorkEdit", ); let api_clone = api.clone(); - router.put( - "/v0/release/:id", + router.get( + "/v0/work/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -3792,80 +5641,49 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - - param_entity - } else { - None - }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.update_release(param_id, param_entity, param_editgroup, context).wait() { + match api.get_work(param_id, param_expand, param_hide, context).wait() { Ok(rsp) => match rsp { - UpdateReleaseResponse::UpdatedEntity(body) => { + GetWorkResponse::FoundEntity(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::UPDATE_RELEASE_UPDATED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_FOUND_ENTITY.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))); - } + Ok(response) } - UpdateReleaseResponse::BadRequest(body) => { + GetWorkResponse::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::UPDATE_RELEASE_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_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))); - } + Ok(response) } - UpdateReleaseResponse::NotFound(body) => { + GetWorkResponse::NotFound(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::UPDATE_RELEASE_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_NOT_FOUND.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))); - } + Ok(response) } - UpdateReleaseResponse::GenericError(body) => { + GetWorkResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::UPDATE_RELEASE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -3882,12 +5700,12 @@ where Ok(response) }) }, - "UpdateRelease", + "GetWork", ); let api_clone = api.clone(); - router.post( - "/v0/work/batch", + router.get( + "/v0/work/edit/:edit_id", move |req: &mut Request| { let mut context = Context::default(); @@ -3900,83 +5718,61 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity_list = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - - let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; - - param_entity_list - } else { - None + // Path parameters + let param_edit_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("edit_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter edit_id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter edit_id: {}", e))))? }; - let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.create_work_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() { + match api.get_work_edit(param_edit_id, context).wait() { Ok(rsp) => match rsp { - CreateWorkBatchResponse::CreatedEntities(body) => { + GetWorkEditResponse::FoundEdit(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::CREATE_WORK_BATCH_CREATED_ENTITIES.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_EDIT_FOUND_EDIT.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))); - } + Ok(response) } - CreateWorkBatchResponse::BadRequest(body) => { + GetWorkEditResponse::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::CREATE_WORK_BATCH_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_EDIT_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))); - } + Ok(response) } - CreateWorkBatchResponse::NotFound(body) => { + GetWorkEditResponse::NotFound(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::CREATE_WORK_BATCH_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_EDIT_NOT_FOUND.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))); - } + Ok(response) } - CreateWorkBatchResponse::GenericError(body) => { + GetWorkEditResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_BATCH_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_EDIT_GENERIC_ERROR.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))); - } + Ok(response) } }, @@ -3993,12 +5789,12 @@ where Ok(response) }) }, - "CreateWorkBatch", + "GetWorkEdit", ); let api_clone = api.clone(); - router.delete( - "/v0/work/:id", + router.get( + "/v0/work/:id/history", move |req: &mut Request| { let mut context = Context::default(); @@ -4028,45 +5824,45 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.delete_work(param_id, param_editgroup, context).wait() { + match api.get_work_history(param_id, param_limit, context).wait() { Ok(rsp) => match rsp { - DeleteWorkResponse::DeletedEntity(body) => { + GetWorkHistoryResponse::FoundEntityHistory(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::DELETE_WORK_DELETED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_HISTORY_FOUND_ENTITY_HISTORY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteWorkResponse::BadRequest(body) => { + GetWorkHistoryResponse::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::DELETE_WORK_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_HISTORY_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteWorkResponse::NotFound(body) => { + GetWorkHistoryResponse::NotFound(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::DELETE_WORK_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_HISTORY_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - DeleteWorkResponse::GenericError(body) => { + GetWorkHistoryResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::DELETE_WORK_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_HISTORY_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -4086,12 +5882,12 @@ where Ok(response) }) }, - "DeleteWork", + "GetWorkHistory", ); let api_clone = api.clone(); router.get( - "/v0/work/:id", + "/v0/work/:id/redirects", move |req: &mut Request| { let mut context = Context::default(); @@ -4119,48 +5915,43 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - match api.get_work(param_id, param_expand, param_hide, context).wait() { + match api.get_work_redirects(param_id, context).wait() { Ok(rsp) => match rsp { - GetWorkResponse::FoundEntity(body) => { + GetWorkRedirectsResponse::FoundEntityRedirects(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::GET_WORK_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REDIRECTS_FOUND_ENTITY_REDIRECTS.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkResponse::BadRequest(body) => { + GetWorkRedirectsResponse::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::GET_WORK_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REDIRECTS_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkResponse::NotFound(body) => { + GetWorkRedirectsResponse::NotFound(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::GET_WORK_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REDIRECTS_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkResponse::GenericError(body) => { + GetWorkRedirectsResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_WORK_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REDIRECTS_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -4180,12 +5971,12 @@ where Ok(response) }) }, - "GetWork", + "GetWorkRedirects", ); let api_clone = api.clone(); router.get( - "/v0/work/:id/history", + "/v0/work/:id/releases", move |req: &mut Request| { let mut context = Context::default(); @@ -4215,45 +6006,45 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); - let param_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_work_history(param_id, param_limit, context).wait() { + match api.get_work_releases(param_id, param_hide, context).wait() { Ok(rsp) => match rsp { - GetWorkHistoryResponse::FoundEntityHistory(body) => { + GetWorkReleasesResponse::Found(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::GET_WORK_HISTORY_FOUND_ENTITY_HISTORY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_RELEASES_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkHistoryResponse::BadRequest(body) => { + GetWorkReleasesResponse::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::GET_WORK_HISTORY_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_RELEASES_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkHistoryResponse::NotFound(body) => { + GetWorkReleasesResponse::NotFound(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::GET_WORK_HISTORY_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_RELEASES_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkHistoryResponse::GenericError(body) => { + GetWorkReleasesResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_WORK_HISTORY_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_RELEASES_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -4273,12 +6064,12 @@ where Ok(response) }) }, - "GetWorkHistory", + "GetWorkReleases", ); let api_clone = api.clone(); router.get( - "/v0/work/:id/releases", + "/v0/work/rev/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -4308,45 +6099,46 @@ where // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) let query_params = req.get::().unwrap_or_default(); + let param_expand = query_params.get("expand").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); let param_hide = query_params.get("hide").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.get_work_releases(param_id, param_hide, context).wait() { + match api.get_work_revision(param_id, param_expand, param_hide, context).wait() { Ok(rsp) => match rsp { - GetWorkReleasesResponse::Found(body) => { + GetWorkRevisionResponse::FoundEntityRevision(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::GET_WORK_RELEASES_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REVISION_FOUND_ENTITY_REVISION.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkReleasesResponse::BadRequest(body) => { + GetWorkRevisionResponse::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::GET_WORK_RELEASES_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REVISION_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkReleasesResponse::NotFound(body) => { + GetWorkRevisionResponse::NotFound(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::GET_WORK_RELEASES_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REVISION_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetWorkReleasesResponse::GenericError(body) => { + GetWorkRevisionResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_WORK_RELEASES_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_REVISION_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -4366,7 +6158,7 @@ where Ok(response) }) }, - "GetWorkReleases", + "GetWorkRevision", ); let api_clone = api.clone(); -- cgit v1.2.3