From 42d73fb7da872eee94325ae8412a66b1f6e5adf9 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 10 Jan 2019 21:36:41 -0800 Subject: rust codegen --- rust/fatcat-api-spec/src/client.rs | 521 ++++++++++++++++++++++++- rust/fatcat-api-spec/src/lib.rs | 190 ++++++++- rust/fatcat-api-spec/src/mimetypes.rs | 136 ++++++- rust/fatcat-api-spec/src/models.rs | 53 +++ rust/fatcat-api-spec/src/server.rs | 711 ++++++++++++++++++++++++++++++++-- 5 files changed, 1537 insertions(+), 74 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 c5cf4297..a3e97fb3 100644 --- a/rust/fatcat-api-spec/src/client.rs +++ b/rust/fatcat-api-spec/src/client.rs @@ -36,18 +36,18 @@ use swagger::{ApiError, Context, XSpanId}; use models; use { AcceptEditgroupResponse, Api, AuthCheckResponse, AuthOidcResponse, CreateContainerBatchResponse, CreateContainerResponse, CreateCreatorBatchResponse, CreateCreatorResponse, - CreateEditgroupResponse, CreateFileBatchResponse, CreateFileResponse, CreateFilesetBatchResponse, CreateFilesetResponse, CreateReleaseBatchResponse, CreateReleaseResponse, - CreateWebcaptureBatchResponse, CreateWebcaptureResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, DeleteCreatorEditResponse, - DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteFilesetEditResponse, DeleteFilesetResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, + CreateEditgroupAnnotationResponse, CreateEditgroupResponse, CreateFileBatchResponse, CreateFileResponse, CreateFilesetBatchResponse, CreateFilesetResponse, CreateReleaseBatchResponse, + CreateReleaseResponse, CreateWebcaptureBatchResponse, CreateWebcaptureResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, + DeleteCreatorEditResponse, DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteFilesetEditResponse, DeleteFilesetResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, DeleteWebcaptureEditResponse, DeleteWebcaptureResponse, DeleteWorkEditResponse, DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, GetContainerEditResponse, GetContainerHistoryResponse, GetContainerRedirectsResponse, GetContainerResponse, GetContainerRevisionResponse, GetCreatorEditResponse, GetCreatorHistoryResponse, GetCreatorRedirectsResponse, - GetCreatorReleasesResponse, GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupResponse, GetEditorChangelogResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, - GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, - GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, - GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, - GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, - LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, - UpdateWorkResponse, + GetCreatorReleasesResponse, GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupAnnotationsResponse, GetEditgroupResponse, GetEditgroupsReviewableResponse, GetEditorAnnotationsResponse, + GetEditorEditgroupsResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, + GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, + GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, + GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, + GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, + UpdateEditgroupResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, UpdateWorkResponse, }; /// Convert input into a base path, e.g. "http://example:123". Also checks the scheme as it goes. @@ -2203,6 +2203,86 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_editgroups_reviewable( + &self, + param_expand: Option, + param_limit: Option, + param_before: Option>, + param_since: 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_limit = param_limit.map_or_else(String::new, |query| format!("limit={limit}&", limit = query.to_string())); + let query_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); + let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); + + let url = format!( + "{}/v0/editgroup/reviewable?{expand}{limit}{before}{since}", + self.base_path, + expand = utf8_percent_encode(&query_expand, QUERY_ENCODE_SET), + limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), + before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), + since = utf8_percent_encode(&query_since, 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(GetEditgroupsReviewableResponse::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(GetEditgroupsReviewableResponse::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(GetEditgroupsReviewableResponse::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(GetEditgroupsReviewableResponse::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_editor(&self, param_editor_id: String, context: &Context) -> Box + Send> { let url = format!( "{}/v0/editor/{editor_id}", @@ -2267,11 +2347,26 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_editor_changelog(&self, param_editor_id: String, context: &Context) -> Box + Send> { + fn get_editor_editgroups( + &self, + param_editor_id: String, + param_limit: Option, + param_before: Option>, + param_since: 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_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); + let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); + let url = format!( - "{}/v0/editor/{editor_id}/changelog", + "{}/v0/editor/{editor_id}/editgroups?{limit}{before}{since}", self.base_path, - editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET) + editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET), + limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), + before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), + since = utf8_percent_encode(&query_since, QUERY_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); @@ -2283,35 +2378,136 @@ 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(GetEditorEditgroupsResponse::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(GetEditorEditgroupsResponse::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(GetEditorEditgroupsResponse::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(GetEditorEditgroupsResponse::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_editgroup( + &self, + param_editgroup_id: String, + param_editgroup: models::Editgroup, + param_submit: Option, + context: &Context, + ) -> Box + Send> { + // Query parameters + let query_submit = param_submit.map_or_else(String::new, |query| format!("submit={submit}&", submit = query.to_string())); + + let url = format!( + "{}/v0/editgroup/{editgroup_id}?{submit}", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), + submit = utf8_percent_encode(&query_submit, QUERY_ENCODE_SET) + ); + + let body = serde_json::to_string(¶m_editgroup).expect("impossible to fail to serialize"); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Put, &url); + let mut custom_headers = hyper::header::Headers::new(); + + let request = request.body(&body); - Ok(GetEditorChangelogResponse::Found(body)) + custom_headers.set(ContentType(mimetypes::requests::UPDATE_EDITGROUP.clone())); + context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); + + let request = request.headers(custom_headers); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn parse_response(mut response: hyper::client::response::Response) -> Result { + 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(UpdateEditgroupResponse::UpdatedEditgroup(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(GetEditorChangelogResponse::BadRequest(body)) + Ok(UpdateEditgroupResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(UpdateEditgroupResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(UpdateEditgroupResponse::Forbidden(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(GetEditorChangelogResponse::NotFound(body)) + Ok(UpdateEditgroupResponse::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(GetEditorChangelogResponse::GenericError(body)) + Ok(UpdateEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2602,6 +2798,102 @@ impl Api for Client { Box::new(futures::done(result)) } + fn create_editgroup_annotation( + &self, + param_editgroup_id: String, + param_annotation: models::EditgroupAnnotation, + context: &Context, + ) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/annotation", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let body = serde_json::to_string(¶m_annotation).expect("impossible to fail to serialize"); + + let hyper_client = (self.hyper_client)(); + let request = hyper_client.request(hyper::method::Method::Post, &url); + let mut custom_headers = hyper::header::Headers::new(); + + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::CREATE_EDITGROUP_ANNOTATION.clone())); + context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); + + let request = request.headers(custom_headers); + + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn parse_response(mut response: hyper::client::response::Response) -> Result { + match response.status.to_u16() { + 201 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(CreateEditgroupAnnotationResponse::Created(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(CreateEditgroupAnnotationResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(CreateEditgroupAnnotationResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(CreateEditgroupAnnotationResponse::Forbidden(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(CreateEditgroupAnnotationResponse::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(CreateEditgroupAnnotationResponse::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_changelog(&self, 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())); @@ -2786,6 +3078,197 @@ impl Api for Client { Box::new(futures::done(result)) } + fn get_editgroup_annotations(&self, param_editgroup_id: String, param_expand: 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 url = format!( + "{}/v0/editgroup/{editgroup_id}/annotations?{expand}", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), + expand = utf8_percent_encode(&query_expand, 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(GetEditgroupAnnotationsResponse::Success(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(GetEditgroupAnnotationsResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(GetEditgroupAnnotationsResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(GetEditgroupAnnotationsResponse::Forbidden(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(GetEditgroupAnnotationsResponse::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(GetEditgroupAnnotationsResponse::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_editor_annotations( + &self, + param_editor_id: String, + param_limit: Option, + param_before: Option>, + param_since: 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_before = param_before.map_or_else(String::new, |query| format!("before={before}&", before = query.to_string())); + let query_since = param_since.map_or_else(String::new, |query| format!("since={since}&", since = query.to_string())); + + let url = format!( + "{}/v0/editor/{editor_id}/annotations?{limit}{before}{since}", + self.base_path, + editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET), + limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET), + before = utf8_percent_encode(&query_before, QUERY_ENCODE_SET), + since = utf8_percent_encode(&query_since, 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(GetEditorAnnotationsResponse::Success(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(GetEditorAnnotationsResponse::BadRequest(body)) + } + 401 => { + 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)?; + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + let response_www_authenticate = response + .headers + .get::() + .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; + + Ok(GetEditorAnnotationsResponse::NotAuthorized { + body: body, + www_authenticate: response_www_authenticate.0.clone(), + }) + } + 403 => { + 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(GetEditorAnnotationsResponse::Forbidden(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(GetEditorAnnotationsResponse::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(GetEditorAnnotationsResponse::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 create_file(&self, param_entity: models::FileEntity, param_editgroup_id: String, context: &Context) -> Box + Send> { // Query parameters let query_editgroup_id = format!("editgroup_id={editgroup_id}&", editgroup_id = param_editgroup_id.to_string()); diff --git a/rust/fatcat-api-spec/src/lib.rs b/rust/fatcat-api-spec/src/lib.rs index 3f1afa67..9585f1c0 100644 --- a/rust/fatcat-api-spec/src/lib.rs +++ b/rust/fatcat-api-spec/src/lib.rs @@ -380,6 +380,18 @@ pub enum AuthOidcResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetEditgroupsReviewableResponse { + /// Found + Found(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetEditorResponse { /// Found @@ -393,11 +405,27 @@ pub enum GetEditorResponse { } #[derive(Debug, PartialEq)] -pub enum GetEditorChangelogResponse { +pub enum GetEditorEditgroupsResponse { /// Found - Found(Vec), + Found(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum UpdateEditgroupResponse { + /// Updated Editgroup + UpdatedEditgroup(models::Editgroup), /// Bad Request BadRequest(models::ErrorResponse), + /// Not Authorized + NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, + /// Forbidden + Forbidden(models::ErrorResponse), /// Not Found NotFound(models::ErrorResponse), /// Generic Error @@ -454,6 +482,22 @@ pub enum CreateEditgroupResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum CreateEditgroupAnnotationResponse { + /// Created + Created(models::EditgroupAnnotation), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Authorized + NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, + /// Forbidden + Forbidden(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum GetChangelogResponse { /// Success @@ -488,6 +532,38 @@ pub enum GetEditgroupResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum GetEditgroupAnnotationsResponse { + /// Success + Success(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Authorized + NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, + /// Forbidden + Forbidden(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum GetEditorAnnotationsResponse { + /// Success + Success(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Authorized + NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, + /// Forbidden + Forbidden(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum CreateFileResponse { /// Created Entity @@ -1338,9 +1414,27 @@ pub trait Api { fn auth_oidc(&self, oidc_params: models::AuthOidc, context: &Context) -> Box + Send>; + fn get_editgroups_reviewable( + &self, + expand: Option, + limit: Option, + before: Option>, + since: Option>, + context: &Context, + ) -> Box + Send>; + fn get_editor(&self, editor_id: String, context: &Context) -> Box + Send>; - fn get_editor_changelog(&self, editor_id: String, context: &Context) -> Box + Send>; + fn get_editor_editgroups( + &self, + editor_id: String, + limit: Option, + before: Option>, + since: Option>, + context: &Context, + ) -> Box + Send>; + + fn update_editgroup(&self, editgroup_id: String, editgroup: models::Editgroup, submit: Option, context: &Context) -> Box + Send>; fn update_editor(&self, editor_id: String, editor: models::Editor, context: &Context) -> Box + Send>; @@ -1348,12 +1442,30 @@ pub trait Api { fn create_editgroup(&self, editgroup: models::Editgroup, context: &Context) -> Box + Send>; + fn create_editgroup_annotation( + &self, + editgroup_id: String, + annotation: models::EditgroupAnnotation, + context: &Context, + ) -> Box + Send>; + fn get_changelog(&self, limit: Option, context: &Context) -> Box + Send>; fn get_changelog_entry(&self, index: i64, context: &Context) -> Box + Send>; fn get_editgroup(&self, editgroup_id: String, context: &Context) -> Box + Send>; + fn get_editgroup_annotations(&self, editgroup_id: String, expand: Option, context: &Context) -> Box + Send>; + + fn get_editor_annotations( + &self, + editor_id: String, + limit: Option, + before: Option>, + since: Option>, + context: &Context, + ) -> Box + Send>; + fn create_file(&self, entity: models::FileEntity, editgroup_id: String, context: &Context) -> Box + Send>; fn create_file_batch( @@ -1584,9 +1696,25 @@ pub trait ApiNoContext { fn auth_oidc(&self, oidc_params: models::AuthOidc) -> Box + Send>; + fn get_editgroups_reviewable( + &self, + expand: Option, + limit: Option, + before: Option>, + since: Option>, + ) -> Box + Send>; + fn get_editor(&self, editor_id: String) -> Box + Send>; - fn get_editor_changelog(&self, editor_id: String) -> Box + Send>; + fn get_editor_editgroups( + &self, + editor_id: String, + limit: Option, + before: Option>, + since: Option>, + ) -> Box + Send>; + + fn update_editgroup(&self, editgroup_id: String, editgroup: models::Editgroup, submit: Option) -> Box + Send>; fn update_editor(&self, editor_id: String, editor: models::Editor) -> Box + Send>; @@ -1594,12 +1722,24 @@ pub trait ApiNoContext { fn create_editgroup(&self, editgroup: models::Editgroup) -> Box + Send>; + fn create_editgroup_annotation(&self, editgroup_id: String, annotation: models::EditgroupAnnotation) -> Box + Send>; + fn get_changelog(&self, limit: Option) -> Box + Send>; fn get_changelog_entry(&self, index: i64) -> Box + Send>; fn get_editgroup(&self, editgroup_id: String) -> Box + Send>; + fn get_editgroup_annotations(&self, editgroup_id: String, expand: Option) -> Box + Send>; + + fn get_editor_annotations( + &self, + editor_id: String, + limit: Option, + before: Option>, + since: Option>, + ) -> Box + Send>; + fn create_file(&self, entity: models::FileEntity, editgroup_id: String) -> Box + Send>; fn create_file_batch(&self, entity_list: &Vec, autoaccept: Option, editgroup_id: Option) -> Box + Send>; @@ -1877,12 +2017,32 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().auth_oidc(oidc_params, &self.context()) } + fn get_editgroups_reviewable( + &self, + expand: Option, + limit: Option, + before: Option>, + since: Option>, + ) -> Box + Send> { + self.api().get_editgroups_reviewable(expand, limit, before, since, &self.context()) + } + fn get_editor(&self, editor_id: String) -> Box + Send> { self.api().get_editor(editor_id, &self.context()) } - fn get_editor_changelog(&self, editor_id: String) -> Box + Send> { - self.api().get_editor_changelog(editor_id, &self.context()) + fn get_editor_editgroups( + &self, + editor_id: String, + limit: Option, + before: Option>, + since: Option>, + ) -> Box + Send> { + self.api().get_editor_editgroups(editor_id, limit, before, since, &self.context()) + } + + fn update_editgroup(&self, editgroup_id: String, editgroup: models::Editgroup, submit: Option) -> Box + Send> { + self.api().update_editgroup(editgroup_id, editgroup, submit, &self.context()) } fn update_editor(&self, editor_id: String, editor: models::Editor) -> Box + Send> { @@ -1897,6 +2057,10 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().create_editgroup(editgroup, &self.context()) } + fn create_editgroup_annotation(&self, editgroup_id: String, annotation: models::EditgroupAnnotation) -> Box + Send> { + self.api().create_editgroup_annotation(editgroup_id, annotation, &self.context()) + } + fn get_changelog(&self, limit: Option) -> Box + Send> { self.api().get_changelog(limit, &self.context()) } @@ -1909,6 +2073,20 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().get_editgroup(editgroup_id, &self.context()) } + fn get_editgroup_annotations(&self, editgroup_id: String, expand: Option) -> Box + Send> { + self.api().get_editgroup_annotations(editgroup_id, expand, &self.context()) + } + + fn get_editor_annotations( + &self, + editor_id: String, + limit: Option, + before: Option>, + since: Option>, + ) -> Box + Send> { + self.api().get_editor_annotations(editor_id, limit, before, since, &self.context()) + } + fn create_file(&self, entity: models::FileEntity, editgroup_id: String) -> Box + Send> { self.api().create_file(entity, editgroup_id, &self.context()) } diff --git a/rust/fatcat-api-spec/src/mimetypes.rs b/rust/fatcat-api-spec/src/mimetypes.rs index 11159610..5c916e47 100644 --- a/rust/fatcat-api-spec/src/mimetypes.rs +++ b/rust/fatcat-api-spec/src/mimetypes.rs @@ -500,6 +500,22 @@ pub mod responses { lazy_static! { pub static ref AUTH_OIDC_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetEditgroupsReviewable + lazy_static! { + pub static ref GET_EDITGROUPS_REVIEWABLE_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupsReviewable + lazy_static! { + pub static ref GET_EDITGROUPS_REVIEWABLE_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupsReviewable + lazy_static! { + pub static ref GET_EDITGROUPS_REVIEWABLE_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupsReviewable + lazy_static! { + pub static ref GET_EDITGROUPS_REVIEWABLE_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetEditor lazy_static! { pub static ref GET_EDITOR_FOUND: Mime = mime!(Application / Json); @@ -516,21 +532,45 @@ pub mod responses { lazy_static! { pub static ref GET_EDITOR_GENERIC_ERROR: Mime = mime!(Application / Json); } - /// Create Mime objects for the response content types for GetEditorChangelog + /// Create Mime objects for the response content types for GetEditorEditgroups + lazy_static! { + pub static ref GET_EDITOR_EDITGROUPS_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorEditgroups + lazy_static! { + pub static ref GET_EDITOR_EDITGROUPS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorEditgroups + lazy_static! { + pub static ref GET_EDITOR_EDITGROUPS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorEditgroups + lazy_static! { + pub static ref GET_EDITOR_EDITGROUPS_GENERIC_ERROR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditgroup + lazy_static! { + pub static ref UPDATE_EDITGROUP_UPDATED_EDITGROUP: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditgroup + lazy_static! { + pub static ref UPDATE_EDITGROUP_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditgroup lazy_static! { - pub static ref GET_EDITOR_CHANGELOG_FOUND: Mime = mime!(Application / Json); + pub static ref UPDATE_EDITGROUP_NOT_AUTHORIZED: Mime = mime!(Application / Json); } - /// Create Mime objects for the response content types for GetEditorChangelog + /// Create Mime objects for the response content types for UpdateEditgroup lazy_static! { - pub static ref GET_EDITOR_CHANGELOG_BAD_REQUEST: Mime = mime!(Application / Json); + pub static ref UPDATE_EDITGROUP_FORBIDDEN: Mime = mime!(Application / Json); } - /// Create Mime objects for the response content types for GetEditorChangelog + /// Create Mime objects for the response content types for UpdateEditgroup lazy_static! { - pub static ref GET_EDITOR_CHANGELOG_NOT_FOUND: Mime = mime!(Application / Json); + pub static ref UPDATE_EDITGROUP_NOT_FOUND: Mime = mime!(Application / Json); } - /// Create Mime objects for the response content types for GetEditorChangelog + /// Create Mime objects for the response content types for UpdateEditgroup lazy_static! { - pub static ref GET_EDITOR_CHANGELOG_GENERIC_ERROR: Mime = mime!(Application / Json); + pub static ref UPDATE_EDITGROUP_GENERIC_ERROR: Mime = mime!(Application / Json); } /// Create Mime objects for the response content types for UpdateEditor lazy_static! { @@ -608,6 +648,30 @@ pub mod responses { lazy_static! { pub static ref CREATE_EDITGROUP_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for CreateEditgroupAnnotation + lazy_static! { + pub static ref CREATE_EDITGROUP_ANNOTATION_CREATED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateEditgroupAnnotation + lazy_static! { + pub static ref CREATE_EDITGROUP_ANNOTATION_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateEditgroupAnnotation + lazy_static! { + pub static ref CREATE_EDITGROUP_ANNOTATION_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateEditgroupAnnotation + lazy_static! { + pub static ref CREATE_EDITGROUP_ANNOTATION_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateEditgroupAnnotation + lazy_static! { + pub static ref CREATE_EDITGROUP_ANNOTATION_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateEditgroupAnnotation + lazy_static! { + pub static ref CREATE_EDITGROUP_ANNOTATION_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for GetChangelog lazy_static! { pub static ref GET_CHANGELOG_SUCCESS: Mime = mime!(Application / Json); @@ -652,6 +716,54 @@ pub mod responses { lazy_static! { pub static ref GET_EDITGROUP_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for GetEditgroupAnnotations + lazy_static! { + pub static ref GET_EDITGROUP_ANNOTATIONS_SUCCESS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupAnnotations + lazy_static! { + pub static ref GET_EDITGROUP_ANNOTATIONS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupAnnotations + lazy_static! { + pub static ref GET_EDITGROUP_ANNOTATIONS_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupAnnotations + lazy_static! { + pub static ref GET_EDITGROUP_ANNOTATIONS_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupAnnotations + lazy_static! { + pub static ref GET_EDITGROUP_ANNOTATIONS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditgroupAnnotations + lazy_static! { + pub static ref GET_EDITGROUP_ANNOTATIONS_GENERIC_ERROR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorAnnotations + lazy_static! { + pub static ref GET_EDITOR_ANNOTATIONS_SUCCESS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorAnnotations + lazy_static! { + pub static ref GET_EDITOR_ANNOTATIONS_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorAnnotations + lazy_static! { + pub static ref GET_EDITOR_ANNOTATIONS_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorAnnotations + lazy_static! { + pub static ref GET_EDITOR_ANNOTATIONS_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorAnnotations + lazy_static! { + pub static ref GET_EDITOR_ANNOTATIONS_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditorAnnotations + lazy_static! { + pub static ref GET_EDITOR_ANNOTATIONS_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for CreateFile lazy_static! { pub static ref CREATE_FILE_CREATED_ENTITY: Mime = mime!(Application / Json); @@ -1781,6 +1893,10 @@ pub mod requests { lazy_static! { pub static ref AUTH_OIDC: Mime = mime!(Application / Json); } + /// Create Mime objects for the request content types for UpdateEditgroup + lazy_static! { + pub static ref UPDATE_EDITGROUP: Mime = mime!(Application / Json); + } /// Create Mime objects for the request content types for UpdateEditor lazy_static! { pub static ref UPDATE_EDITOR: Mime = mime!(Application / Json); @@ -1789,6 +1905,10 @@ pub mod requests { lazy_static! { pub static ref CREATE_EDITGROUP: Mime = mime!(Application / Json); } + /// Create Mime objects for the request content types for CreateEditgroupAnnotation + lazy_static! { + pub static ref CREATE_EDITGROUP_ANNOTATION: Mime = mime!(Application / Json); + } /// Create Mime objects for the request content types for CreateFile lazy_static! { pub static ref CREATE_FILE: Mime = mime!(Application / Json); diff --git a/rust/fatcat-api-spec/src/models.rs b/rust/fatcat-api-spec/src/models.rs index a5c588a0..d07aa320 100644 --- a/rust/fatcat-api-spec/src/models.rs +++ b/rust/fatcat-api-spec/src/models.rs @@ -234,6 +234,10 @@ pub struct Editgroup { #[serde(skip_serializing_if = "Option::is_none")] pub editor_id: Option, + #[serde(rename = "submitted")] + #[serde(skip_serializing_if = "Option::is_none")] + pub submitted: Option>, + #[serde(rename = "description")] #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, @@ -242,6 +246,10 @@ pub struct Editgroup { #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, + #[serde(rename = "annotations")] + #[serde(skip_serializing_if = "Option::is_none")] + pub annotations: Option>, + #[serde(rename = "edits")] #[serde(skip_serializing_if = "Option::is_none")] pub edits: Option, @@ -252,13 +260,58 @@ impl Editgroup { Editgroup { editgroup_id: None, editor_id: None, + submitted: None, description: None, extra: None, + annotations: None, edits: None, } } } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct EditgroupAnnotation { + /// UUID (lower-case, dash-separated, hex-encoded 128-bit) + #[serde(rename = "annotation_id")] + #[serde(skip_serializing_if = "Option::is_none")] + pub annotation_id: Option, + + /// base32-encoded unique identifier + #[serde(rename = "editgroup_id")] + #[serde(skip_serializing_if = "Option::is_none")] + pub editgroup_id: Option, + + /// base32-encoded unique identifier + #[serde(rename = "editor_id")] + #[serde(skip_serializing_if = "Option::is_none")] + pub editor_id: Option, + + #[serde(rename = "created")] + #[serde(skip_serializing_if = "Option::is_none")] + pub created: Option>, + + #[serde(rename = "comment_markdown")] + #[serde(skip_serializing_if = "Option::is_none")] + pub comment_markdown: Option, + + #[serde(rename = "extra")] + #[serde(skip_serializing_if = "Option::is_none")] + pub extra: Option, +} + +impl EditgroupAnnotation { + pub fn new() -> EditgroupAnnotation { + EditgroupAnnotation { + annotation_id: None, + editgroup_id: None, + editor_id: None, + created: None, + comment_markdown: None, + extra: None, + } + } +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct EditgroupEdits { #[serde(rename = "containers")] diff --git a/rust/fatcat-api-spec/src/server.rs b/rust/fatcat-api-spec/src/server.rs index 03875a38..8b616959 100644 --- a/rust/fatcat-api-spec/src/server.rs +++ b/rust/fatcat-api-spec/src/server.rs @@ -38,18 +38,18 @@ use swagger::{ApiError, Context, XSpanId}; use models; use { AcceptEditgroupResponse, Api, AuthCheckResponse, AuthOidcResponse, CreateContainerBatchResponse, CreateContainerResponse, CreateCreatorBatchResponse, CreateCreatorResponse, - CreateEditgroupResponse, CreateFileBatchResponse, CreateFileResponse, CreateFilesetBatchResponse, CreateFilesetResponse, CreateReleaseBatchResponse, CreateReleaseResponse, - CreateWebcaptureBatchResponse, CreateWebcaptureResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, DeleteCreatorEditResponse, - DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteFilesetEditResponse, DeleteFilesetResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, + CreateEditgroupAnnotationResponse, CreateEditgroupResponse, CreateFileBatchResponse, CreateFileResponse, CreateFilesetBatchResponse, CreateFilesetResponse, CreateReleaseBatchResponse, + CreateReleaseResponse, CreateWebcaptureBatchResponse, CreateWebcaptureResponse, CreateWorkBatchResponse, CreateWorkResponse, DeleteContainerEditResponse, DeleteContainerResponse, + DeleteCreatorEditResponse, DeleteCreatorResponse, DeleteFileEditResponse, DeleteFileResponse, DeleteFilesetEditResponse, DeleteFilesetResponse, DeleteReleaseEditResponse, DeleteReleaseResponse, DeleteWebcaptureEditResponse, DeleteWebcaptureResponse, DeleteWorkEditResponse, DeleteWorkResponse, GetChangelogEntryResponse, GetChangelogResponse, GetContainerEditResponse, GetContainerHistoryResponse, GetContainerRedirectsResponse, GetContainerResponse, GetContainerRevisionResponse, GetCreatorEditResponse, GetCreatorHistoryResponse, GetCreatorRedirectsResponse, - GetCreatorReleasesResponse, GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupResponse, GetEditorChangelogResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, - GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, - GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, - GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, - GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, - LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, - UpdateWorkResponse, + GetCreatorReleasesResponse, GetCreatorResponse, GetCreatorRevisionResponse, GetEditgroupAnnotationsResponse, GetEditgroupResponse, GetEditgroupsReviewableResponse, GetEditorAnnotationsResponse, + GetEditorEditgroupsResponse, GetEditorResponse, GetFileEditResponse, GetFileHistoryResponse, GetFileRedirectsResponse, GetFileResponse, GetFileRevisionResponse, GetFilesetEditResponse, + GetFilesetHistoryResponse, GetFilesetRedirectsResponse, GetFilesetResponse, GetFilesetRevisionResponse, GetReleaseEditResponse, GetReleaseFilesResponse, GetReleaseFilesetsResponse, + GetReleaseHistoryResponse, GetReleaseRedirectsResponse, GetReleaseResponse, GetReleaseRevisionResponse, GetReleaseWebcapturesResponse, GetWebcaptureEditResponse, GetWebcaptureHistoryResponse, + GetWebcaptureRedirectsResponse, GetWebcaptureResponse, GetWebcaptureRevisionResponse, GetWorkEditResponse, GetWorkHistoryResponse, GetWorkRedirectsResponse, GetWorkReleasesResponse, + GetWorkResponse, GetWorkRevisionResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse, UpdateContainerResponse, UpdateCreatorResponse, + UpdateEditgroupResponse, UpdateEditorResponse, UpdateFileResponse, UpdateFilesetResponse, UpdateReleaseResponse, UpdateWebcaptureResponse, UpdateWorkResponse, }; header! { (Warning, "Warning") => [String] } @@ -2883,6 +2883,87 @@ where "AuthOidc", ); + let api_clone = api.clone(); + router.get( + "/v0/editgroup/reviewable", + 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_expand = query_params.get("expand").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()); + let param_before = query_params.get("before").and_then(|list| list.first()).and_then(|x| x.parse::>().ok()); + let param_since = query_params.get("since").and_then(|list| list.first()).and_then(|x| x.parse::>().ok()); + + match api.get_editgroups_reviewable(param_expand, param_limit, param_before, param_since, context).wait() { + Ok(rsp) => match rsp { + GetEditgroupsReviewableResponse::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_EDITGROUPS_REVIEWABLE_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupsReviewableResponse::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_EDITGROUPS_REVIEWABLE_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupsReviewableResponse::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_EDITGROUPS_REVIEWABLE_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupsReviewableResponse::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_EDITGROUPS_REVIEWABLE_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) + }) + }, + "GetEditgroupsReviewable", + ); + let api_clone = api.clone(); router.get( "/v0/editor/:editor_id", @@ -2974,7 +3055,7 @@ where let api_clone = api.clone(); router.get( - "/v0/editor/:editor_id/changelog", + "/v0/editor/:editor_id/editgroups", move |req: &mut Request| { let mut context = Context::default(); @@ -3002,46 +3083,207 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter editor_id: {}", e))))? }; - match api.get_editor_changelog(param_editor_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_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let param_before = query_params.get("before").and_then(|list| list.first()).and_then(|x| x.parse::>().ok()); + let param_since = query_params.get("since").and_then(|list| list.first()).and_then(|x| x.parse::>().ok()); + + match api.get_editor_editgroups(param_editor_id, param_limit, param_before, param_since, context).wait() { Ok(rsp) => match rsp { - GetEditorChangelogResponse::Found(body) => { + GetEditorEditgroupsResponse::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_EDITOR_CHANGELOG_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_EDITGROUPS_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorChangelogResponse::BadRequest(body) => { + GetEditorEditgroupsResponse::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_EDITOR_EDITGROUPS_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorChangelogResponse::NotFound(body) => { + GetEditorEditgroupsResponse::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_EDITOR_EDITGROUPS_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorChangelogResponse::GenericError(body) => { + GetEditorEditgroupsResponse::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_EDITOR_EDITGROUPS_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) + }) + }, + "GetEditorEditgroups", + ); + + let api_clone = api.clone(); + router.put( + "/v0/editgroup/: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::(); + + let authorization = context.authorization.as_ref().ok_or_else(|| Response::with((status::Forbidden, "Unauthenticated".to_string())))?; + + // Path parameters + let param_editgroup_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("editgroup_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter editgroup_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 editgroup_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_submit = query_params.get("submit").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_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 + }; + let param_editgroup = param_editgroup.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter editgroup".to_string())))?; + + match api.update_editgroup(param_editgroup_id, param_editgroup, param_submit, context).wait() { + Ok(rsp) => match rsp { + UpdateEditgroupResponse::UpdatedEditgroup(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_EDITGROUP_UPDATED_EDITGROUP.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) + } + UpdateEditgroupResponse::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_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) + } + UpdateEditgroupResponse::NotAuthorized { body, www_authenticate } => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(401), body_string)); + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + response.headers.set(ResponseWwwAuthenticate(www_authenticate)); + + response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITGROUP_NOT_AUTHORIZED.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) + } + UpdateEditgroupResponse::Forbidden(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(403), body_string)); + response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITGROUP_FORBIDDEN.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) + } + UpdateEditgroupResponse::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_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) + } + UpdateEditgroupResponse::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_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) } }, @@ -3058,7 +3300,7 @@ where Ok(response) }) }, - "GetEditorChangelog", + "UpdateEditgroup", ); let api_clone = api.clone(); @@ -3473,8 +3715,8 @@ where ); let api_clone = api.clone(); - router.get( - "/v0/changelog", + router.post( + "/v0/editgroup/:editgroup_id/annotation", move |req: &mut Request| { let mut context = Context::default(); @@ -3487,31 +3729,182 @@ 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_limit = query_params.get("limit").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); + let authorization = context.authorization.as_ref().ok_or_else(|| Response::with((status::Forbidden, "Unauthenticated".to_string())))?; - 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"); + // Path parameters + let param_editgroup_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("editgroup_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter editgroup_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 editgroup_id: {}", e))))? + }; - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_SUCCESS.clone())); + // 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. - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let param_annotation = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter annotation - not valid UTF-8: {}", e))))?; - Ok(response) - } - GetChangelogResponse::BadRequest(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(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_BAD_REQUEST.clone())); + let param_annotation = if let Some(param_annotation_raw) = param_annotation { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_annotation_raw); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let param_annotation: 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 annotation - doesn't match schema: {}", e))))?; - Ok(response) + param_annotation + } else { + None + }; + let param_annotation = param_annotation.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter annotation".to_string())))?; + + match api.create_editgroup_annotation(param_editgroup_id, param_annotation, context).wait() { + Ok(rsp) => match rsp { + CreateEditgroupAnnotationResponse::Created(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_ANNOTATION_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) + } + CreateEditgroupAnnotationResponse::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_ANNOTATION_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) + } + CreateEditgroupAnnotationResponse::NotAuthorized { body, www_authenticate } => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(401), body_string)); + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + response.headers.set(ResponseWwwAuthenticate(www_authenticate)); + + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_ANNOTATION_NOT_AUTHORIZED.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) + } + CreateEditgroupAnnotationResponse::Forbidden(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(403), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_ANNOTATION_FORBIDDEN.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) + } + CreateEditgroupAnnotationResponse::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_EDITGROUP_ANNOTATION_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) + } + CreateEditgroupAnnotationResponse::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_ANNOTATION_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) + }) + }, + "CreateEditgroupAnnotation", + ); + + 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) => { + 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::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_CHANGELOG_BAD_REQUEST.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"); @@ -3718,6 +4111,242 @@ where "GetEditgroup", ); + let api_clone = api.clone(); + router.get( + "/v0/editgroup/:editgroup_id/annotations", + 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::(); + + let authorization = context.authorization.as_ref().ok_or_else(|| Response::with((status::Forbidden, "Unauthenticated".to_string())))?; + + // Path parameters + let param_editgroup_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("editgroup_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter editgroup_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 editgroup_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()); + + match api.get_editgroup_annotations(param_editgroup_id, param_expand, context).wait() { + Ok(rsp) => match rsp { + GetEditgroupAnnotationsResponse::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_EDITGROUP_ANNOTATIONS_SUCCESS.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupAnnotationsResponse::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_ANNOTATIONS_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupAnnotationsResponse::NotAuthorized { body, www_authenticate } => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(401), body_string)); + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + response.headers.set(ResponseWwwAuthenticate(www_authenticate)); + + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_ANNOTATIONS_NOT_AUTHORIZED.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupAnnotationsResponse::Forbidden(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(403), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_ANNOTATIONS_FORBIDDEN.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupAnnotationsResponse::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_ANNOTATIONS_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditgroupAnnotationsResponse::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_ANNOTATIONS_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) + }) + }, + "GetEditgroupAnnotations", + ); + + let api_clone = api.clone(); + router.get( + "/v0/editor/:editor_id/annotations", + 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_editor_id = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("editor_id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter editor_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 editor_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_before = query_params.get("before").and_then(|list| list.first()).and_then(|x| x.parse::>().ok()); + let param_since = query_params.get("since").and_then(|list| list.first()).and_then(|x| x.parse::>().ok()); + + match api.get_editor_annotations(param_editor_id, param_limit, param_before, param_since, context).wait() { + Ok(rsp) => match rsp { + GetEditorAnnotationsResponse::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_EDITOR_ANNOTATIONS_SUCCESS.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditorAnnotationsResponse::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_ANNOTATIONS_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditorAnnotationsResponse::NotAuthorized { body, www_authenticate } => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(401), body_string)); + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + response.headers.set(ResponseWwwAuthenticate(www_authenticate)); + + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_ANNOTATIONS_NOT_AUTHORIZED.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditorAnnotationsResponse::Forbidden(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(403), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_ANNOTATIONS_FORBIDDEN.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditorAnnotationsResponse::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_ANNOTATIONS_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetEditorAnnotationsResponse::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_ANNOTATIONS_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) + }) + }, + "GetEditorAnnotations", + ); + let api_clone = api.clone(); router.post( "/v0/file", -- cgit v1.2.3