From eb6993c6cc40e532cb1462e44408ed30db5244c0 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 13 Sep 2019 11:27:09 -0700 Subject: rust codegen This re-ordered a lot of code, because several endpoints had their tags changed, but should be no actual change in behavior/spec. --- rust/fatcat-openapi/src/client.rs | 1502 ++++++++++---------- rust/fatcat-openapi/src/lib.rs | 432 +++--- rust/fatcat-openapi/src/mimetypes.rs | 420 +++--- rust/fatcat-openapi/src/models.rs | 173 ++- rust/fatcat-openapi/src/server.rs | 2540 +++++++++++++++++----------------- 5 files changed, 2589 insertions(+), 2478 deletions(-) (limited to 'rust/fatcat-openapi/src') diff --git a/rust/fatcat-openapi/src/client.rs b/rust/fatcat-openapi/src/client.rs index 378c546f..65bf67a5 100644 --- a/rust/fatcat-openapi/src/client.rs +++ b/rust/fatcat-openapi/src/client.rs @@ -173,42 +173,36 @@ impl Client { } impl Api for Client { - fn create_container(&self, param_editgroup_id: String, param_entity: models::ContainerEntity, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}/container", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + fn auth_check(&self, param_role: Option, context: &Context) -> Box + Send> { + // Query parameters + let query_role = param_role.map_or_else(String::new, |query| format!("role={role}&", role = query.to_string())); - let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); + let url = format!("{}/v0/auth/check?{role}", self.base_path, role = utf8_percent_encode(&query_role, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Post, &url); + let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 201 => { + 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(CreateContainerResponse::CreatedEntity(body)) + Ok(AuthCheckResponse::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(CreateContainerResponse::BadRequest(body)) + Ok(AuthCheckResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -220,7 +214,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(CreateContainerResponse::NotAuthorized { + Ok(AuthCheckResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -230,21 +224,14 @@ 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(CreateContainerResponse::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(CreateContainerResponse::NotFound(body)) + Ok(AuthCheckResponse::Forbidden(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(CreateContainerResponse::GenericError(body)) + Ok(AuthCheckResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -264,10 +251,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn create_container_auto_batch(&self, param_auto_batch: models::ContainerAutoBatch, context: &Context) -> Box + Send> { - let url = format!("{}/v0/editgroup/auto/container/batch", self.base_path); + fn auth_oidc(&self, param_oidc_params: models::AuthOidc, context: &Context) -> Box + Send> { + let url = format!("{}/v0/auth/oidc", self.base_path); - let body = serde_json::to_string(¶m_auto_batch).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_oidc_params).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -275,27 +262,34 @@ impl Api for Client { let request = request.body(&body); - custom_headers.set(ContentType(mimetypes::requests::CREATE_CONTAINER_AUTO_BATCH.clone())); + custom_headers.set(ContentType(mimetypes::requests::AUTH_OIDC.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { + 200 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(AuthOidcResponse::Found(body)) + } 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(CreateContainerAutoBatchResponse::CreatedEditgroup(body)) + Ok(AuthOidcResponse::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(CreateContainerAutoBatchResponse::BadRequest(body)) + Ok(AuthOidcResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -307,7 +301,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(CreateContainerAutoBatchResponse::NotAuthorized { + Ok(AuthOidcResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -317,21 +311,21 @@ 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(CreateContainerAutoBatchResponse::Forbidden(body)) + Ok(AuthOidcResponse::Forbidden(body)) } - 404 => { + 409 => { 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(CreateContainerAutoBatchResponse::NotFound(body)) + Ok(AuthOidcResponse::Conflict(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(CreateContainerAutoBatchResponse::GenericError(body)) + Ok(AuthOidcResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -351,16 +345,14 @@ impl Api for Client { Box::new(futures::done(result)) } - fn delete_container(&self, param_editgroup_id: String, param_ident: String, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}/container/{ident}", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), - ident = utf8_percent_encode(¶m_ident.to_string(), PATH_SEGMENT_ENCODE_SET) - ); + 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())); + + let url = format!("{}/v0/changelog?{limit}", self.base_path, limit = utf8_percent_encode(&query_limit, QUERY_ENCODE_SET)); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Delete, &url); + 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()))); @@ -368,57 +360,92 @@ 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(DeleteContainerResponse::DeletedEntity(body)) + Ok(GetChangelogResponse::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(DeleteContainerResponse::BadRequest(body)) + Ok(GetChangelogResponse::BadRequest(body)) } - 401 => { + 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)?; - 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(DeleteContainerResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) + Ok(GetChangelogResponse::GenericError(body)) } - 403 => { + 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_entry(&self, param_index: i64, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/changelog/{index}", + self.base_path, + index = utf8_percent_encode(¶m_index.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(GetChangelogEntryResponse::FoundChangelogEntry(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(DeleteContainerResponse::Forbidden(body)) + Ok(GetChangelogEntryResponse::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(DeleteContainerResponse::NotFound(body)) + Ok(GetChangelogEntryResponse::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(DeleteContainerResponse::GenericError(body)) + Ok(GetChangelogEntryResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -438,38 +465,42 @@ impl Api for Client { Box::new(futures::done(result)) } - fn delete_container_edit(&self, param_editgroup_id: String, param_edit_id: String, context: &Context) -> Box + Send> { + fn create_container(&self, param_editgroup_id: String, param_entity: models::ContainerEntity, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/editgroup/{editgroup_id}/container/edit/{edit_id}", + "{}/v0/editgroup/{editgroup_id}/container", self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), - edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); + let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Delete, &url); + 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_CONTAINER.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 200 => { + 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(DeleteContainerEditResponse::DeletedEdit(body)) + Ok(CreateContainerResponse::CreatedEntity(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)) + Ok(CreateContainerResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -481,7 +512,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(DeleteContainerEditResponse::NotAuthorized { + Ok(CreateContainerResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -491,21 +522,21 @@ 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(DeleteContainerEditResponse::Forbidden(body)) + Ok(CreateContainerResponse::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(DeleteContainerEditResponse::NotFound(body)) + Ok(CreateContainerResponse::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)) + Ok(CreateContainerResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -525,57 +556,74 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_container(&self, param_ident: 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())); + fn create_container_auto_batch(&self, param_auto_batch: models::ContainerAutoBatch, context: &Context) -> Box + Send> { + let url = format!("{}/v0/editgroup/auto/container/batch", self.base_path); - let url = format!( - "{}/v0/container/{ident}?{expand}{hide}", - self.base_path, - ident = utf8_percent_encode(¶m_ident.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 body = serde_json::to_string(¶m_auto_batch).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + 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_CONTAINER_AUTO_BATCH.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 200 => { + 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetContainerResponse::FoundEntity(body)) + Ok(CreateContainerAutoBatchResponse::CreatedEditgroup(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(GetContainerResponse::BadRequest(body)) + Ok(CreateContainerAutoBatchResponse::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(CreateContainerAutoBatchResponse::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(CreateContainerAutoBatchResponse::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(GetContainerResponse::NotFound(body)) + Ok(CreateContainerAutoBatchResponse::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(GetContainerResponse::GenericError(body)) + Ok(CreateContainerAutoBatchResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -595,15 +643,16 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_container_edit(&self, param_edit_id: String, context: &Context) -> Box + Send> { + fn delete_container(&self, param_editgroup_id: String, param_ident: String, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/container/edit/{edit_id}", + "{}/v0/editgroup/{editgroup_id}/container/{ident}", self.base_path, - edit_id = utf8_percent_encode(¶m_edit_id.to_string(), PATH_SEGMENT_ENCODE_SET) + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), + ident = utf8_percent_encode(¶m_ident.to_string(), PATH_SEGMENT_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + 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()))); @@ -611,14 +660,257 @@ 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(GetContainerEditResponse::FoundEdit(body)) + Ok(DeleteContainerResponse::DeletedEntity(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(DeleteContainerResponse::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(DeleteContainerResponse::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(DeleteContainerResponse::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(DeleteContainerResponse::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(DeleteContainerResponse::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 delete_container_edit(&self, param_editgroup_id: String, param_edit_id: String, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/container/edit/{edit_id}", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET), + 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)) + } + 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(DeleteContainerEditResponse::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(DeleteContainerEditResponse::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(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_ident: 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/container/{ident}?{expand}{hide}", + self.base_path, + ident = utf8_percent_encode(¶m_ident.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(GetContainerResponse::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(GetContainerResponse::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(GetContainerResponse::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(GetContainerResponse::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_edit(&self, param_edit_id: String, 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(); @@ -1985,14 +2277,15 @@ impl Api for Client { Box::new(futures::done(result)) } - fn auth_check(&self, param_role: Option, context: &Context) -> Box + Send> { - // Query parameters - let query_role = param_role.map_or_else(String::new, |query| format!("role={role}&", role = query.to_string())); - - let url = format!("{}/v0/auth/check?{role}", self.base_path, role = utf8_percent_encode(&query_role, QUERY_ENCODE_SET)); + fn accept_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/accept", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + let request = hyper_client.request(hyper::method::Method::Post, &url); let mut custom_headers = hyper::header::Headers::new(); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); @@ -2000,21 +2293,21 @@ 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(AuthCheckResponse::Success(body)) + Ok(AcceptEditgroupResponse::MergedSuccessfully(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(AuthCheckResponse::BadRequest(body)) + Ok(AcceptEditgroupResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -2026,7 +2319,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(AuthCheckResponse::NotAuthorized { + Ok(AcceptEditgroupResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -2036,14 +2329,28 @@ 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(AuthCheckResponse::Forbidden(body)) + Ok(AcceptEditgroupResponse::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(AcceptEditgroupResponse::NotFound(body)) + } + 409 => { + 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(AcceptEditgroupResponse::EditConflict(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(AuthCheckResponse::GenericError(body)) + Ok(AcceptEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2063,10 +2370,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn auth_oidc(&self, param_oidc_params: models::AuthOidc, context: &Context) -> Box + Send> { - let url = format!("{}/v0/auth/oidc", self.base_path); + fn create_editgroup(&self, param_editgroup: models::Editgroup, context: &Context) -> Box + Send> { + let url = format!("{}/v0/editgroup", self.base_path); - let body = serde_json::to_string(¶m_oidc_params).expect("impossible to fail to serialize"); + 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::Post, &url); @@ -2074,34 +2381,123 @@ impl Api for Client { let request = request.body(&body); - custom_headers.set(ContentType(mimetypes::requests::AUTH_OIDC.clone())); + custom_headers.set(ContentType(mimetypes::requests::CREATE_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 { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { - 200 => { + 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)?; + let body = serde_json::from_str::(&buf)?; - Ok(AuthOidcResponse::Found(body)) + Ok(CreateEditgroupResponse::SuccessfullyCreated(body)) + } + 400 => { + let mut buf = String::new(); + response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; + let body = serde_json::from_str::(&buf)?; + + Ok(CreateEditgroupResponse::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(CreateEditgroupResponse::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(CreateEditgroupResponse::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(CreateEditgroupResponse::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(CreateEditgroupResponse::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_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)?; + let body = serde_json::from_str::(&buf)?; - Ok(AuthOidcResponse::Created(body)) + 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(AuthOidcResponse::BadRequest(body)) + Ok(CreateEditgroupAnnotationResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -2113,7 +2509,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(AuthOidcResponse::NotAuthorized { + Ok(CreateEditgroupAnnotationResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -2123,21 +2519,21 @@ 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(AuthOidcResponse::Forbidden(body)) + Ok(CreateEditgroupAnnotationResponse::Forbidden(body)) } - 409 => { + 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(AuthOidcResponse::Conflict(body)) + 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(AuthOidcResponse::GenericError(body)) + Ok(CreateEditgroupAnnotationResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2157,27 +2553,11 @@ 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())); - + fn get_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/editgroup/reviewable?{expand}{limit}{before}{since}", + "{}/v0/editgroup/{editgroup_id}", 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) + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); let hyper_client = (self.hyper_client)(); @@ -2189,35 +2569,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(GetEditgroupsReviewableResponse::Found(body)) + Ok(GetEditgroupResponse::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)) + Ok(GetEditgroupResponse::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)) + Ok(GetEditgroupResponse::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)) + Ok(GetEditgroupResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2237,11 +2617,15 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_editor(&self, param_editor_id: String, context: &Context) -> Box + Send> { + 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/editor/{editor_id}", + "{}/v0/editgroup/{editgroup_id}/annotations?{expand}", self.base_path, - editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET) + 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)(); @@ -2253,35 +2637,57 @@ 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(GetEditorResponse::Found(body)) + 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(GetEditorResponse::BadRequest(body)) + 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(GetEditorResponse::NotFound(body)) + 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(GetEditorResponse::GenericError(body)) + Ok(GetEditgroupAnnotationsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2301,23 +2707,24 @@ impl Api for Client { Box::new(futures::done(result)) } - fn get_editor_editgroups( + fn get_editgroups_reviewable( &self, - param_editor_id: String, + param_expand: Option, param_limit: Option, param_before: Option>, param_since: Option>, context: &Context, - ) -> Box + Send> { + ) -> 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/editor/{editor_id}/editgroups?{limit}{before}{since}", + "{}/v0/editgroup/reviewable?{expand}{limit}{before}{since}", self.base_path, - editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET), + 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) @@ -2332,35 +2739,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)?; - Ok(GetEditorEditgroupsResponse::Found(body)) + 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(GetEditorEditgroupsResponse::BadRequest(body)) + 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(GetEditorEditgroupsResponse::NotFound(body)) + 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(GetEditorEditgroupsResponse::GenericError(body)) + Ok(GetEditgroupsReviewableResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2481,78 +2888,51 @@ impl Api for Client { Box::new(futures::done(result)) } - fn update_editor(&self, param_editor_id: String, param_editor: models::Editor, context: &Context) -> Box + Send> { + fn get_editor(&self, param_editor_id: String, context: &Context) -> Box + Send> { let url = format!( "{}/v0/editor/{editor_id}", self.base_path, editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); - let body = serde_json::to_string(¶m_editor).expect("impossible to fail to serialize"); - let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Put, &url); + let request = hyper_client.request(hyper::method::Method::Get, &url); let mut custom_headers = hyper::header::Headers::new(); - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::UPDATE_EDITOR.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; let body = serde_json::from_str::(&buf)?; - Ok(UpdateEditorResponse::UpdatedEditor(body)) + Ok(GetEditorResponse::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(UpdateEditorResponse::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(UpdateEditorResponse::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(UpdateEditorResponse::Forbidden(body)) + Ok(GetEditorResponse::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(UpdateEditorResponse::NotFound(body)) + Ok(GetEditorResponse::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(UpdateEditorResponse::GenericError(body)) + Ok(GetEditorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2572,15 +2952,30 @@ impl Api for Client { Box::new(futures::done(result)) } - fn accept_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { + 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/editgroup/{editgroup_id}/accept", + "{}/v0/editor/{editor_id}/annotations?{limit}{before}{since}", self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_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)(); - let request = hyper_client.request(hyper::method::Method::Post, &url); + 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()))); @@ -2588,115 +2983,21 @@ 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(AcceptEditgroupResponse::MergedSuccessfully(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(AcceptEditgroupResponse::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(AcceptEditgroupResponse::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(AcceptEditgroupResponse::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(AcceptEditgroupResponse::NotFound(body)) - } - 409 => { - 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(AcceptEditgroupResponse::EditConflict(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(AcceptEditgroupResponse::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_editgroup(&self, param_editgroup: models::Editgroup, context: &Context) -> Box + Send> { - let url = format!("{}/v0/editgroup", self.base_path); - - 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::Post, &url); - let mut custom_headers = hyper::header::Headers::new(); - - let request = request.body(&body); - - custom_headers.set(ContentType(mimetypes::requests::CREATE_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() { - 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)?; + let body = serde_json::from_str::>(&buf)?; - Ok(CreateEditgroupResponse::SuccessfullyCreated(body)) + 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(CreateEditgroupResponse::BadRequest(body)) + Ok(GetEditorAnnotationsResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -2708,7 +3009,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(CreateEditgroupResponse::NotAuthorized { + Ok(GetEditorAnnotationsResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -2718,21 +3019,21 @@ 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(CreateEditgroupResponse::Forbidden(body)) + 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(CreateEditgroupResponse::NotFound(body)) + 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(CreateEditgroupResponse::GenericError(body)) + Ok(GetEditorAnnotationsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -2752,357 +3053,66 @@ impl Api for Client { Box::new(futures::done(result)) } - fn create_editgroup_annotation( + fn get_editor_editgroups( &self, - param_editgroup_id: String, - param_annotation: models::EditgroupAnnotation, + param_editor_id: String, + param_limit: Option, + param_before: Option>, + param_since: Option>, 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> { + ) -> 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/changelog?{limit}", self.base_path, 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(GetChangelogResponse::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(GetChangelogResponse::BadRequest(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(GetChangelogResponse::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_entry(&self, param_index: i64, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/changelog/{index}", - self.base_path, - index = utf8_percent_encode(¶m_index.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(GetChangelogEntryResponse::FoundChangelogEntry(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(GetChangelogEntryResponse::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(GetChangelogEntryResponse::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(GetChangelogEntryResponse::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_editgroup(&self, param_editgroup_id: String, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_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(GetEditgroupResponse::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(GetEditgroupResponse::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(GetEditgroupResponse::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(GetEditgroupResponse::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_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 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/{editgroup_id}/annotations?{expand}", + "{}/v0/editor/{editor_id}/editgroups?{limit}{before}{since}", 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) + 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(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)?; + context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); - Ok(GetEditgroupAnnotationsResponse::BadRequest(body)) - } - 401 => { + 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)?; - 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.")?; + let body = serde_json::from_str::>(&buf)?; - Ok(GetEditgroupAnnotationsResponse::NotAuthorized { - body: body, - www_authenticate: response_www_authenticate.0.clone(), - }) + Ok(GetEditorEditgroupsResponse::Found(body)) } - 403 => { + 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::Forbidden(body)) + 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(GetEditgroupAnnotationsResponse::NotFound(body)) + 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(GetEditgroupAnnotationsResponse::GenericError(body)) + Ok(GetEditorEditgroupsResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -3122,52 +3132,42 @@ impl Api for Client { 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())); - + fn update_editor(&self, param_editor_id: String, param_editor: models::Editor, context: &Context) -> Box + Send> { let url = format!( - "{}/v0/editor/{editor_id}/annotations?{limit}{before}{since}", + "{}/v0/editor/{editor_id}", 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) + editor_id = utf8_percent_encode(¶m_editor_id.to_string(), PATH_SEGMENT_ENCODE_SET) ); + let body = serde_json::to_string(¶m_editor).expect("impossible to fail to serialize"); + let hyper_client = (self.hyper_client)(); - let request = hyper_client.request(hyper::method::Method::Get, &url); + let request = hyper_client.request(hyper::method::Method::Put, &url); let mut custom_headers = hyper::header::Headers::new(); + let request = request.body(&body); + + custom_headers.set(ContentType(mimetypes::requests::UPDATE_EDITOR.clone())); context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone()))); let request = request.headers(custom_headers); // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn parse_response(mut response: hyper::client::response::Response) -> Result { + fn parse_response(mut response: hyper::client::response::Response) -> Result { match response.status.to_u16() { 200 => { let mut buf = String::new(); response.read_to_string(&mut buf).map_err(|e| ApiError(format!("Response was not valid UTF8: {}", e)))?; - let body = serde_json::from_str::>(&buf)?; + let body = serde_json::from_str::(&buf)?; - Ok(GetEditorAnnotationsResponse::Success(body)) + Ok(UpdateEditorResponse::UpdatedEditor(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)) + Ok(UpdateEditorResponse::BadRequest(body)) } 401 => { let mut buf = String::new(); @@ -3179,7 +3179,7 @@ impl Api for Client { .get::() .ok_or_else(|| "Required response header WWW_Authenticate for response 401 was not found.")?; - Ok(GetEditorAnnotationsResponse::NotAuthorized { + Ok(UpdateEditorResponse::NotAuthorized { body: body, www_authenticate: response_www_authenticate.0.clone(), }) @@ -3189,21 +3189,21 @@ 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(GetEditorAnnotationsResponse::Forbidden(body)) + Ok(UpdateEditorResponse::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)) + Ok(UpdateEditorResponse::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)) + Ok(UpdateEditorResponse::GenericError(body)) } code => { let mut buf = [0; 100]; @@ -5062,97 +5062,6 @@ impl Api for Client { Box::new(futures::done(result)) } - fn create_work(&self, param_editgroup_id: String, param_entity: models::WorkEntity, context: &Context) -> Box + Send> { - let url = format!( - "{}/v0/editgroup/{editgroup_id}/work", - self.base_path, - editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) - ); - - let body = serde_json::to_string(¶m_entity).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_WORK.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(CreateWorkResponse::CreatedEntity(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(CreateWorkResponse::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(CreateWorkResponse::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(CreateWorkResponse::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(CreateWorkResponse::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(CreateWorkResponse::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 delete_release(&self, param_editgroup_id: String, param_ident: String, context: &Context) -> Box + Send> { let url = format!( "{}/v0/editgroup/{editgroup_id}/release/{ident}", @@ -6867,6 +6776,97 @@ impl Api for Client { Box::new(futures::done(result)) } + fn create_work(&self, param_editgroup_id: String, param_entity: models::WorkEntity, context: &Context) -> Box + Send> { + let url = format!( + "{}/v0/editgroup/{editgroup_id}/work", + self.base_path, + editgroup_id = utf8_percent_encode(¶m_editgroup_id.to_string(), PATH_SEGMENT_ENCODE_SET) + ); + + let body = serde_json::to_string(¶m_entity).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_WORK.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(CreateWorkResponse::CreatedEntity(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(CreateWorkResponse::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(CreateWorkResponse::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(CreateWorkResponse::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(CreateWorkResponse::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(CreateWorkResponse::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_work_auto_batch(&self, param_auto_batch: models::WorkAutoBatch, context: &Context) -> Box + Send> { let url = format!("{}/v0/editgroup/auto/work/batch", self.base_path); diff --git a/rust/fatcat-openapi/src/lib.rs b/rust/fatcat-openapi/src/lib.rs index b19b5793..da4f23af 100644 --- a/rust/fatcat-openapi/src/lib.rs +++ b/rust/fatcat-openapi/src/lib.rs @@ -32,6 +32,60 @@ mod mimetypes; pub use swagger::{ApiError, Context, ContextWrapper}; +#[derive(Debug, PartialEq)] +pub enum AuthCheckResponse { + /// Success + Success(models::Success), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Authorized + NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, + /// Forbidden + Forbidden(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum AuthOidcResponse { + /// Found + Found(models::AuthOidcResult), + /// Created + Created(models::AuthOidcResult), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Authorized + NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, + /// Forbidden + Forbidden(models::ErrorResponse), + /// Conflict + Conflict(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum GetChangelogResponse { + /// Success + Success(Vec), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + +#[derive(Debug, PartialEq)] +pub enum GetChangelogEntryResponse { + /// Found Changelog Entry + FoundChangelogEntry(models::ChangelogEntry), + /// Bad Request + BadRequest(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Generic Error + GenericError(models::ErrorResponse), +} + #[derive(Debug, PartialEq)] pub enum CreateContainerResponse { /// Created Entity @@ -349,43 +403,33 @@ pub enum UpdateCreatorResponse { } #[derive(Debug, PartialEq)] -pub enum AuthCheckResponse { - /// Success - Success(models::Success), +pub enum AcceptEditgroupResponse { + /// Merged Successfully + MergedSuccessfully(models::Success), /// Bad Request BadRequest(models::ErrorResponse), /// Not Authorized NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, /// Forbidden Forbidden(models::ErrorResponse), + /// Not Found + NotFound(models::ErrorResponse), + /// Edit Conflict + EditConflict(models::ErrorResponse), /// Generic Error GenericError(models::ErrorResponse), } #[derive(Debug, PartialEq)] -pub enum AuthOidcResponse { - /// Found - Found(models::AuthOidcResult), - /// Created - Created(models::AuthOidcResult), +pub enum CreateEditgroupResponse { + /// Successfully Created + SuccessfullyCreated(models::Editgroup), /// Bad Request BadRequest(models::ErrorResponse), /// Not Authorized NotAuthorized { body: models::ErrorResponse, www_authenticate: String }, /// Forbidden Forbidden(models::ErrorResponse), - /// Conflict - Conflict(models::ErrorResponse), - /// Generic Error - GenericError(models::ErrorResponse), -} - -#[derive(Debug, PartialEq)] -pub enum GetEditgroupsReviewableResponse { - /// Found - Found(Vec), - /// Bad Request - BadRequest(models::ErrorResponse), /// Not Found NotFound(models::ErrorResponse), /// Generic Error @@ -393,11 +437,15 @@ pub enum GetEditgroupsReviewableResponse { } #[derive(Debug, PartialEq)] -pub enum GetEditorResponse { - /// Found - Found(models::Editor), +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 @@ -405,9 +453,9 @@ pub enum GetEditorResponse { } #[derive(Debug, PartialEq)] -pub enum GetEditorEditgroupsResponse { +pub enum GetEditgroupResponse { /// Found - Found(Vec), + Found(models::Editgroup), /// Bad Request BadRequest(models::ErrorResponse), /// Not Found @@ -417,9 +465,9 @@ pub enum GetEditorEditgroupsResponse { } #[derive(Debug, PartialEq)] -pub enum UpdateEditgroupResponse { - /// Updated Editgroup - UpdatedEditgroup(models::Editgroup), +pub enum GetEditgroupAnnotationsResponse { + /// Success + Success(Vec), /// Bad Request BadRequest(models::ErrorResponse), /// Not Authorized @@ -433,15 +481,11 @@ pub enum UpdateEditgroupResponse { } #[derive(Debug, PartialEq)] -pub enum UpdateEditorResponse { - /// Updated Editor - UpdatedEditor(models::Editor), +pub enum GetEditgroupsReviewableResponse { + /// Found + Found(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 @@ -449,9 +493,9 @@ pub enum UpdateEditorResponse { } #[derive(Debug, PartialEq)] -pub enum AcceptEditgroupResponse { - /// Merged Successfully - MergedSuccessfully(models::Success), +pub enum UpdateEditgroupResponse { + /// Updated Editgroup + UpdatedEditgroup(models::Editgroup), /// Bad Request BadRequest(models::ErrorResponse), /// Not Authorized @@ -460,22 +504,16 @@ pub enum AcceptEditgroupResponse { Forbidden(models::ErrorResponse), /// Not Found NotFound(models::ErrorResponse), - /// Edit Conflict - EditConflict(models::ErrorResponse), /// Generic Error GenericError(models::ErrorResponse), } #[derive(Debug, PartialEq)] -pub enum CreateEditgroupResponse { - /// Successfully Created - SuccessfullyCreated(models::Editgroup), +pub enum GetEditorResponse { + /// Found + Found(models::Editor), /// 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 @@ -483,9 +521,9 @@ pub enum CreateEditgroupResponse { } #[derive(Debug, PartialEq)] -pub enum CreateEditgroupAnnotationResponse { - /// Created - Created(models::EditgroupAnnotation), +pub enum GetEditorAnnotationsResponse { + /// Success + Success(Vec), /// Bad Request BadRequest(models::ErrorResponse), /// Not Authorized @@ -499,31 +537,9 @@ pub enum CreateEditgroupAnnotationResponse { } #[derive(Debug, PartialEq)] -pub enum GetChangelogResponse { - /// Success - Success(Vec), - /// Bad Request - BadRequest(models::ErrorResponse), - /// Generic Error - GenericError(models::ErrorResponse), -} - -#[derive(Debug, PartialEq)] -pub enum GetChangelogEntryResponse { - /// Found Changelog Entry - FoundChangelogEntry(models::ChangelogEntry), - /// Bad Request - BadRequest(models::ErrorResponse), - /// Not Found - NotFound(models::ErrorResponse), - /// Generic Error - GenericError(models::ErrorResponse), -} - -#[derive(Debug, PartialEq)] -pub enum GetEditgroupResponse { +pub enum GetEditorEditgroupsResponse { /// Found - Found(models::Editgroup), + Found(Vec), /// Bad Request BadRequest(models::ErrorResponse), /// Not Found @@ -533,25 +549,9 @@ pub enum GetEditgroupResponse { } #[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), +pub enum UpdateEditorResponse { + /// Updated Editor + UpdatedEditor(models::Editor), /// Bad Request BadRequest(models::ErrorResponse), /// Not Authorized @@ -888,22 +888,6 @@ pub enum CreateReleaseAutoBatchResponse { GenericError(models::ErrorResponse), } -#[derive(Debug, PartialEq)] -pub enum CreateWorkResponse { - /// Created Entity - CreatedEntity(models::EntityEdit), - /// 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 DeleteReleaseResponse { /// Deleted Entity @@ -1200,6 +1184,22 @@ pub enum UpdateWebcaptureResponse { GenericError(models::ErrorResponse), } +#[derive(Debug, PartialEq)] +pub enum CreateWorkResponse { + /// Created Entity + CreatedEntity(models::EntityEdit), + /// 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 CreateWorkAutoBatchResponse { /// Created Editgroup @@ -1338,6 +1338,14 @@ pub enum UpdateWorkResponse { /// API pub trait Api { + fn auth_check(&self, role: Option, context: &Context) -> Box + Send>; + + fn auth_oidc(&self, oidc_params: models::AuthOidc, 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 create_container(&self, editgroup_id: String, entity: models::ContainerEntity, context: &Context) -> Box + Send>; fn create_container_auto_batch(&self, auto_batch: models::ContainerAutoBatch, context: &Context) -> Box + Send>; @@ -1398,9 +1406,20 @@ pub trait Api { fn update_creator(&self, editgroup_id: String, ident: String, entity: models::CreatorEntity, context: &Context) -> Box + Send>; - fn auth_check(&self, role: Option, context: &Context) -> Box + Send>; + fn accept_editgroup(&self, editgroup_id: String, context: &Context) -> Box + Send>; - fn auth_oidc(&self, oidc_params: models::AuthOidc, context: &Context) -> Box + Send>; + 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_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_editgroups_reviewable( &self, @@ -1411,48 +1430,29 @@ pub trait Api { context: &Context, ) -> Box + Send>; + fn update_editgroup(&self, editgroup_id: String, editgroup: models::Editgroup, submit: Option, context: &Context) -> Box + Send>; + fn get_editor(&self, editor_id: String, context: &Context) -> Box + Send>; - fn get_editor_editgroups( + fn get_editor_annotations( &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>; - - fn accept_editgroup(&self, editgroup_id: String, context: &Context) -> Box + Send>; - - 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>; + ) -> Box + Send>; - fn get_editor_annotations( + fn get_editor_editgroups( &self, editor_id: String, limit: Option, before: Option>, since: Option>, context: &Context, - ) -> Box + Send>; + ) -> Box + Send>; + + fn update_editor(&self, editor_id: String, editor: models::Editor, context: &Context) -> Box + Send>; fn create_file(&self, editgroup_id: String, entity: models::FileEntity, context: &Context) -> Box + Send>; @@ -1508,8 +1508,6 @@ pub trait Api { fn create_release_auto_batch(&self, auto_batch: models::ReleaseAutoBatch, context: &Context) -> Box + Send>; - fn create_work(&self, editgroup_id: String, entity: models::WorkEntity, context: &Context) -> Box + Send>; - fn delete_release(&self, editgroup_id: String, ident: String, context: &Context) -> Box + Send>; fn delete_release_edit(&self, editgroup_id: String, edit_id: String, context: &Context) -> Box + Send>; @@ -1569,6 +1567,8 @@ pub trait Api { fn update_webcapture(&self, editgroup_id: String, ident: String, entity: models::WebcaptureEntity, context: &Context) -> Box + Send>; + fn create_work(&self, editgroup_id: String, entity: models::WorkEntity, context: &Context) -> Box + Send>; + fn create_work_auto_batch(&self, auto_batch: models::WorkAutoBatch, context: &Context) -> Box + Send>; fn delete_work(&self, editgroup_id: String, ident: String, context: &Context) -> Box + Send>; @@ -1592,6 +1592,14 @@ pub trait Api { /// API without a `Context` pub trait ApiNoContext { + fn auth_check(&self, role: Option) -> Box + Send>; + + fn auth_oidc(&self, oidc_params: models::AuthOidc) -> Box + Send>; + + fn get_changelog(&self, limit: Option) -> Box + Send>; + + fn get_changelog_entry(&self, index: i64) -> Box + Send>; + fn create_container(&self, editgroup_id: String, entity: models::ContainerEntity) -> Box + Send>; fn create_container_auto_batch(&self, auto_batch: models::ContainerAutoBatch) -> Box + Send>; @@ -1644,9 +1652,15 @@ pub trait ApiNoContext { fn update_creator(&self, editgroup_id: String, ident: String, entity: models::CreatorEntity) -> Box + Send>; - fn auth_check(&self, role: Option) -> Box + Send>; + fn accept_editgroup(&self, editgroup_id: String) -> Box + Send>; - fn auth_oidc(&self, oidc_params: models::AuthOidc) -> Box + Send>; + fn create_editgroup(&self, editgroup: models::Editgroup) -> Box + Send>; + + fn create_editgroup_annotation(&self, editgroup_id: String, annotation: models::EditgroupAnnotation) -> 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_editgroups_reviewable( &self, @@ -1656,41 +1670,27 @@ pub trait ApiNoContext { since: Option>, ) -> Box + Send>; + fn update_editgroup(&self, editgroup_id: String, editgroup: models::Editgroup, submit: Option) -> Box + Send>; + fn get_editor(&self, editor_id: String) -> Box + Send>; - fn get_editor_editgroups( + fn get_editor_annotations( &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>; - - fn accept_editgroup(&self, editgroup_id: String) -> Box + Send>; - - 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>; + ) -> Box + Send>; - fn get_editor_annotations( + fn get_editor_editgroups( &self, editor_id: String, limit: Option, before: Option>, since: Option>, - ) -> Box + Send>; + ) -> Box + Send>; + + fn update_editor(&self, editor_id: String, editor: models::Editor) -> Box + Send>; fn create_file(&self, editgroup_id: String, entity: models::FileEntity) -> Box + Send>; @@ -1745,8 +1745,6 @@ pub trait ApiNoContext { fn create_release_auto_batch(&self, auto_batch: models::ReleaseAutoBatch) -> Box + Send>; - fn create_work(&self, editgroup_id: String, entity: models::WorkEntity) -> Box + Send>; - fn delete_release(&self, editgroup_id: String, ident: String) -> Box + Send>; fn delete_release_edit(&self, editgroup_id: String, edit_id: String) -> Box + Send>; @@ -1805,6 +1803,8 @@ pub trait ApiNoContext { fn update_webcapture(&self, editgroup_id: String, ident: String, entity: models::WebcaptureEntity) -> Box + Send>; + fn create_work(&self, editgroup_id: String, entity: models::WorkEntity) -> Box + Send>; + fn create_work_auto_batch(&self, auto_batch: models::WorkAutoBatch) -> Box + Send>; fn delete_work(&self, editgroup_id: String, ident: String) -> Box + Send>; @@ -1842,6 +1842,22 @@ impl<'a, T: Api + Sized> ContextWrapperExt<'a> for T { } impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { + fn auth_check(&self, role: Option) -> Box + Send> { + self.api().auth_check(role, &self.context()) + } + + fn auth_oidc(&self, oidc_params: models::AuthOidc) -> Box + Send> { + self.api().auth_oidc(oidc_params, &self.context()) + } + + fn get_changelog(&self, limit: Option) -> Box + Send> { + self.api().get_changelog(limit, &self.context()) + } + + fn get_changelog_entry(&self, index: i64) -> Box + Send> { + self.api().get_changelog_entry(index, &self.context()) + } + fn create_container(&self, editgroup_id: String, entity: models::ContainerEntity) -> Box + Send> { self.api().create_container(editgroup_id, entity, &self.context()) } @@ -1940,12 +1956,24 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().update_creator(editgroup_id, ident, entity, &self.context()) } - fn auth_check(&self, role: Option) -> Box + Send> { - self.api().auth_check(role, &self.context()) + fn accept_editgroup(&self, editgroup_id: String) -> Box + Send> { + self.api().accept_editgroup(editgroup_id, &self.context()) } - fn auth_oidc(&self, oidc_params: models::AuthOidc) -> Box + Send> { - self.api().auth_oidc(oidc_params, &self.context()) + fn create_editgroup(&self, editgroup: models::Editgroup) -> Box + Send> { + 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_editgroup(&self, editgroup_id: String) -> Box + Send> { + 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_editgroups_reviewable( @@ -1958,64 +1986,36 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().get_editgroups_reviewable(expand, 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 get_editor(&self, editor_id: String) -> Box + Send> { self.api().get_editor(editor_id, &self.context()) } - fn get_editor_editgroups( + fn get_editor_annotations( &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> { - self.api().update_editor(editor_id, editor, &self.context()) - } - - fn accept_editgroup(&self, editgroup_id: String) -> Box + Send> { - self.api().accept_editgroup(editgroup_id, &self.context()) - } - - fn create_editgroup(&self, editgroup: models::Editgroup) -> Box + Send> { - 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()) - } - - fn get_changelog_entry(&self, index: i64) -> Box + Send> { - self.api().get_changelog_entry(index, &self.context()) - } - - fn get_editgroup(&self, editgroup_id: String) -> Box + Send> { - 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()) + ) -> Box + Send> { + self.api().get_editor_annotations(editor_id, limit, before, since, &self.context()) } - fn get_editor_annotations( + fn get_editor_editgroups( &self, editor_id: String, limit: Option, before: Option>, since: Option>, - ) -> Box + Send> { - self.api().get_editor_annotations(editor_id, limit, before, since, &self.context()) + ) -> Box + Send> { + self.api().get_editor_editgroups(editor_id, limit, before, since, &self.context()) + } + + fn update_editor(&self, editor_id: String, editor: models::Editor) -> Box + Send> { + self.api().update_editor(editor_id, editor, &self.context()) } fn create_file(&self, editgroup_id: String, entity: models::FileEntity) -> Box + Send> { @@ -2117,10 +2117,6 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().create_release_auto_batch(auto_batch, &self.context()) } - fn create_work(&self, editgroup_id: String, entity: models::WorkEntity) -> Box + Send> { - self.api().create_work(editgroup_id, entity, &self.context()) - } - fn delete_release(&self, editgroup_id: String, ident: String) -> Box + Send> { self.api().delete_release(editgroup_id, ident, &self.context()) } @@ -2224,6 +2220,10 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().update_webcapture(editgroup_id, ident, entity, &self.context()) } + fn create_work(&self, editgroup_id: String, entity: models::WorkEntity) -> Box + Send> { + self.api().create_work(editgroup_id, entity, &self.context()) + } + fn create_work_auto_batch(&self, auto_batch: models::WorkAutoBatch) -> Box + Send> { self.api().create_work_auto_batch(auto_batch, &self.context()) } diff --git a/rust/fatcat-openapi/src/mimetypes.rs b/rust/fatcat-openapi/src/mimetypes.rs index 0676f63b..ef297f69 100644 --- a/rust/fatcat-openapi/src/mimetypes.rs +++ b/rust/fatcat-openapi/src/mimetypes.rs @@ -4,6 +4,82 @@ pub mod responses { use hyper::mime::*; // The macro is called per-operation to beat the recursion limit + /// Create Mime objects for the response content types for AuthCheck + lazy_static! { + pub static ref AUTH_CHECK_SUCCESS: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthCheck + lazy_static! { + pub static ref AUTH_CHECK_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthCheck + lazy_static! { + pub static ref AUTH_CHECK_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthCheck + lazy_static! { + pub static ref AUTH_CHECK_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthCheck + lazy_static! { + pub static ref AUTH_CHECK_GENERIC_ERROR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC_CREATED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC_CONFLICT: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC_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); + } + /// Create Mime objects for the response content types for GetChangelog + lazy_static! { + pub static ref GET_CHANGELOG_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetChangelog + lazy_static! { + pub static ref GET_CHANGELOG_GENERIC_ERROR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetChangelogEntry + lazy_static! { + pub static ref GET_CHANGELOG_ENTRY_FOUND_CHANGELOG_ENTRY: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetChangelogEntry + lazy_static! { + pub static ref GET_CHANGELOG_ENTRY_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetChangelogEntry + lazy_static! { + pub static ref GET_CHANGELOG_ENTRY_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetChangelogEntry + lazy_static! { + pub static ref GET_CHANGELOG_ENTRY_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for CreateContainer lazy_static! { pub static ref CREATE_CONTAINER_CREATED_ENTITY: Mime = mime!(Application / Json); @@ -452,150 +528,6 @@ pub mod responses { lazy_static! { pub static ref UPDATE_CREATOR_GENERIC_ERROR: Mime = mime!(Application / Json); } - /// Create Mime objects for the response content types for AuthCheck - lazy_static! { - pub static ref AUTH_CHECK_SUCCESS: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthCheck - lazy_static! { - pub static ref AUTH_CHECK_BAD_REQUEST: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthCheck - lazy_static! { - pub static ref AUTH_CHECK_NOT_AUTHORIZED: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthCheck - lazy_static! { - pub static ref AUTH_CHECK_FORBIDDEN: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthCheck - lazy_static! { - pub static ref AUTH_CHECK_GENERIC_ERROR: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthOidc - lazy_static! { - pub static ref AUTH_OIDC_FOUND: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthOidc - lazy_static! { - pub static ref AUTH_OIDC_CREATED: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthOidc - lazy_static! { - pub static ref AUTH_OIDC_BAD_REQUEST: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthOidc - lazy_static! { - pub static ref AUTH_OIDC_NOT_AUTHORIZED: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthOidc - lazy_static! { - pub static ref AUTH_OIDC_FORBIDDEN: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthOidc - lazy_static! { - pub static ref AUTH_OIDC_CONFLICT: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for AuthOidc - 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); - } - /// Create Mime objects for the response content types for GetEditor - lazy_static! { - pub static ref GET_EDITOR_BAD_REQUEST: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for GetEditor - lazy_static! { - pub static ref GET_EDITOR_NOT_FOUND: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for GetEditor - lazy_static! { - pub static ref GET_EDITOR_GENERIC_ERROR: Mime = mime!(Application / Json); - } - /// 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 UPDATE_EDITGROUP_NOT_AUTHORIZED: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditgroup - lazy_static! { - pub static ref UPDATE_EDITGROUP_FORBIDDEN: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditgroup - lazy_static! { - pub static ref UPDATE_EDITGROUP_NOT_FOUND: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditgroup - lazy_static! { - pub static ref UPDATE_EDITGROUP_GENERIC_ERROR: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditor - lazy_static! { - pub static ref UPDATE_EDITOR_UPDATED_EDITOR: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditor - lazy_static! { - pub static ref UPDATE_EDITOR_BAD_REQUEST: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditor - lazy_static! { - pub static ref UPDATE_EDITOR_NOT_AUTHORIZED: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditor - lazy_static! { - pub static ref UPDATE_EDITOR_FORBIDDEN: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditor - lazy_static! { - pub static ref UPDATE_EDITOR_NOT_FOUND: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for UpdateEditor - lazy_static! { - pub static ref UPDATE_EDITOR_GENERIC_ERROR: Mime = mime!(Application / Json); - } /// Create Mime objects for the response content types for AcceptEditgroup lazy_static! { pub static ref ACCEPT_EDITGROUP_MERGED_SUCCESSFULLY: Mime = mime!(Application / Json); @@ -672,34 +604,6 @@ pub mod responses { 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); - } - /// Create Mime objects for the response content types for GetChangelog - lazy_static! { - pub static ref GET_CHANGELOG_BAD_REQUEST: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for GetChangelog - lazy_static! { - pub static ref GET_CHANGELOG_GENERIC_ERROR: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for GetChangelogEntry - lazy_static! { - pub static ref GET_CHANGELOG_ENTRY_FOUND_CHANGELOG_ENTRY: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for GetChangelogEntry - lazy_static! { - pub static ref GET_CHANGELOG_ENTRY_BAD_REQUEST: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for GetChangelogEntry - lazy_static! { - pub static ref GET_CHANGELOG_ENTRY_NOT_FOUND: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for GetChangelogEntry - lazy_static! { - pub static ref GET_CHANGELOG_ENTRY_GENERIC_ERROR: Mime = mime!(Application / Json); - } /// Create Mime objects for the response content types for GetEditgroup lazy_static! { pub static ref GET_EDITGROUP_FOUND: Mime = mime!(Application / Json); @@ -740,6 +644,62 @@ pub mod responses { lazy_static! { pub static ref GET_EDITGROUP_ANNOTATIONS_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 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 UPDATE_EDITGROUP_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditgroup + lazy_static! { + pub static ref UPDATE_EDITGROUP_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditgroup + lazy_static! { + pub static ref UPDATE_EDITGROUP_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditgroup + lazy_static! { + pub static ref UPDATE_EDITGROUP_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); + } + /// Create Mime objects for the response content types for GetEditor + lazy_static! { + pub static ref GET_EDITOR_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditor + lazy_static! { + pub static ref GET_EDITOR_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for GetEditor + lazy_static! { + pub static ref GET_EDITOR_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); @@ -764,6 +724,46 @@ pub mod responses { lazy_static! { pub static ref GET_EDITOR_ANNOTATIONS_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// 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 UpdateEditor + lazy_static! { + pub static ref UPDATE_EDITOR_UPDATED_EDITOR: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditor + lazy_static! { + pub static ref UPDATE_EDITOR_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditor + lazy_static! { + pub static ref UPDATE_EDITOR_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditor + lazy_static! { + pub static ref UPDATE_EDITOR_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditor + lazy_static! { + pub static ref UPDATE_EDITOR_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for UpdateEditor + lazy_static! { + pub static ref UPDATE_EDITOR_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); @@ -1228,30 +1228,6 @@ pub mod responses { lazy_static! { pub static ref CREATE_RELEASE_AUTO_BATCH_GENERIC_ERROR: Mime = mime!(Application / Json); } - /// Create Mime objects for the response content types for CreateWork - lazy_static! { - pub static ref CREATE_WORK_CREATED_ENTITY: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for CreateWork - lazy_static! { - pub static ref CREATE_WORK_BAD_REQUEST: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for CreateWork - lazy_static! { - pub static ref CREATE_WORK_NOT_AUTHORIZED: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for CreateWork - lazy_static! { - pub static ref CREATE_WORK_FORBIDDEN: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for CreateWork - lazy_static! { - pub static ref CREATE_WORK_NOT_FOUND: Mime = mime!(Application / Json); - } - /// Create Mime objects for the response content types for CreateWork - lazy_static! { - pub static ref CREATE_WORK_GENERIC_ERROR: Mime = mime!(Application / Json); - } /// Create Mime objects for the response content types for DeleteRelease lazy_static! { pub static ref DELETE_RELEASE_DELETED_ENTITY: Mime = mime!(Application / Json); @@ -1668,6 +1644,30 @@ pub mod responses { lazy_static! { pub static ref UPDATE_WEBCAPTURE_GENERIC_ERROR: Mime = mime!(Application / Json); } + /// Create Mime objects for the response content types for CreateWork + lazy_static! { + pub static ref CREATE_WORK_CREATED_ENTITY: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateWork + lazy_static! { + pub static ref CREATE_WORK_BAD_REQUEST: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateWork + lazy_static! { + pub static ref CREATE_WORK_NOT_AUTHORIZED: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateWork + lazy_static! { + pub static ref CREATE_WORK_FORBIDDEN: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateWork + lazy_static! { + pub static ref CREATE_WORK_NOT_FOUND: Mime = mime!(Application / Json); + } + /// Create Mime objects for the response content types for CreateWork + lazy_static! { + pub static ref CREATE_WORK_GENERIC_ERROR: Mime = mime!(Application / Json); + } /// Create Mime objects for the response content types for CreateWorkAutoBatch lazy_static! { pub static ref CREATE_WORK_AUTO_BATCH_CREATED_EDITGROUP: Mime = mime!(Application / Json); @@ -1865,6 +1865,10 @@ pub mod responses { pub mod requests { use hyper::mime::*; + /// Create Mime objects for the request content types for AuthOidc + lazy_static! { + pub static ref AUTH_OIDC: Mime = mime!(Application / Json); + } /// Create Mime objects for the request content types for CreateContainer lazy_static! { pub static ref CREATE_CONTAINER: Mime = mime!(Application / Json); @@ -1889,9 +1893,13 @@ pub mod requests { lazy_static! { pub static ref UPDATE_CREATOR: Mime = mime!(Application / Json); } - /// Create Mime objects for the request content types for AuthOidc + /// Create Mime objects for the request content types for CreateEditgroup lazy_static! { - pub static ref AUTH_OIDC: Mime = mime!(Application / Json); + 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 UpdateEditgroup lazy_static! { @@ -1901,14 +1909,6 @@ pub mod requests { lazy_static! { pub static ref UPDATE_EDITOR: Mime = mime!(Application / Json); } - /// Create Mime objects for the request content types for CreateEditgroup - 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); @@ -1941,10 +1941,6 @@ pub mod requests { lazy_static! { pub static ref CREATE_RELEASE_AUTO_BATCH: Mime = mime!(Application / Json); } - /// Create Mime objects for the request content types for CreateWork - lazy_static! { - pub static ref CREATE_WORK: Mime = mime!(Application / Json); - } /// Create Mime objects for the request content types for UpdateRelease lazy_static! { pub static ref UPDATE_RELEASE: Mime = mime!(Application / Json); @@ -1961,6 +1957,10 @@ pub mod requests { lazy_static! { pub static ref UPDATE_WEBCAPTURE: Mime = mime!(Application / Json); } + /// Create Mime objects for the request content types for CreateWork + lazy_static! { + pub static ref CREATE_WORK: Mime = mime!(Application / Json); + } /// Create Mime objects for the request content types for CreateWorkAutoBatch lazy_static! { pub static ref CREATE_WORK_AUTO_BATCH: Mime = mime!(Application / Json); diff --git a/rust/fatcat-openapi/src/models.rs b/rust/fatcat-openapi/src/models.rs index c8b68328..e9e527f5 100644 --- a/rust/fatcat-openapi/src/models.rs +++ b/rust/fatcat-openapi/src/models.rs @@ -11,15 +11,19 @@ use swagger; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct AuthOidc { + /// Fatcat-specific short name (slug) for remote service being used for authentication. #[serde(rename = "provider")] pub provider: String, + /// `SUB` from OIDC protocol. Usually a URL. #[serde(rename = "sub")] pub sub: String, + /// `ISS` from OIDC protocol. Usually a stable account username, number, or identifier. #[serde(rename = "iss")] pub iss: String, + /// What it sounds like; returned by OIDC, and used as a hint when creating new editor accounts. Fatcat usernames are usually this string with the `provider` slug as a suffix, though some munging may occur. #[serde(rename = "preferred_username")] pub preferred_username: String, } @@ -52,12 +56,15 @@ impl AuthOidcResult { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ChangelogEntry { + /// Monotonically increasing sequence number of this changelog entry. #[serde(rename = "index")] pub index: i64, + /// Identifier of editgroup accepted/merged in this changelog entry. #[serde(rename = "editgroup_id")] pub editgroup_id: String, + /// Date and time when the editgroup was accpeted. #[serde(rename = "timestamp")] pub timestamp: chrono::DateTime, @@ -101,28 +108,32 @@ pub struct ContainerEntity { #[serde(skip_serializing_if = "Option::is_none")] pub wikidata_qid: Option, + /// Linking ISSN number (ISSN-L). Should be valid and registered with issn.org #[serde(rename = "issnl")] #[serde(skip_serializing_if = "Option::is_none")] pub issnl: Option, + /// Name of the organization or entity responsible for publication. Not the complete imprint/brand. #[serde(rename = "publisher")] #[serde(skip_serializing_if = "Option::is_none")] pub publisher: Option, - /// Eg, 'journal' + /// Type of container, eg 'journal' or 'proceedings'. See Guide for list of valid types. #[serde(rename = "container_type")] #[serde(skip_serializing_if = "Option::is_none")] pub container_type: Option, - /// Required for valid entities + /// Name of the container (eg, Journal title). Required for entity creation. #[serde(rename = "name")] #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + /// Free-form JSON metadata that will be stored with specific entity edits (eg, creation/update/delete). #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] pub edit_extra: Option, + /// Free-form JSON metadata that will be stored with the other entity metadata. See guide for (unenforced) schema conventions. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, @@ -186,23 +197,27 @@ impl CreatorAutoBatch { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct CreatorEntity { + /// Wikidata entity QID #[serde(rename = "wikidata_qid")] #[serde(skip_serializing_if = "Option::is_none")] pub wikidata_qid: Option, + /// ORCiD (https://orcid.org) identifier #[serde(rename = "orcid")] #[serde(skip_serializing_if = "Option::is_none")] pub orcid: Option, + /// In English commonly the last, or family name, but ordering is context and culture specific. #[serde(rename = "surname")] #[serde(skip_serializing_if = "Option::is_none")] pub surname: Option, + /// In English commonly the first name, but ordering is context and culture specific. #[serde(rename = "given_name")] #[serde(skip_serializing_if = "Option::is_none")] pub given_name: Option, - /// Required for valid entities + /// Name as should be displayed in web interface or in author lists (not index/sorted). Required for valid entities. #[serde(rename = "display_name")] #[serde(skip_serializing_if = "Option::is_none")] pub display_name: Option, @@ -227,10 +242,12 @@ pub struct CreatorEntity { #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, + /// Free-form JSON metadata that will be stored with the other entity metadata. See guide for (unenforced) schema conventions. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, + /// Free-form JSON metadata that will be stored with specific entity edits (eg, creation/update/delete). #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] pub edit_extra: Option, @@ -256,40 +273,47 @@ impl CreatorEntity { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Editgroup { - /// base32-encoded unique identifier + /// Fatcat identifier for this editgroup. Assigned on creation. #[serde(rename = "editgroup_id")] #[serde(skip_serializing_if = "Option::is_none")] pub editgroup_id: Option, - /// base32-encoded unique identifier + /// Fatcat identifer of editor that created this editgroup. #[serde(rename = "editor_id")] #[serde(skip_serializing_if = "Option::is_none")] pub editor_id: Option, + /// Complete editor object identified by `container_id` field. Only included in GET responses. #[serde(rename = "editor")] #[serde(skip_serializing_if = "Option::is_none")] pub editor: Option, + /// For accepted/merged editgroups, the changelog index that the accept occured at. WARNING: not populated in all contexts that an editgroup could be included in a response. #[serde(rename = "changelog_index")] #[serde(skip_serializing_if = "Option::is_none")] pub changelog_index: Option, + /// Timestamp when this editgroup was first created. #[serde(rename = "created")] #[serde(skip_serializing_if = "Option::is_none")] pub created: Option>, + /// Timestamp when this editgroup was most recently submitted for review. If withdrawn, or never submitted, will be `null`. #[serde(rename = "submitted")] #[serde(skip_serializing_if = "Option::is_none")] pub submitted: Option>, + /// Comment describing the changes in this editgroup. Can be updated with PUT request. #[serde(rename = "description")] #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, + /// Free-form JSON metadata attached to this editgroup. Eg, metadata provenance, or script user-agent details. See guide for (unenforced) schema norms. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, + /// Only included in GET responses, and not in all contexts. Do not include this field in PUT or POST requests. #[serde(rename = "annotations")] #[serde(skip_serializing_if = "Option::is_none")] pub annotations: Option>, @@ -323,20 +347,22 @@ pub struct EditgroupAnnotation { #[serde(skip_serializing_if = "Option::is_none")] pub annotation_id: Option, - /// base32-encoded unique identifier + /// Editgroup that this annotation applies to. Set automatically in creations based on URL parameter. #[serde(rename = "editgroup_id")] #[serde(skip_serializing_if = "Option::is_none")] pub editgroup_id: Option, - /// base32-encoded unique identifier + /// Defaults to editor created the annotation via POST request. #[serde(rename = "editor_id")] #[serde(skip_serializing_if = "Option::is_none")] pub editor_id: Option, + /// Only included in GET responses; ignored in PUT or POST requests. #[serde(rename = "editor")] #[serde(skip_serializing_if = "Option::is_none")] pub editor: Option, + /// Timestamp when annotation was first created. #[serde(rename = "created")] #[serde(skip_serializing_if = "Option::is_none")] pub created: Option>, @@ -345,6 +371,7 @@ pub struct EditgroupAnnotation { #[serde(skip_serializing_if = "Option::is_none")] pub comment_markdown: Option, + /// Additional free-form JSON metadata that can be included as part of the annotation (or even as the primary annotation itself). See guide for details. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, @@ -364,6 +391,7 @@ impl EditgroupAnnotation { } } +/// Only included in GET responses, and not in all contexts. Do not include this field in PUT or POST requests. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct EditgroupEdits { #[serde(rename = "containers")] @@ -411,22 +439,26 @@ impl EditgroupEdits { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Editor { - /// base32-encoded unique identifier + /// Fatcat identifier for the editor. Can not be changed. #[serde(rename = "editor_id")] #[serde(skip_serializing_if = "Option::is_none")] pub editor_id: Option, + /// Username/handle (short slug-like string) to identify this editor. May be changed at any time by the editor; use the `editor_id` as a persistend identifer. #[serde(rename = "username")] pub username: String, + /// Whether this editor has the `admin` role. #[serde(rename = "is_admin")] #[serde(skip_serializing_if = "Option::is_none")] pub is_admin: Option, + /// Whether this editor is a bot (as opposed to a human making manual edits) #[serde(rename = "is_bot")] #[serde(skip_serializing_if = "Option::is_none")] pub is_bot: Option, + /// Whether this editor's account is enabled (if not API tokens and web logins will not work). #[serde(rename = "is_active")] #[serde(skip_serializing_if = "Option::is_none")] pub is_active: Option, @@ -446,30 +478,30 @@ impl Editor { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct EntityEdit { - /// UUID (lower-case, dash-separated, hex-encoded 128-bit) + /// Unique UUID for this specific edit object. #[serde(rename = "edit_id")] pub edit_id: String, - /// base32-encoded unique identifier + /// Fatcat identifier of the entity this edit is mutating. #[serde(rename = "ident")] pub ident: String, - /// UUID (lower-case, dash-separated, hex-encoded 128-bit) + /// Entity revision that this edit will set the entity to. May be `null` in the case of deletions. #[serde(rename = "revision")] #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, - /// UUID (lower-case, dash-separated, hex-encoded 128-bit) + /// Revision of entity just before this edit. May be used in the future to prevent edit race conditions. #[serde(rename = "prev_revision")] #[serde(skip_serializing_if = "Option::is_none")] pub prev_revision: Option, - /// base32-encoded unique identifier + /// When an edit is to merge entities (redirect one to another), this is the entity fatcat identifier for the target entity. #[serde(rename = "redirect_ident")] #[serde(skip_serializing_if = "Option::is_none")] pub redirect_ident: Option, - /// base32-encoded unique identifier + /// Editgroup identifier that this edit is part of. #[serde(rename = "editgroup_id")] pub editgroup_id: String, @@ -556,11 +588,12 @@ impl FileAutoBatch { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FileEntity { - /// Optional; GET-only + /// Full release entities, included in GET responses when `releases` included in `expand` parameter. Ignored if included in PUT or POST requests. #[serde(rename = "releases")] #[serde(skip_serializing_if = "Option::is_none")] pub releases: Option>, + /// Set of identifier of release entities this file represents a full manifestation of. Usually a single release, but some files contain content of multiple full releases (eg, an issue of a journal). #[serde(rename = "release_ids")] #[serde(skip_serializing_if = "Option::is_none")] pub release_ids: Option>, @@ -573,26 +606,32 @@ pub struct FileEntity { #[serde(skip_serializing_if = "Option::is_none")] pub urls: Option>, + /// SHA-256 hash of data, in hex encoding #[serde(rename = "sha256")] #[serde(skip_serializing_if = "Option::is_none")] pub sha256: Option, + /// SHA-1 hash of data, in hex encoding #[serde(rename = "sha1")] #[serde(skip_serializing_if = "Option::is_none")] pub sha1: Option, + /// MD5 hash of data, in hex encoding #[serde(rename = "md5")] #[serde(skip_serializing_if = "Option::is_none")] pub md5: Option, + /// Size of file in bytes. Non-zero. #[serde(rename = "size")] #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, + /// Free-form JSON metadata that will be stored with specific entity edits (eg, creation/update/delete). #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] pub edit_extra: Option, + /// Free-form JSON metadata that will be stored with the other entity metadata. See guide for (unenforced) schema conventions. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, @@ -641,9 +680,11 @@ impl FileEntity { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FileUrl { + /// URL/URI pointing directly to a machine retrievable copy of this exact file. #[serde(rename = "url")] pub url: String, + /// Indicates type of host this URL points to. Eg, \"publisher\", \"repository\", \"webarchive\". See guide for list of acceptable values. #[serde(rename = "rel")] pub rel: String, } @@ -674,11 +715,12 @@ impl FilesetAutoBatch { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FilesetEntity { - /// Optional; GET-only + /// Full release entities, included in GET responses when `releases` included in `expand` parameter. Ignored if included in PUT or POST requests. #[serde(rename = "releases")] #[serde(skip_serializing_if = "Option::is_none")] pub releases: Option>, + /// Set of identifier of release entities this fileset represents a full manifestation of. Usually a single release. #[serde(rename = "release_ids")] #[serde(skip_serializing_if = "Option::is_none")] pub release_ids: Option>, @@ -711,10 +753,12 @@ pub struct FilesetEntity { #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, + /// Free-form JSON metadata that will be stored with the other entity metadata. See guide for (unenforced) schema conventions. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, + /// Free-form JSON metadata that will be stored with specific entity edits (eg, creation/update/delete). #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] pub edit_extra: Option, @@ -739,24 +783,30 @@ impl FilesetEntity { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct FilesetFile { + /// Path name of file within this fileset (eg, directory) #[serde(rename = "path")] pub path: String, + /// File size in bytes #[serde(rename = "size")] pub size: i64, + /// MD5 hash of data, in hex encoding #[serde(rename = "md5")] #[serde(skip_serializing_if = "Option::is_none")] pub md5: Option, + /// SHA-1 hash of data, in hex encoding #[serde(rename = "sha1")] #[serde(skip_serializing_if = "Option::is_none")] pub sha1: Option, + /// SHA-256 hash of data, in hex encoding #[serde(rename = "sha256")] #[serde(skip_serializing_if = "Option::is_none")] pub sha256: Option, + /// Free-form additional metadata about this specific file in the set. Eg, `mimetype`. See guide for nomative (but unenforced) schema fields. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, @@ -780,6 +830,7 @@ pub struct FilesetUrl { #[serde(rename = "url")] pub url: String, + /// Indicates type of host this URL points to. See guide for list of acceptable values. #[serde(rename = "rel")] pub rel: String, } @@ -792,18 +843,22 @@ impl FilesetUrl { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ReleaseAbstract { + /// SHA-1 hash of data, in hex encoding #[serde(rename = "sha1")] #[serde(skip_serializing_if = "Option::is_none")] pub sha1: Option, + /// Abstract content. May be encoded, as per `mimetype` field, but only string/text content may be included. #[serde(rename = "content")] #[serde(skip_serializing_if = "Option::is_none")] pub content: Option, + /// Mimetype of abstract contents. `text/plain` is the default if content isn't encoded. #[serde(rename = "mimetype")] #[serde(skip_serializing_if = "Option::is_none")] pub mimetype: Option, + /// ISO language code of the abstract. Same semantics as release `language` field. #[serde(rename = "lang")] #[serde(skip_serializing_if = "Option::is_none")] pub lang: Option, @@ -840,32 +895,37 @@ impl ReleaseAutoBatch { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ReleaseContrib { + /// Internally assigned zero-indexed sequence number of contribution. Authors should come first; this encodes the order of attriubtion. #[serde(rename = "index")] #[serde(skip_serializing_if = "Option::is_none")] pub index: Option, - /// base32-encoded unique identifier + /// If known, indicates the creator entity this contribution was made by. #[serde(rename = "creator_id")] #[serde(skip_serializing_if = "Option::is_none")] pub creator_id: Option, - /// Optional; GET-only + /// Complete creator entity. Only returned in GET responses, and only if `contribs` included in the `expand` query parameter. #[serde(rename = "creator")] #[serde(skip_serializing_if = "Option::is_none")] pub creator: Option, + /// Full name of the contributor as typeset in the release. #[serde(rename = "raw_name")] #[serde(skip_serializing_if = "Option::is_none")] pub raw_name: Option, + /// In English commonly the first name, but ordering is context and culture specific. #[serde(rename = "given_name")] #[serde(skip_serializing_if = "Option::is_none")] pub given_name: Option, + /// In English commonly the last, or family name, but ordering is context and culture specific. #[serde(rename = "surname")] #[serde(skip_serializing_if = "Option::is_none")] pub surname: Option, + /// Short string (slug) indicating type of contribution (eg, \"author\", \"translator\"). See guide for list of accpeted values. #[serde(rename = "role")] #[serde(skip_serializing_if = "Option::is_none")] pub role: Option, @@ -875,6 +935,7 @@ pub struct ReleaseContrib { #[serde(skip_serializing_if = "Option::is_none")] pub raw_affiliation: Option, + /// Additional free-form JSON metadata about this contributor/contribution. See guide for normative schema. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, @@ -910,110 +971,126 @@ pub struct ReleaseEntity { #[serde(skip_serializing_if = "Option::is_none")] pub contribs: Option>, - /// Short version of license name. Eg, 'CC-BY' + /// Short string (slug) name of license under which release is openly published (if applicable). #[serde(rename = "license_slug")] #[serde(skip_serializing_if = "Option::is_none")] pub license_slug: Option, - /// Two-letter RFC1766/ISO639-1 language code, with extensions + /// Primary language of the content of the full release. Two-letter RFC1766/ISO639-1 language code, with some custom extensions/additions. See guide. #[serde(rename = "language")] #[serde(skip_serializing_if = "Option::is_none")] pub language: Option, + /// Name, usually English, of the entity or institution responsible for publication of this release. Not necessarily the imprint/brand. See guide. #[serde(rename = "publisher")] #[serde(skip_serializing_if = "Option::is_none")] pub publisher: Option, + /// For, eg, updated technical reports or software packages, where the version string may be the only field disambiguating between releases. #[serde(rename = "version")] #[serde(skip_serializing_if = "Option::is_none")] pub version: Option, + /// For, eg, technical reports, which are published in series or assigned some other institutional or container-specific identifier. #[serde(rename = "number")] #[serde(skip_serializing_if = "Option::is_none")] pub number: Option, + /// Either a single page number (\"first page\") or a range of pages separated by a dash (\"-\"). See guide for details. #[serde(rename = "pages")] #[serde(skip_serializing_if = "Option::is_none")] pub pages: Option, + /// Issue number of volume/container that this release was published in. Sometimes coresponds to a month number in the year, but can be any string. See guide. #[serde(rename = "issue")] #[serde(skip_serializing_if = "Option::is_none")] pub issue: Option, + /// Volume number of container that this release was published in. Often corresponds to the \"Nth\" year of publication, but can be any string. See guide. #[serde(rename = "volume")] #[serde(skip_serializing_if = "Option::is_none")] pub volume: Option, + /// Set of external identifiers for this release. #[serde(rename = "ext_ids")] pub ext_ids: models::ReleaseExtIds, + /// Year corresponding with `withdrawn_date` like `release_year`/`release_date`. #[serde(rename = "withdrawn_year")] #[serde(skip_serializing_if = "Option::is_none")] pub withdrawn_year: Option, + /// Full date when this release was formally withdrawn (if applicable). ISO format, like `release_date`. #[serde(rename = "withdrawn_date")] #[serde(skip_serializing_if = "Option::is_none")] pub withdrawn_date: Option, + /// Type of withdrawl or retraction of this release, if applicable. If release has not been withdrawn, should be `null` (aka, not set, not the string \"null\" or an empty string). #[serde(rename = "withdrawn_status")] #[serde(skip_serializing_if = "Option::is_none")] pub withdrawn_status: Option, + /// Year when this release was formally published. Must match `release_date` if that field is set; this field exists because sometimes only the year is known. #[serde(rename = "release_year")] #[serde(skip_serializing_if = "Option::is_none")] pub release_year: Option, + /// Full date when this release was formally published. ISO format, like `2019-03-05`. See guide for semantics. #[serde(rename = "release_date")] #[serde(skip_serializing_if = "Option::is_none")] pub release_date: Option, + /// The stage of publication of this specific release. See guide for valid values and semantics. #[serde(rename = "release_stage")] #[serde(skip_serializing_if = "Option::is_none")] pub release_stage: Option, + /// \"Type\" or \"medium\" that this release is published as. See guide for valid values. #[serde(rename = "release_type")] #[serde(skip_serializing_if = "Option::is_none")] pub release_type: Option, + /// Used to link this release to a container entity that the release was published as part of. #[serde(rename = "container_id")] #[serde(skip_serializing_if = "Option::is_none")] pub container_id: Option, - /// Optional; GET-only + /// Complete webcapture entities identified by `webcapture_ids` field. Only included in GET responses when `webcaptures` included in `expand` parameter; ignored in PUT or POST requests. #[serde(rename = "webcaptures")] #[serde(skip_serializing_if = "Option::is_none")] pub webcaptures: Option>, - /// Optional; GET-only + /// Complete file entities identified by `filesets_ids` field. Only included in GET responses when `filesets` included in `expand` parameter; ignored in PUT or POST requests. #[serde(rename = "filesets")] #[serde(skip_serializing_if = "Option::is_none")] pub filesets: Option>, - /// Optional; GET-only + /// Complete file entities identified by `file_ids` field. Only included in GET responses when `files` included in `expand` parameter; ignored in PUT or POST requests. #[serde(rename = "files")] #[serde(skip_serializing_if = "Option::is_none")] pub files: Option>, - /// Optional; GET-only + /// Complete container entity identified by `container_id` field. Only included in GET reponses when `container` included in `expand` parameter; ignored in PUT or POST requests. #[serde(rename = "container")] #[serde(skip_serializing_if = "Option::is_none")] pub container: Option, + /// Identifier of work this release is part of. In creation (POST) requests, a work entity will be created automatically if this field is not set. #[serde(rename = "work_id")] #[serde(skip_serializing_if = "Option::is_none")] pub work_id: Option, - /// Title in original language (or, the language of the full text of this release) + /// Title in original language if `title` field has been translated. See guide for details. #[serde(rename = "original_title")] #[serde(skip_serializing_if = "Option::is_none")] pub original_title: Option, - /// Avoid this field if possible, and merge with title; usually English + /// Subtitle of release. In many cases, better to merge with title than include as separate field (unless combined title would be very long). See guide for details. #[serde(rename = "subtitle")] #[serde(skip_serializing_if = "Option::is_none")] pub subtitle: Option, - /// Required for valid entities. The title used in citations and for display; usually English + /// Required for valid entities. The title used in citations and for display. Sometimes the English translation of title e even if release content is not English. #[serde(rename = "title")] #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, @@ -1038,10 +1115,12 @@ pub struct ReleaseEntity { #[serde(skip_serializing_if = "Option::is_none")] pub redirect: Option, + /// Free-form JSON metadata that will be stored with the other entity metadata. See guide for (unenforced) schema conventions. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, + /// Free-form JSON metadata that will be stored with specific entity edits (eg, creation/update/delete). #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] pub edit_extra: Option, @@ -1090,42 +1169,52 @@ impl ReleaseEntity { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ReleaseExtIds { + /// Digital serde_json::Value Identifier (DOI), mostly for published papers and datasets. Should be registered and resolvable via https://doi.org/ #[serde(rename = "doi")] #[serde(skip_serializing_if = "Option::is_none")] pub doi: Option, + /// Wikidata entity QID #[serde(rename = "wikidata_qid")] #[serde(skip_serializing_if = "Option::is_none")] pub wikidata_qid: Option, + /// ISBN-13, for books. Usually not set for chapters. ISBN-10 should be converted to ISBN-13. #[serde(rename = "isbn13")] #[serde(skip_serializing_if = "Option::is_none")] pub isbn13: Option, + /// PubMed Identifier #[serde(rename = "pmid")] #[serde(skip_serializing_if = "Option::is_none")] pub pmid: Option, + /// PubMed Central Identifier #[serde(rename = "pmcid")] #[serde(skip_serializing_if = "Option::is_none")] pub pmcid: Option, + /// CORE (https://core.ac.uk) identifier #[serde(rename = "core")] #[serde(skip_serializing_if = "Option::is_none")] pub core: Option, + /// arXiv (https://arxiv.org) identifier; must include version #[serde(rename = "arxiv")] #[serde(skip_serializing_if = "Option::is_none")] pub arxiv: Option, + /// JSTOR work identifier #[serde(rename = "jstor")] #[serde(skip_serializing_if = "Option::is_none")] pub jstor: Option, + /// ARK identifier #[serde(rename = "ark")] #[serde(skip_serializing_if = "Option::is_none")] pub ark: Option, + /// Microsoft Academic Graph identifier #[serde(rename = "mag")] #[serde(skip_serializing_if = "Option::is_none")] pub mag: Option, @@ -1150,35 +1239,42 @@ impl ReleaseExtIds { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct ReleaseRef { + /// Zero-indexed sequence number of this reference in the list of references. Assigned automatically and used internally; don't confuse with `key`. #[serde(rename = "index")] #[serde(skip_serializing_if = "Option::is_none")] pub index: Option, - /// base32-encoded unique identifier + /// Optional, fatcat identifier of release entity that this reference is citing. #[serde(rename = "target_release_id")] #[serde(skip_serializing_if = "Option::is_none")] pub target_release_id: Option, + /// Additional free-form JSON metadata about this citation. Generally follows Citation Style Language (CSL) JSON schema. See guide for details. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, + /// Short string used to indicate this reference from within the release text; or numbering of references as typeset in the release itself. Optional; don't confuse with `index` field. #[serde(rename = "key")] #[serde(skip_serializing_if = "Option::is_none")] pub key: Option, + /// Year that the cited work was published in. #[serde(rename = "year")] #[serde(skip_serializing_if = "Option::is_none")] pub year: Option, + /// Name of the container (eg, journal) that the citation work was published as part of. May be an acronym or full name. #[serde(rename = "container_name")] #[serde(skip_serializing_if = "Option::is_none")] pub container_name: Option, + /// Name of the work being cited. #[serde(rename = "title")] #[serde(skip_serializing_if = "Option::is_none")] pub title: Option, + /// Page number or other indicator of the specific subset of a work being cited. Not to be confused with the first page (or page range) of an entire paper or chapter being cited. #[serde(rename = "locator")] #[serde(skip_serializing_if = "Option::is_none")] pub locator: Option, @@ -1234,31 +1330,38 @@ impl WebcaptureAutoBatch { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct WebcaptureCdxLine { + /// \"Sortable URL\" format. See guide for details. #[serde(rename = "surt")] pub surt: String, - /// UTC, 'Z'-terminated, second (or better) precision + /// Date and time of capture, in ISO format. UTC, 'Z'-terminated, second (or better) precision. #[serde(rename = "timestamp")] pub timestamp: chrono::DateTime, + /// Full URL/URI of resource captured. #[serde(rename = "url")] pub url: String, + /// Mimetype of the resource at this URL. May be the Content-Type header, or the actually sniffed file type. #[serde(rename = "mimetype")] #[serde(skip_serializing_if = "Option::is_none")] pub mimetype: Option, + /// HTTP status code. Should generally be 200, especially for the primary resource, but may be 3xx (redirect) or even error codes if embedded resources can not be fetched successfully. #[serde(rename = "status_code")] #[serde(skip_serializing_if = "Option::is_none")] pub status_code: Option, + /// Resource (file) size in bytes #[serde(rename = "size")] #[serde(skip_serializing_if = "Option::is_none")] pub size: Option, + /// SHA-1 hash of data, in hex encoding #[serde(rename = "sha1")] pub sha1: String, + /// SHA-256 hash of data, in hex encoding #[serde(rename = "sha256")] #[serde(skip_serializing_if = "Option::is_none")] pub sha256: Option, @@ -1281,20 +1384,22 @@ impl WebcaptureCdxLine { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct WebcaptureEntity { - /// Optional; GET-only + /// Full release entities, included in GET responses when `releases` included in `expand` parameter. Ignored if included in PUT or POST requests. #[serde(rename = "releases")] #[serde(skip_serializing_if = "Option::is_none")] pub releases: Option>, + /// Set of identifier of release entities this fileset represents a full manifestation of. Usually a single release. #[serde(rename = "release_ids")] #[serde(skip_serializing_if = "Option::is_none")] pub release_ids: Option>, - /// same format as CDX line timestamp (UTC, etc). Corresponds to the overall capture timestamp. Can be the earliest or average of CDX timestamps if that makes sense. + /// Same format as CDX line timestamp (UTC, etc). Corresponds to the overall capture timestamp. Should generally be the timestamp of capture of the primary resource URL. #[serde(rename = "timestamp")] #[serde(skip_serializing_if = "Option::is_none")] pub timestamp: Option>, + /// Base URL of the primary resource this is a capture of #[serde(rename = "original_url")] #[serde(skip_serializing_if = "Option::is_none")] pub original_url: Option, @@ -1307,10 +1412,12 @@ pub struct WebcaptureEntity { #[serde(skip_serializing_if = "Option::is_none")] pub cdx: Option>, + /// Free-form JSON metadata that will be stored with specific entity edits (eg, creation/update/delete). #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] pub edit_extra: Option, + /// Free-form JSON metadata that will be stored with the other entity metadata. See guide for (unenforced) schema conventions. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, @@ -1357,9 +1464,11 @@ impl WebcaptureEntity { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct WebcaptureUrl { + /// URL/URI pointing to archive of this web resource. #[serde(rename = "url")] pub url: String, + /// Type of archive endpoint. Usually `wayback` (WBM replay of primary resource), or `warc` (direct URL to a WARC file containing all resources of the capture). See guide for full list. #[serde(rename = "rel")] pub rel: String, } @@ -1390,10 +1499,12 @@ impl WorkAutoBatch { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct WorkEntity { + /// Free-form JSON metadata that will be stored with specific entity edits (eg, creation/update/delete). #[serde(rename = "edit_extra")] #[serde(skip_serializing_if = "Option::is_none")] pub edit_extra: Option, + /// Free-form JSON metadata that will be stored with the other entity metadata. See guide for (unenforced) schema conventions. #[serde(rename = "extra")] #[serde(skip_serializing_if = "Option::is_none")] pub extra: Option, diff --git a/rust/fatcat-openapi/src/server.rs b/rust/fatcat-openapi/src/server.rs index 102b6e41..406b6789 100644 --- a/rust/fatcat-openapi/src/server.rs +++ b/rust/fatcat-openapi/src/server.rs @@ -98,8 +98,8 @@ where T: Api + Send + Sync + Clone + 'static, { let api_clone = api.clone(); - router.post( - "/v0/editgroup/:editgroup_id/container", + router.get( + "/v0/auth/check", move |req: &mut Request| { let mut context = Context::default(); @@ -114,121 +114,63 @@ where 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))))? - }; - - // 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())))?; + // 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_role = query_params.get("role").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - match api.create_container(param_editgroup_id, param_entity, context).wait() { + match api.auth_check(param_role, context).wait() { Ok(rsp) => match rsp { - CreateContainerResponse::CreatedEntity(body) => { + AuthCheckResponse::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(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_CONTAINER_CREATED_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::AUTH_CHECK_SUCCESS.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) } - CreateContainerResponse::BadRequest(body) => { + AuthCheckResponse::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_CONTAINER_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_CHECK_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) } - CreateContainerResponse::NotAuthorized { body, www_authenticate } => { + AuthCheckResponse::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_CONTAINER_NOT_AUTHORIZED.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_CHECK_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) } - CreateContainerResponse::Forbidden(body) => { + AuthCheckResponse::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_CONTAINER_FORBIDDEN.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_CHECK_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) - } - CreateContainerResponse::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_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) } - CreateContainerResponse::GenericError(body) => { + AuthCheckResponse::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_CONTAINER_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_CHECK_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) } }, @@ -245,12 +187,12 @@ where Ok(response) }) }, - "CreateContainer", + "AuthCheck", ); let api_clone = api.clone(); router.post( - "/v0/editgroup/auto/container/batch", + "/v0/auth/oidc", move |req: &mut Request| { let mut context = Context::default(); @@ -269,34 +211,46 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_auto_batch = req + let param_oidc_params = req .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter auto_batch - not valid UTF-8: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter oidc_params - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_auto_batch = if let Some(param_auto_batch_raw) = param_auto_batch { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_auto_batch_raw); + let param_oidc_params = if let Some(param_oidc_params_raw) = param_oidc_params { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_oidc_params_raw); - let param_auto_batch: Option = serde_ignored::deserialize(deserializer, |path| { + let param_oidc_params: 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 auto_batch - doesn't match schema: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter oidc_params - doesn't match schema: {}", e))))?; - param_auto_batch + param_oidc_params } else { None }; - let param_auto_batch = param_auto_batch.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter auto_batch".to_string())))?; + let param_oidc_params = param_oidc_params.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter oidc_params".to_string())))?; - match api.create_container_auto_batch(param_auto_batch, context).wait() { + match api.auth_oidc(param_oidc_params, context).wait() { Ok(rsp) => match rsp { - CreateContainerAutoBatchResponse::CreatedEditgroup(body) => { + AuthOidcResponse::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::AUTH_OIDC_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) + } + AuthOidcResponse::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_CONTAINER_AUTO_BATCH_CREATED_EDITGROUP.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_CREATED.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -304,11 +258,11 @@ where } Ok(response) } - CreateContainerAutoBatchResponse::BadRequest(body) => { + AuthOidcResponse::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_CONTAINER_AUTO_BATCH_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -316,14 +270,14 @@ where } Ok(response) } - CreateContainerAutoBatchResponse::NotAuthorized { body, www_authenticate } => { + AuthOidcResponse::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_CONTAINER_AUTO_BATCH_NOT_AUTHORIZED.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_NOT_AUTHORIZED.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -331,11 +285,11 @@ where } Ok(response) } - CreateContainerAutoBatchResponse::Forbidden(body) => { + AuthOidcResponse::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_CONTAINER_AUTO_BATCH_FORBIDDEN.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_FORBIDDEN.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -343,11 +297,11 @@ where } Ok(response) } - CreateContainerAutoBatchResponse::NotFound(body) => { + AuthOidcResponse::Conflict(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_CONTAINER_AUTO_BATCH_NOT_FOUND.clone())); + let mut response = Response::with((status::Status::from_u16(409), body_string)); + response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_CONFLICT.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -355,11 +309,11 @@ where } Ok(response) } - CreateContainerAutoBatchResponse::GenericError(body) => { + AuthOidcResponse::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_CONTAINER_AUTO_BATCH_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -381,12 +335,12 @@ where Ok(response) }) }, - "CreateContainerAutoBatch", + "AuthOidc", ); let api_clone = api.clone(); - router.delete( - "/v0/editgroup/:editgroup_id/container/:ident", + router.get( + "/v0/changelog", move |req: &mut Request| { let mut context = Context::default(); @@ -399,96 +353,42 @@ where 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))))? - }; - let param_ident = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("ident") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter ident".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 ident: {}", 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| Some(x.parse::())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?; - match api.delete_container(param_editgroup_id, param_ident, context).wait() { + match api.get_changelog(param_limit, context).wait() { Ok(rsp) => match rsp { - DeleteContainerResponse::DeletedEntity(body) => { + 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::DELETE_CONTAINER_DELETED_ENTITY.clone())); + 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) } - DeleteContainerResponse::BadRequest(body) => { + 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::DELETE_CONTAINER_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - DeleteContainerResponse::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::DELETE_CONTAINER_NOT_AUTHORIZED.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - DeleteContainerResponse::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::DELETE_CONTAINER_FORBIDDEN.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - DeleteContainerResponse::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_CONTAINER_NOT_FOUND.clone())); + 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) } - DeleteContainerResponse::GenericError(body) => { + 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::DELETE_CONTAINER_GENERIC_ERROR.clone())); + 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()))); @@ -508,12 +408,515 @@ where Ok(response) }) }, - "DeleteContainer", + "GetChangelog", ); let api_clone = api.clone(); - router.delete( - "/v0/editgroup/:editgroup_id/container/edit/:edit_id", + router.get( + "/v0/changelog/:index", + 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_index = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("index") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter index".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 index: {}", e))))? + }; + + match api.get_changelog_entry(param_index, context).wait() { + Ok(rsp) => match rsp { + GetChangelogEntryResponse::FoundChangelogEntry(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())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetChangelogEntryResponse::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_ENTRY_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetChangelogEntryResponse::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())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + 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.post( + "/v0/editgroup/:editgroup_id/container", + 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))))? + }; + + // 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_container(param_editgroup_id, param_entity, context).wait() { + Ok(rsp) => match rsp { + CreateContainerResponse::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_CONTAINER_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) + } + CreateContainerResponse::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_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) + } + CreateContainerResponse::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_CONTAINER_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) + } + CreateContainerResponse::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_CONTAINER_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) + } + CreateContainerResponse::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_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) + } + CreateContainerResponse::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_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) + } + }, + 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) + }) + }, + "CreateContainer", + ); + + let api_clone = api.clone(); + router.post( + "/v0/editgroup/auto/container/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::(); + + let authorization = context.authorization.as_ref().ok_or_else(|| Response::with((status::Forbidden, "Unauthenticated".to_string())))?; + + // 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_auto_batch = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter auto_batch - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_auto_batch = if let Some(param_auto_batch_raw) = param_auto_batch { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_auto_batch_raw); + + let param_auto_batch: 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 auto_batch - doesn't match schema: {}", e))))?; + + param_auto_batch + } else { + None + }; + let param_auto_batch = param_auto_batch.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter auto_batch".to_string())))?; + + match api.create_container_auto_batch(param_auto_batch, context).wait() { + Ok(rsp) => match rsp { + CreateContainerAutoBatchResponse::CreatedEditgroup(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_CONTAINER_AUTO_BATCH_CREATED_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) + } + CreateContainerAutoBatchResponse::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_CONTAINER_AUTO_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) + } + CreateContainerAutoBatchResponse::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_CONTAINER_AUTO_BATCH_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) + } + CreateContainerAutoBatchResponse::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_CONTAINER_AUTO_BATCH_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) + } + CreateContainerAutoBatchResponse::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_CONTAINER_AUTO_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) + } + CreateContainerAutoBatchResponse::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_CONTAINER_AUTO_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) + }) + }, + "CreateContainerAutoBatch", + ); + + let api_clone = api.clone(); + router.delete( + "/v0/editgroup/:editgroup_id/container/:ident", + 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))))? + }; + let param_ident = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("ident") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter ident".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 ident: {}", e))))? + }; + + match api.delete_container(param_editgroup_id, param_ident, context).wait() { + Ok(rsp) => match rsp { + DeleteContainerResponse::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_CONTAINER_DELETED_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteContainerResponse::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_CONTAINER_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteContainerResponse::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::DELETE_CONTAINER_NOT_AUTHORIZED.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteContainerResponse::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::DELETE_CONTAINER_FORBIDDEN.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteContainerResponse::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_CONTAINER_NOT_FOUND.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + DeleteContainerResponse::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_CONTAINER_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) + }) + }, + "DeleteContainer", + ); + + let api_clone = api.clone(); + router.delete( + "/v0/editgroup/:editgroup_id/container/edit/:edit_id", move |req: &mut Request| { let mut context = Context::default(); @@ -2469,298 +2872,41 @@ where match api.lookup_creator(param_orcid, param_wikidata_qid, param_expand, param_hide, context).wait() { Ok(rsp) => match rsp { - 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::LOOKUP_CREATOR_FOUND_ENTITY.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - 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::LOOKUP_CREATOR_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - 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::LOOKUP_CREATOR_NOT_FOUND.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - 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::LOOKUP_CREATOR_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) - }) - }, - "LookupCreator", - ); - - let api_clone = api.clone(); - router.put( - "/v0/editgroup/:editgroup_id/creator/:ident", - 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))))? - }; - let param_ident = { - let param = req - .extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("ident") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter ident".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 ident: {}", e))))? - }; - - // 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_creator(param_editgroup_id, param_ident, param_entity, context).wait() { - Ok(rsp) => match rsp { - 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(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() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } - Ok(response) - } - 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::UPDATE_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) - } - UpdateCreatorResponse::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_CREATOR_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) - } - UpdateCreatorResponse::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_CREATOR_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) - } - 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::UPDATE_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) - } - 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::UPDATE_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) - } - }, - 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) - }) - }, - "UpdateCreator", - ); - - let api_clone = api.clone(); - router.get( - "/v0/auth/check", - 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())))?; - - // 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_role = query_params.get("role").and_then(|list| list.first()).and_then(|x| x.parse::().ok()); - - match api.auth_check(param_role, context).wait() { - Ok(rsp) => match rsp { - AuthCheckResponse::Success(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::AUTH_CHECK_SUCCESS.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) } - AuthCheckResponse::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::AUTH_CHECK_BAD_REQUEST.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - AuthCheckResponse::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::AUTH_CHECK_NOT_AUTHORIZED.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) } - AuthCheckResponse::Forbidden(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(403), body_string)); - response.headers.set(ContentType(mimetypes::responses::AUTH_CHECK_FORBIDDEN.clone())); + let mut response = Response::with((status::Status::from_u16(404), body_string)); + 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) } - AuthCheckResponse::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::AUTH_CHECK_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()))); @@ -2780,12 +2926,12 @@ where Ok(response) }) }, - "AuthCheck", + "LookupCreator", ); let api_clone = api.clone(); - router.post( - "/v0/auth/oidc", + router.put( + "/v0/editgroup/:editgroup_id/creator/:ident", move |req: &mut Request| { let mut context = Context::default(); @@ -2800,50 +2946,66 @@ where 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))))? + }; + let param_ident = { + let param = req + .extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("ident") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter ident".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 ident: {}", e))))? + }; + // 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_oidc_params = req + let param_entity = req .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter oidc_params - not valid UTF-8: {}", e))))?; + .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_oidc_params = if let Some(param_oidc_params_raw) = param_oidc_params { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_oidc_params_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_oidc_params: 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 oidc_params - doesn't match schema: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - param_oidc_params + param_entity } else { None }; - let param_oidc_params = param_oidc_params.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter oidc_params".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.auth_oidc(param_oidc_params, context).wait() { + match api.update_creator(param_editgroup_id, param_ident, param_entity, context).wait() { Ok(rsp) => match rsp { - AuthOidcResponse::Found(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(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_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) - } - AuthOidcResponse::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::AUTH_OIDC_CREATED.clone())); + 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() { @@ -2851,11 +3013,11 @@ where } Ok(response) } - AuthOidcResponse::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::AUTH_OIDC_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() { @@ -2863,14 +3025,14 @@ where } Ok(response) } - AuthOidcResponse::NotAuthorized { body, www_authenticate } => { + UpdateCreatorResponse::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::AUTH_OIDC_NOT_AUTHORIZED.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CREATOR_NOT_AUTHORIZED.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -2878,11 +3040,11 @@ where } Ok(response) } - AuthOidcResponse::Forbidden(body) => { + UpdateCreatorResponse::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::AUTH_OIDC_FORBIDDEN.clone())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_CREATOR_FORBIDDEN.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -2890,11 +3052,11 @@ where } Ok(response) } - AuthOidcResponse::Conflict(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(409), body_string)); - response.headers.set(ContentType(mimetypes::responses::AUTH_OIDC_CONFLICT.clone())); + let mut response = Response::with((status::Status::from_u16(404), body_string)); + 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() { @@ -2902,11 +3064,11 @@ where } Ok(response) } - AuthOidcResponse::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::AUTH_OIDC_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() { @@ -2928,12 +3090,12 @@ where Ok(response) }) }, - "AuthOidc", + "UpdateCreator", ); let api_clone = api.clone(); - router.get( - "/v0/editgroup/reviewable", + router.post( + "/v0/editgroup/:editgroup_id/accept", move |req: &mut Request| { let mut context = Context::default(); @@ -2946,154 +3108,93 @@ 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_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| Some(x.parse::())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?; - let param_before = query_params - .get("before") - .and_then(|list| list.first()) - .and_then(|x| Some(x.parse::>())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; - let param_since = query_params - .get("since") - .and_then(|list| list.first()) - .and_then(|x| Some(x.parse::>())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; + let authorization = context.authorization.as_ref().ok_or_else(|| Response::with((status::Forbidden, "Unauthenticated".to_string())))?; - match api.get_editgroups_reviewable(param_expand, param_limit, param_before, param_since, context).wait() { + // 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))))? + }; + + match api.accept_editgroup(param_editgroup_id, context).wait() { Ok(rsp) => match rsp { - GetEditgroupsReviewableResponse::Found(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_EDITGROUPS_REVIEWABLE_FOUND.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) } - GetEditgroupsReviewableResponse::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_EDITGROUPS_REVIEWABLE_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) } - GetEditgroupsReviewableResponse::NotFound(body) => { + AcceptEditgroupResponse::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(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(401), body_string)); + header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } + response.headers.set(ResponseWwwAuthenticate(www_authenticate)); - let mut response = Response::with((status::Status::from_u16(500), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUPS_REVIEWABLE_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_NOT_AUTHORIZED.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", - 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))))? - }; - - match api.get_editor(param_editor_id, context).wait() { - Ok(rsp) => match rsp { - GetEditorResponse::Found(body) => { + AcceptEditgroupResponse::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(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_FOUND.clone())); + let mut response = Response::with((status::Status::from_u16(403), body_string)); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_FORBIDDEN.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetEditorResponse::BadRequest(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(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_BAD_REQUEST.clone())); + 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) } - GetEditorResponse::NotFound(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(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_NOT_FOUND.clone())); - + 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) } - GetEditorResponse::GenericError(body) => { + 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_EDITOR_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()))); @@ -3113,12 +3214,12 @@ where Ok(response) }) }, - "GetEditor", + "AcceptEditgroup", ); let api_clone = api.clone(); - router.get( - "/v0/editor/:editor_id/editgroups", + router.post( + "/v0/editgroup", move |req: &mut Request| { let mut context = Context::default(); @@ -3131,82 +3232,108 @@ where 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))))? - }; + let authorization = context.authorization.as_ref().ok_or_else(|| Response::with((status::Forbidden, "Unauthenticated".to_string())))?; - // 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| Some(x.parse::())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?; - let param_before = query_params - .get("before") - .and_then(|list| list.first()) - .and_then(|x| Some(x.parse::>())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; - let param_since = query_params - .get("since") - .and_then(|list| list.first()) - .and_then(|x| Some(x.parse::>())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; + // 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_editor_editgroups(param_editor_id, param_limit, param_before, param_since, context).wait() { + 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.create_editgroup(param_editgroup, context).wait() { Ok(rsp) => match rsp { - GetEditorEditgroupsResponse::Found(body) => { + 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(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_EDITGROUPS_FOUND.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) } - GetEditorEditgroupsResponse::BadRequest(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(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_EDITGROUPS_BAD_REQUEST.clone())); + 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) + } + CreateEditgroupResponse::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_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) + } + CreateEditgroupResponse::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_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) } - GetEditorEditgroupsResponse::NotFound(body) => { + CreateEditgroupResponse::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_EDITGROUPS_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_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) } - GetEditorEditgroupsResponse::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::GET_EDITOR_EDITGROUPS_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) } }, @@ -3223,12 +3350,12 @@ where Ok(response) }) }, - "GetEditorEditgroups", + "CreateEditgroup", ); let api_clone = api.clone(); - router.put( - "/v0/editgroup/:editgroup_id", + router.post( + "/v0/editgroup/:editgroup_id/annotation", move |req: &mut Request| { let mut context = Context::default(); @@ -3258,47 +3385,38 @@ where .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| Some(x.to_lowercase().parse::())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected boolean)".to_string())))?; - // 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 + let param_annotation = req .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editgroup - not valid UTF-8: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter annotation - 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_annotation = if let Some(param_annotation_raw) = param_annotation { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_annotation_raw); - let param_editgroup: Option = serde_ignored::deserialize(deserializer, |path| { + 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 editgroup - doesn't match schema: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter annotation - doesn't match schema: {}", e))))?; - param_editgroup + param_annotation } else { None }; - let param_editgroup = param_editgroup.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter editgroup".to_string())))?; + let param_annotation = param_annotation.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter annotation".to_string())))?; - match api.update_editgroup(param_editgroup_id, param_editgroup, param_submit, context).wait() { + match api.create_editgroup_annotation(param_editgroup_id, param_annotation, context).wait() { Ok(rsp) => match rsp { - UpdateEditgroupResponse::UpdatedEditgroup(body) => { + 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(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITGROUP_UPDATED_EDITGROUP.clone())); + 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() { @@ -3306,11 +3424,11 @@ where } Ok(response) } - UpdateEditgroupResponse::BadRequest(body) => { + 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::UPDATE_EDITGROUP_BAD_REQUEST.clone())); + 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() { @@ -3318,14 +3436,14 @@ where } Ok(response) } - UpdateEditgroupResponse::NotAuthorized { body, www_authenticate } => { + 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::UPDATE_EDITGROUP_NOT_AUTHORIZED.clone())); + 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() { @@ -3333,11 +3451,11 @@ where } Ok(response) } - UpdateEditgroupResponse::Forbidden(body) => { + 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::UPDATE_EDITGROUP_FORBIDDEN.clone())); + 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() { @@ -3345,11 +3463,11 @@ where } Ok(response) } - UpdateEditgroupResponse::NotFound(body) => { + 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::UPDATE_EDITGROUP_NOT_FOUND.clone())); + 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() { @@ -3357,11 +3475,11 @@ where } Ok(response) } - UpdateEditgroupResponse::GenericError(body) => { + 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::UPDATE_EDITGROUP_GENERIC_ERROR.clone())); + 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() { @@ -3383,12 +3501,12 @@ where Ok(response) }) }, - "UpdateEditgroup", + "CreateEditgroupAnnotation", ); let api_clone = api.clone(); - router.put( - "/v0/editor/:editor_id", + router.get( + "/v0/editgroup/:editgroup_id", move |req: &mut Request| { let mut context = Context::default(); @@ -3401,123 +3519,61 @@ where 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_editor_id = { + let param_editgroup_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))))? - }; - - // 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_editor = req - .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editor - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_editor = if let Some(param_editor_raw) = param_editor { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_editor_raw); - - let param_editor: 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 editor - doesn't match schema: {}", e))))?; - - param_editor - } else { - None - }; - let param_editor = param_editor.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter editor".to_string())))?; - - match api.update_editor(param_editor_id, param_editor, context).wait() { - Ok(rsp) => match rsp { - UpdateEditorResponse::UpdatedEditor(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_EDITOR_UPDATED_EDITOR.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) - } - UpdateEditorResponse::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_EDITOR_BAD_REQUEST.clone())); + .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))))? + }; - 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) - } - UpdateEditorResponse::NotAuthorized { body, www_authenticate } => { + match api.get_editgroup(param_editgroup_id, context).wait() { + Ok(rsp) => match rsp { + 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(401), body_string)); - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - response.headers.set(ResponseWwwAuthenticate(www_authenticate)); - - response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITOR_NOT_AUTHORIZED.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + 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) } - UpdateEditorResponse::Forbidden(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(403), body_string)); - response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITOR_FORBIDDEN.clone())); + let mut response = Response::with((status::Status::from_u16(400), body_string)); + 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) } - UpdateEditorResponse::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_EDITOR_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) } - UpdateEditorResponse::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_EDITOR_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) } }, @@ -3534,12 +3590,12 @@ where Ok(response) }) }, - "UpdateEditor", + "GetEditgroup", ); let api_clone = api.clone(); - router.post( - "/v0/editgroup/:editgroup_id/accept", + router.get( + "/v0/editgroup/:editgroup_id/annotations", move |req: &mut Request| { let mut context = Context::default(); @@ -3552,8 +3608,6 @@ where 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 @@ -3569,76 +3623,70 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter editgroup_id: {}", e))))? }; - match api.accept_editgroup(param_editgroup_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()); + + match api.get_editgroup_annotations(param_editgroup_id, param_expand, context).wait() { Ok(rsp) => match rsp { - AcceptEditgroupResponse::MergedSuccessfully(body) => { + 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::ACCEPT_EDITGROUP_MERGED_SUCCESSFULLY.clone())); + 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) } - AcceptEditgroupResponse::BadRequest(body) => { + 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::ACCEPT_EDITGROUP_BAD_REQUEST.clone())); + 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) } - AcceptEditgroupResponse::NotAuthorized { body, www_authenticate } => { + 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::ACCEPT_EDITGROUP_NOT_AUTHORIZED.clone())); + 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) } - AcceptEditgroupResponse::Forbidden(body) => { + 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::ACCEPT_EDITGROUP_FORBIDDEN.clone())); + 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) } - AcceptEditgroupResponse::NotFound(body) => { + 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::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_EDITGROUP_ANNOTATIONS_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - AcceptEditgroupResponse::GenericError(body) => { + 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::ACCEPT_EDITGROUP_GENERIC_ERROR.clone())); + 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()))); @@ -3658,12 +3706,12 @@ where Ok(response) }) }, - "AcceptEditgroup", + "GetEditgroupAnnotations", ); let api_clone = api.clone(); - router.post( - "/v0/editgroup", + router.get( + "/v0/editgroup/reviewable", move |req: &mut Request| { let mut context = Context::default(); @@ -3676,108 +3724,68 @@ where 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())))?; - - // 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())))?; + // 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| Some(x.parse::())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?; + let param_before = query_params + .get("before") + .and_then(|list| list.first()) + .and_then(|x| Some(x.parse::>())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; + let param_since = query_params + .get("since") + .and_then(|list| list.first()) + .and_then(|x| Some(x.parse::>())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; - match api.create_editgroup(param_editgroup, context).wait() { + match api.get_editgroups_reviewable(param_expand, param_limit, param_before, param_since, context).wait() { Ok(rsp) => match rsp { - CreateEditgroupResponse::SuccessfullyCreated(body) => { + 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(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_EDITGROUPS_REVIEWABLE_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) => { - 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())); - 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::NotAuthorized { body, www_authenticate } => { + 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(401), body_string)); - header! { (ResponseWwwAuthenticate, "WWW_Authenticate") => [String] } - response.headers.set(ResponseWwwAuthenticate(www_authenticate)); - - response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_NOT_AUTHORIZED.clone())); + 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()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } - Ok(response) - } - CreateEditgroupResponse::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_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) } - CreateEditgroupResponse::NotFound(body) => { + 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::CREATE_EDITGROUP_NOT_FOUND.clone())); + 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()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - CreateEditgroupResponse::GenericError(body) => { + 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::CREATE_EDITGROUP_GENERIC_ERROR.clone())); + 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()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -3794,12 +3802,12 @@ where Ok(response) }) }, - "CreateEditgroup", + "GetEditgroupsReviewable", ); let api_clone = api.clone(); - router.post( - "/v0/editgroup/:editgroup_id/annotation", + router.put( + "/v0/editgroup/:editgroup_id", move |req: &mut Request| { let mut context = Context::default(); @@ -3829,38 +3837,47 @@ where .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| Some(x.to_lowercase().parse::())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected boolean)".to_string())))?; + // 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_annotation = req + let param_editgroup = req .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter annotation - not valid UTF-8: {}", e))))?; + .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_annotation = if let Some(param_annotation_raw) = param_annotation { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_annotation_raw); + let param_editgroup = if let Some(param_editgroup_raw) = param_editgroup { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_editgroup_raw); - let param_annotation: Option = serde_ignored::deserialize(deserializer, |path| { + 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 annotation - doesn't match schema: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editgroup - doesn't match schema: {}", e))))?; - param_annotation + param_editgroup } else { None }; - let param_annotation = param_annotation.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter annotation".to_string())))?; + let param_editgroup = param_editgroup.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter editgroup".to_string())))?; - match api.create_editgroup_annotation(param_editgroup_id, param_annotation, context).wait() { + match api.update_editgroup(param_editgroup_id, param_editgroup, param_submit, context).wait() { Ok(rsp) => match rsp { - CreateEditgroupAnnotationResponse::Created(body) => { + 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(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_ANNOTATION_CREATED.clone())); + 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() { @@ -3868,11 +3885,11 @@ where } Ok(response) } - CreateEditgroupAnnotationResponse::BadRequest(body) => { + 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::CREATE_EDITGROUP_ANNOTATION_BAD_REQUEST.clone())); + 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() { @@ -3880,14 +3897,14 @@ where } Ok(response) } - CreateEditgroupAnnotationResponse::NotAuthorized { body, www_authenticate } => { + 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::CREATE_EDITGROUP_ANNOTATION_NOT_AUTHORIZED.clone())); + 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() { @@ -3895,11 +3912,11 @@ where } Ok(response) } - CreateEditgroupAnnotationResponse::Forbidden(body) => { + 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::CREATE_EDITGROUP_ANNOTATION_FORBIDDEN.clone())); + 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() { @@ -3907,11 +3924,11 @@ where } Ok(response) } - CreateEditgroupAnnotationResponse::NotFound(body) => { + 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::CREATE_EDITGROUP_ANNOTATION_NOT_FOUND.clone())); + 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() { @@ -3919,11 +3936,11 @@ where } Ok(response) } - CreateEditgroupAnnotationResponse::GenericError(body) => { + 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::CREATE_EDITGROUP_ANNOTATION_GENERIC_ERROR.clone())); + 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() { @@ -3945,85 +3962,12 @@ where 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| Some(x.parse::())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".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"); - - 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"); - - 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", + "UpdateEditgroup", ); let api_clone = api.clone(); router.get( - "/v0/changelog/:index", + "/v0/editor/:editor_id", move |req: &mut Request| { let mut context = Context::default(); @@ -4037,57 +3981,57 @@ where context.authorization = req.extensions.remove::(); // Path parameters - let param_index = { + let param_editor_id = { let param = req .extensions .get::() .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("index") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter index".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 index: {}", e))))? + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter editor_id: {}", e))))? }; - match api.get_changelog_entry(param_index, context).wait() { + match api.get_editor(param_editor_id, context).wait() { Ok(rsp) => match rsp { - GetChangelogEntryResponse::FoundChangelogEntry(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(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_CHANGELOG_ENTRY_FOUND_CHANGELOG_ENTRY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - GetChangelogEntryResponse::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::GET_CHANGELOG_ENTRY_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()))); Ok(response) } - GetChangelogEntryResponse::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::GET_CHANGELOG_ENTRY_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()))); Ok(response) } - GetChangelogEntryResponse::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::GET_CHANGELOG_ENTRY_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()))); @@ -4107,12 +4051,12 @@ where Ok(response) }) }, - "GetChangelogEntry", + "GetEditor", ); let api_clone = api.clone(); router.get( - "/v0/editgroup/:editgroup_id", + "/v0/editor/:editor_id/annotations", move |req: &mut Request| { let mut context = Context::default(); @@ -4126,57 +4070,101 @@ where context.authorization = req.extensions.remove::(); // Path parameters - let param_editgroup_id = { + let param_editor_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())))?; + .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 editgroup_id: {}", e))))? + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter editor_id: {}", e))))? }; - match api.get_editgroup(param_editgroup_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| Some(x.parse::())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?; + let param_before = query_params + .get("before") + .and_then(|list| list.first()) + .and_then(|x| Some(x.parse::>())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; + let param_since = query_params + .get("since") + .and_then(|list| list.first()) + .and_then(|x| Some(x.parse::>())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; + + match api.get_editor_annotations(param_editor_id, param_limit, param_before, param_since, context).wait() { Ok(rsp) => match rsp { - GetEditgroupResponse::Found(body) => { + 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_EDITGROUP_FOUND.clone())); + 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) } - GetEditgroupResponse::BadRequest(body) => { + 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_EDITGROUP_BAD_REQUEST.clone())); + 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) } - GetEditgroupResponse::NotFound(body) => { + 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_EDITGROUP_NOT_FOUND.clone())); + 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) } - GetEditgroupResponse::GenericError(body) => { + 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_EDITGROUP_GENERIC_ERROR.clone())); + 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()))); @@ -4196,12 +4184,12 @@ where Ok(response) }) }, - "GetEditgroup", + "GetEditorAnnotations", ); let api_clone = api.clone(); router.get( - "/v0/editgroup/:editgroup_id/annotations", + "/v0/editor/:editor_id/editgroups", move |req: &mut Request| { let mut context = Context::default(); @@ -4215,84 +4203,78 @@ where context.authorization = req.extensions.remove::(); // Path parameters - let param_editgroup_id = { + let param_editor_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())))?; + .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 editgroup_id: {}", e))))? + .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_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| Some(x.parse::())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?; + let param_before = query_params + .get("before") + .and_then(|list| list.first()) + .and_then(|x| Some(x.parse::>())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; + let param_since = query_params + .get("since") + .and_then(|list| list.first()) + .and_then(|x| Some(x.parse::>())) + .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) + .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; - match api.get_editgroup_annotations(param_editgroup_id, param_expand, context).wait() { + match api.get_editor_editgroups(param_editor_id, param_limit, param_before, param_since, 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 } => { + 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(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())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + 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) } - GetEditgroupAnnotationsResponse::Forbidden(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(403), body_string)); - response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_ANNOTATIONS_FORBIDDEN.clone())); + let mut response = Response::with((status::Status::from_u16(400), body_string)); + 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) } - GetEditgroupAnnotationsResponse::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_EDITGROUP_ANNOTATIONS_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) } - GetEditgroupAnnotationsResponse::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_EDITGROUP_ANNOTATIONS_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()))); @@ -4312,12 +4294,12 @@ where Ok(response) }) }, - "GetEditgroupAnnotations", + "GetEditorEditgroups", ); let api_clone = api.clone(); - router.get( - "/v0/editor/:editor_id/annotations", + router.put( + "/v0/editor/:editor_id", move |req: &mut Request| { let mut context = Context::default(); @@ -4330,6 +4312,8 @@ where 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_editor_id = { let param = req @@ -4345,90 +4329,106 @@ where .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| Some(x.parse::())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected integer)".to_string())))?; - let param_before = query_params - .get("before") - .and_then(|list| list.first()) - .and_then(|x| Some(x.parse::>())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; - let param_since = query_params - .get("since") - .and_then(|list| list.first()) - .and_then(|x| Some(x.parse::>())) - .map_or_else(|| Ok(None), |x| x.map(|v| Some(v))) - .map_err(|x| Response::with((status::BadRequest, "unparsable query parameter (expected UTC datetime in ISO/RFC format)".to_string())))?; + // 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_editor_annotations(param_editor_id, param_limit, param_before, param_since, context).wait() { + let param_editor = req + .get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter editor - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_editor = if let Some(param_editor_raw) = param_editor { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_editor_raw); + + let param_editor: 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 editor - doesn't match schema: {}", e))))?; + + param_editor + } else { + None + }; + let param_editor = param_editor.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter editor".to_string())))?; + + match api.update_editor(param_editor_id, param_editor, context).wait() { Ok(rsp) => match rsp { - GetEditorAnnotationsResponse::Success(body) => { + UpdateEditorResponse::UpdatedEditor(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())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITOR_UPDATED_EDITOR.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) } - GetEditorAnnotationsResponse::BadRequest(body) => { + UpdateEditorResponse::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())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_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) } - GetEditorAnnotationsResponse::NotAuthorized { body, www_authenticate } => { + UpdateEditorResponse::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())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITOR_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) } - GetEditorAnnotationsResponse::Forbidden(body) => { + UpdateEditorResponse::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())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_EDITOR_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) } - GetEditorAnnotationsResponse::NotFound(body) => { + UpdateEditorResponse::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())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_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) } - GetEditorAnnotationsResponse::GenericError(body) => { + UpdateEditorResponse::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())); + response.headers.set(ContentType(mimetypes::responses::UPDATE_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) } }, @@ -4445,7 +4445,7 @@ where Ok(response) }) }, - "GetEditorAnnotations", + "UpdateEditor", ); let api_clone = api.clone(); @@ -6904,170 +6904,34 @@ 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 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_editgroup_id, param_entity, 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::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_RELEASE_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) - } - CreateReleaseResponse::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_RELEASE_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) - } - 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/editgroup/auto/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::(); - - let authorization = context.authorization.as_ref().ok_or_else(|| Response::with((status::Forbidden, "Unauthenticated".to_string())))?; - - // 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_auto_batch = req + let param_entity = req .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter auto_batch - not valid UTF-8: {}", e))))?; + .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_auto_batch = if let Some(param_auto_batch_raw) = param_auto_batch { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_auto_batch_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_auto_batch: 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 auto_batch - doesn't match schema: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - param_auto_batch + param_entity } else { None }; - let param_auto_batch = param_auto_batch.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter auto_batch".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.create_release_auto_batch(param_auto_batch, context).wait() { + match api.create_release(param_editgroup_id, param_entity, context).wait() { Ok(rsp) => match rsp { - CreateReleaseAutoBatchResponse::CreatedEditgroup(body) => { + 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_AUTO_BATCH_CREATED_EDITGROUP.clone())); + 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() { @@ -7075,11 +6939,11 @@ where } Ok(response) } - CreateReleaseAutoBatchResponse::BadRequest(body) => { + 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_AUTO_BATCH_BAD_REQUEST.clone())); + 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() { @@ -7087,14 +6951,14 @@ where } Ok(response) } - CreateReleaseAutoBatchResponse::NotAuthorized { body, www_authenticate } => { + CreateReleaseResponse::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_RELEASE_AUTO_BATCH_NOT_AUTHORIZED.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_NOT_AUTHORIZED.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7102,11 +6966,11 @@ where } Ok(response) } - CreateReleaseAutoBatchResponse::Forbidden(body) => { + CreateReleaseResponse::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_RELEASE_AUTO_BATCH_FORBIDDEN.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_FORBIDDEN.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7114,11 +6978,11 @@ where } Ok(response) } - CreateReleaseAutoBatchResponse::NotFound(body) => { + 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_AUTO_BATCH_NOT_FOUND.clone())); + 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() { @@ -7126,11 +6990,11 @@ where } Ok(response) } - CreateReleaseAutoBatchResponse::GenericError(body) => { + 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_AUTO_BATCH_GENERIC_ERROR.clone())); + 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() { @@ -7152,12 +7016,12 @@ where Ok(response) }) }, - "CreateReleaseAutoBatch", + "CreateRelease", ); let api_clone = api.clone(); router.post( - "/v0/editgroup/:editgroup_id/work", + "/v0/editgroup/auto/release/batch", move |req: &mut Request| { let mut context = Context::default(); @@ -7172,53 +7036,38 @@ where 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))))? - }; - // 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 + let param_auto_batch = req .get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter auto_batch - 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_auto_batch = if let Some(param_auto_batch_raw) = param_auto_batch { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_auto_batch_raw); - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { + let param_auto_batch: 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))))?; + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter auto_batch - doesn't match schema: {}", e))))?; - param_entity + param_auto_batch } else { None }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + let param_auto_batch = param_auto_batch.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter auto_batch".to_string())))?; - match api.create_work(param_editgroup_id, param_entity, context).wait() { + match api.create_release_auto_batch(param_auto_batch, context).wait() { Ok(rsp) => match rsp { - CreateWorkResponse::CreatedEntity(body) => { + CreateReleaseAutoBatchResponse::CreatedEditgroup(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())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_AUTO_BATCH_CREATED_EDITGROUP.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7226,11 +7075,11 @@ where } Ok(response) } - CreateWorkResponse::BadRequest(body) => { + CreateReleaseAutoBatchResponse::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::CREATE_RELEASE_AUTO_BATCH_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7238,14 +7087,14 @@ where } Ok(response) } - CreateWorkResponse::NotAuthorized { body, www_authenticate } => { + CreateReleaseAutoBatchResponse::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_WORK_NOT_AUTHORIZED.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_AUTO_BATCH_NOT_AUTHORIZED.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7253,11 +7102,11 @@ where } Ok(response) } - CreateWorkResponse::Forbidden(body) => { + CreateReleaseAutoBatchResponse::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_WORK_FORBIDDEN.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_AUTO_BATCH_FORBIDDEN.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7265,11 +7114,11 @@ where } Ok(response) } - CreateWorkResponse::NotFound(body) => { + CreateReleaseAutoBatchResponse::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::CREATE_RELEASE_AUTO_BATCH_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7277,11 +7126,11 @@ where } Ok(response) } - CreateWorkResponse::GenericError(body) => { + CreateReleaseAutoBatchResponse::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::CREATE_RELEASE_AUTO_BATCH_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -7303,7 +7152,7 @@ where Ok(response) }) }, - "CreateWork", + "CreateReleaseAutoBatch", ); let api_clone = api.clone(); @@ -9742,6 +9591,157 @@ where "UpdateWebcapture", ); + let api_clone = api.clone(); + router.post( + "/v0/editgroup/:editgroup_id/work", + 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))))? + }; + + // 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_work(param_editgroup_id, param_entity, 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::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_WORK_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) + } + CreateWorkResponse::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_WORK_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) + } + 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.post( "/v0/editgroup/auto/work/batch", -- cgit v1.2.3