From 0bc7522d8c658a099c1106b7fade3c4d2acc9775 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 28 May 2018 14:48:15 -0700 Subject: refactor to more ergonomic operation names --- rust/fatcat-api/src/server.rs | 1433 ++++++++++++++++++++--------------------- 1 file changed, 716 insertions(+), 717 deletions(-) (limited to 'rust/fatcat-api/src/server.rs') diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs index 0db2c445..3e003783 100644 --- a/rust/fatcat-api/src/server.rs +++ b/rust/fatcat-api/src/server.rs @@ -36,10 +36,9 @@ use swagger::{ApiError, Context, XSpanId}; #[allow(unused_imports)] use models; -use {Api, ContainerBatchPostResponse, ContainerIdGetResponse, ContainerLookupGetResponse, ContainerPostResponse, CreatorBatchPostResponse, CreatorIdGetResponse, CreatorLookupGetResponse, - CreatorPostResponse, EditgroupIdAcceptPostResponse, EditgroupIdGetResponse, EditgroupPostResponse, EditorUsernameChangelogGetResponse, EditorUsernameGetResponse, FileBatchPostResponse, - FileIdGetResponse, FileLookupGetResponse, FilePostResponse, ReleaseBatchPostResponse, ReleaseIdGetResponse, ReleaseLookupGetResponse, ReleasePostResponse, WorkBatchPostResponse, - WorkIdGetResponse, WorkPostResponse}; +use {AcceptEditgroupResponse, Api, CreateContainerBatchResponse, CreateContainerResponse, CreateCreatorBatchResponse, CreateCreatorResponse, CreateEditgroupResponse, CreateFileBatchResponse, + CreateFileResponse, CreateReleaseBatchResponse, CreateReleaseResponse, CreateWorkBatchResponse, CreateWorkResponse, GetContainerResponse, GetCreatorResponse, GetEditgroupResponse, + GetEditorChangelogResponse, GetEditorResponse, GetFileResponse, GetReleaseResponse, GetWorkResponse, LookupContainerResponse, LookupCreatorResponse, LookupFileResponse, LookupReleaseResponse}; header! { (Warning, "Warning") => [String] } @@ -88,7 +87,7 @@ where { let api_clone = api.clone(); router.post( - "/v0/container/batch", + "/v0/editgroup/:id/accept", move |req: &mut Request| { let mut context = Context::default(); @@ -101,78 +100,60 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity_list = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - - let param_entity_list: Option> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; - - param_entity_list - } else { - None + // Path parameters + let param_id = { + let param = req.extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.container_batch_post(param_entity_list.as_ref(), context).wait() { + match api.accept_editgroup(param_id, context).wait() { Ok(rsp) => match rsp { - ContainerBatchPostResponse::CreatedEntities(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(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_BATCH_POST_CREATED_ENTITIES.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + 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()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ContainerBatchPostResponse::BadRequest(body) => { + AcceptEditgroupResponse::Unmergable(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_BATCH_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_UNMERGABLE.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) } - ContainerBatchPostResponse::NotFound(body) => { + AcceptEditgroupResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_BATCH_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::ACCEPT_EDITGROUP_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ContainerBatchPostResponse::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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_BATCH_POST_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()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -189,12 +170,12 @@ where Ok(response) }) }, - "ContainerBatchPost", + "AcceptEditgroup", ); let api_clone = api.clone(); - router.get( - "/v0/container/:id", + router.post( + "/v0/container", move |req: &mut Request| { let mut context = Context::default(); @@ -207,60 +188,78 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req.extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + // 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.container_id_get(param_id, context).wait() { + match api.create_container(param_entity, context).wait() { Ok(rsp) => match rsp { - ContainerIdGetResponse::FoundEntity(body) => { + 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(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_FOUND_ENTITY.clone())); + 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) } - ContainerIdGetResponse::BadRequest(body) => { + 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::CONTAINER_ID_GET_BAD_REQUEST.clone())); + 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) } - ContainerIdGetResponse::NotFound(body) => { + 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::CONTAINER_ID_GET_NOT_FOUND.clone())); + 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) } - ContainerIdGetResponse::GenericError(body) => { + 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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_ID_GET_GENERIC_ERROR.clone())); + 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) } }, @@ -277,12 +276,12 @@ where Ok(response) }) }, - "ContainerIdGet", + "CreateContainer", ); let api_clone = api.clone(); - router.get( - "/v0/container/lookup", + router.post( + "/v0/container/batch", move |req: &mut Request| { let mut context = Context::default(); @@ -295,56 +294,78 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_issnl = query_params - .get("issnl") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter issnl".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issnl was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter issnl - doesn't match schema: {}", e))))?; + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity_list = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); + + let param_entity_list: Option> = + serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + + param_entity_list + } else { + None + }; + let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.container_lookup_get(param_issnl, context).wait() { + match api.create_container_batch(param_entity_list.as_ref(), context).wait() { Ok(rsp) => match rsp { - ContainerLookupGetResponse::FoundEntity(body) => { + CreateContainerBatchResponse::CreatedEntities(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_FOUND_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_CONTAINER_BATCH_CREATED_ENTITIES.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - ContainerLookupGetResponse::BadRequest(body) => { + CreateContainerBatchResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CONTAINER_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) } - ContainerLookupGetResponse::NotFound(body) => { + CreateContainerBatchResponse::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::CONTAINER_LOOKUP_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CONTAINER_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) } - ContainerLookupGetResponse::GenericError(body) => { + CreateContainerBatchResponse::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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_LOOKUP_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CONTAINER_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) } }, @@ -361,12 +382,12 @@ where Ok(response) }) }, - "ContainerLookupGet", + "CreateContainerBatch", ); let api_clone = api.clone(); router.post( - "/v0/container", + "/v0/creator", move |req: &mut Request| { let mut context = Context::default(); @@ -391,7 +412,7 @@ where let param_entity = if let Some(param_entity_raw) = param_entity { let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_entity: Option = + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); @@ -403,13 +424,13 @@ where }; let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.container_post(param_entity, context).wait() { + match api.create_creator(param_entity, context).wait() { Ok(rsp) => match rsp { - ContainerPostResponse::CreatedEntity(body) => { + CreateCreatorResponse::CreatedEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_CREATED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_CREATED_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -417,11 +438,11 @@ where } Ok(response) } - ContainerPostResponse::BadRequest(body) => { + CreateCreatorResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -429,11 +450,11 @@ where } Ok(response) } - ContainerPostResponse::NotFound(body) => { + CreateCreatorResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -441,11 +462,11 @@ where } Ok(response) } - ContainerPostResponse::GenericError(body) => { + CreateCreatorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CONTAINER_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -467,7 +488,7 @@ where Ok(response) }) }, - "ContainerPost", + "CreateCreator", ); let api_clone = api.clone(); @@ -509,13 +530,13 @@ where }; let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.creator_batch_post(param_entity_list.as_ref(), context).wait() { + match api.create_creator_batch(param_entity_list.as_ref(), context).wait() { Ok(rsp) => match rsp { - CreatorBatchPostResponse::CreatedEntities(body) => { + CreateCreatorBatchResponse::CreatedEntities(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_BATCH_POST_CREATED_ENTITIES.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_CREATED_ENTITIES.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -523,11 +544,11 @@ where } Ok(response) } - CreatorBatchPostResponse::BadRequest(body) => { + CreateCreatorBatchResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_BATCH_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -535,11 +556,11 @@ where } Ok(response) } - CreatorBatchPostResponse::NotFound(body) => { + CreateCreatorBatchResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_BATCH_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -547,11 +568,11 @@ where } Ok(response) } - CreatorBatchPostResponse::GenericError(body) => { + CreateCreatorBatchResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_BATCH_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_CREATOR_BATCH_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -573,12 +594,12 @@ where Ok(response) }) }, - "CreatorBatchPost", + "CreateCreatorBatch", ); let api_clone = api.clone(); - router.get( - "/v0/creator/:id", + router.post( + "/v0/editgroup", move |req: &mut Request| { let mut context = Context::default(); @@ -591,60 +612,65 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req.extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; + // 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.creator_id_get(param_id, context).wait() { - Ok(rsp) => match rsp { - CreatorIdGetResponse::FoundEntity(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + 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 response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_FOUND_ENTITY.clone())); + let mut unused_elements = Vec::new(); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - Ok(response) - } - CreatorIdGetResponse::BadRequest(body) => { + 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_editgroup(param_entity, context).wait() { + Ok(rsp) => match rsp { + CreateEditgroupResponse::SuccessfullyCreated(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_BAD_REQUEST.clone())); + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_SUCCESSFULLY_CREATED.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - CreatorIdGetResponse::NotFound(body) => { + CreateEditgroupResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_NOT_FOUND.clone())); + let mut response = Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_EDITGROUP_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - CreatorIdGetResponse::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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_ID_GET_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) } }, @@ -661,12 +687,12 @@ where Ok(response) }) }, - "CreatorIdGet", + "CreateEditgroup", ); let api_clone = api.clone(); - router.get( - "/v0/creator/lookup", + router.post( + "/v0/file", move |req: &mut Request| { let mut context = Context::default(); @@ -679,56 +705,78 @@ 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_orcid = query_params - .get("orcid") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter orcid".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter orcid was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter orcid - doesn't match schema: {}", e))))?; - - match api.creator_lookup_get(param_orcid, context).wait() { - Ok(rsp) => match rsp { - CreatorLookupGetResponse::FoundEntity(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_FOUND_ENTITY.clone())); + let param_entity = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + let mut unused_elements = Vec::new(); - Ok(response) - } - CreatorLookupGetResponse::BadRequest(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_BAD_REQUEST.clone())); + let param_entity: Option = + serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + + 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_file(param_entity, context).wait() { + Ok(rsp) => match rsp { + CreateFileResponse::CreatedEntity(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_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) + } + CreateFileResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BAD_REQUEST.clone())); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - CreatorLookupGetResponse::NotFound(body) => { + CreateFileResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - CreatorLookupGetResponse::GenericError(body) => { + CreateFileResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_LOOKUP_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } }, @@ -745,12 +793,12 @@ where Ok(response) }) }, - "CreatorLookupGet", + "CreateFile", ); let api_clone = api.clone(); router.post( - "/v0/creator", + "/v0/file/batch", move |req: &mut Request| { let mut context = Context::default(); @@ -767,33 +815,33 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_entity = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; + let param_entity_list = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); + let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - let param_entity: Option = + let param_entity_list: Option> = serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; - param_entity + param_entity_list } else { None }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; + let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.creator_post(param_entity, context).wait() { + match api.create_file_batch(param_entity_list.as_ref(), context).wait() { Ok(rsp) => match rsp { - CreatorPostResponse::CreatedEntity(body) => { + CreateFileBatchResponse::CreatedEntities(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_CREATED_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_CREATED_ENTITIES.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -801,11 +849,11 @@ where } Ok(response) } - CreatorPostResponse::BadRequest(body) => { + CreateFileBatchResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -813,11 +861,11 @@ where } Ok(response) } - CreatorPostResponse::NotFound(body) => { + CreateFileBatchResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -825,11 +873,11 @@ where } Ok(response) } - CreatorPostResponse::GenericError(body) => { + CreateFileBatchResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::CREATOR_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_FILE_BATCH_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -851,12 +899,12 @@ where Ok(response) }) }, - "CreatorPost", + "CreateFileBatch", ); let api_clone = api.clone(); router.post( - "/v0/editgroup/:id/accept", + "/v0/release", move |req: &mut Request| { let mut context = Context::default(); @@ -869,60 +917,78 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req.extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + // 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.editgroup_id_accept_post(param_id, context).wait() { + match api.create_release(param_entity, context).wait() { Ok(rsp) => match rsp { - EditgroupIdAcceptPostResponse::MergedSuccessfully(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(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_MERGED_SUCCESSFULLY.clone())); + 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) } - EditgroupIdAcceptPostResponse::Unmergable(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::EDITGROUP_ID_ACCEPT_POST_UNMERGABLE.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() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - EditgroupIdAcceptPostResponse::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::EDITGROUP_ID_ACCEPT_POST_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() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - EditgroupIdAcceptPostResponse::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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_ACCEPT_POST_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() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } }, @@ -939,12 +1005,12 @@ where Ok(response) }) }, - "EditgroupIdAcceptPost", + "CreateRelease", ); let api_clone = api.clone(); - router.get( - "/v0/editgroup/:id", + router.post( + "/v0/release/batch", move |req: &mut Request| { let mut context = Context::default(); @@ -957,60 +1023,78 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req.extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity_list = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); + + let param_entity_list: Option> = + serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + + param_entity_list + } else { + None }; + let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.editgroup_id_get(param_id, context).wait() { + match api.create_release_batch(param_entity_list.as_ref(), context).wait() { Ok(rsp) => match rsp { - EditgroupIdGetResponse::FoundEntity(body) => { + CreateReleaseBatchResponse::CreatedEntities(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_FOUND_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_BATCH_CREATED_ENTITIES.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - EditgroupIdGetResponse::BadRequest(body) => { + CreateReleaseBatchResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_BATCH_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - EditgroupIdGetResponse::NotFound(body) => { + CreateReleaseBatchResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_BATCH_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - EditgroupIdGetResponse::GenericError(body) => { + CreateReleaseBatchResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_ID_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_RELEASE_BATCH_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } }, @@ -1027,12 +1111,12 @@ where Ok(response) }) }, - "EditgroupIdGet", + "CreateReleaseBatch", ); let api_clone = api.clone(); router.post( - "/v0/editgroup", + "/v0/work", move |req: &mut Request| { let mut context = Context::default(); @@ -1057,10 +1141,11 @@ where let param_entity = if let Some(param_entity_raw) = param_entity { let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { - 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))))?; + 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 { @@ -1068,13 +1153,13 @@ where }; let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.editgroup_post(param_entity, context).wait() { + match api.create_work(param_entity, context).wait() { Ok(rsp) => match rsp { - EditgroupPostResponse::SuccessfullyCreated(body) => { + 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::EDITGROUP_POST_SUCCESSFULLY_CREATED.clone())); + 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() { @@ -1082,11 +1167,23 @@ where } Ok(response) } - EditgroupPostResponse::BadRequest(body) => { + 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::EDITGROUP_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_BAD_REQUEST.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } + Ok(response) + } + CreateWorkResponse::NotFound(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(404), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); if !unused_elements.is_empty() { @@ -1094,11 +1191,11 @@ where } Ok(response) } - EditgroupPostResponse::GenericError(body) => { + 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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITGROUP_POST_GENERIC_ERROR.clone())); + 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() { @@ -1120,12 +1217,12 @@ where Ok(response) }) }, - "EditgroupPost", + "CreateWork", ); let api_clone = api.clone(); - router.get( - "/v0/editor/:username/changelog", + router.post( + "/v0/work/batch", move |req: &mut Request| { let mut context = Context::default(); @@ -1138,50 +1235,78 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_username = { - let param = req.extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("username") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))? + // Body parameters (note that non-required body parameters will ignore garbage + // values, rather than causing a 400 response). Produce warning header and logs for + // any unused fields. + + let param_entity_list = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; + + let mut unused_elements = Vec::new(); + + let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); + + let param_entity_list: Option> = + serde_ignored::deserialize(deserializer, |path| { + warn!("Ignoring unknown field in body: {}", path); + unused_elements.push(path.to_string()); + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + + param_entity_list + } else { + None }; + let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.editor_username_changelog_get(param_username, context).wait() { + match api.create_work_batch(param_entity_list.as_ref(), context).wait() { Ok(rsp) => match rsp { - EditorUsernameChangelogGetResponse::FoundMergedChanges(body) => { + CreateWorkBatchResponse::CreatedEntities(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_FOUND_MERGED_CHANGES.clone())); + let mut response = Response::with((status::Status::from_u16(201), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_BATCH_CREATED_ENTITIES.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } + Ok(response) + } + CreateWorkBatchResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_BATCH_BAD_REQUEST.clone())); + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - EditorUsernameChangelogGetResponse::NotFound(body) => { + CreateWorkBatchResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_BATCH_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } - EditorUsernameChangelogGetResponse::GenericError(body) => { + CreateWorkBatchResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_CHANGELOG_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::CREATE_WORK_BATCH_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - + if !unused_elements.is_empty() { + response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); + } Ok(response) } }, @@ -1198,12 +1323,12 @@ where Ok(response) }) }, - "EditorUsernameChangelogGet", + "CreateWorkBatch", ); let api_clone = api.clone(); router.get( - "/v0/editor/:username", + "/v0/container/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -1217,46 +1342,56 @@ where context.authorization = req.extensions.remove::(); // Path parameters - let param_username = { + let param_id = { let param = req.extensions .get::() .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("username") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?; + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; percent_decode(param.as_bytes()) .decode_utf8() .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))? + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - match api.editor_username_get(param_username, context).wait() { + match api.get_container(param_id, context).wait() { Ok(rsp) => match rsp { - EditorUsernameGetResponse::FoundEditor(body) => { + GetContainerResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_FOUND_EDITOR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_FOUND_ENTITY.clone())); + + context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); + + Ok(response) + } + GetContainerResponse::BadRequest(body) => { + let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); + + let mut response = Response::with((status::Status::from_u16(400), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - EditorUsernameGetResponse::NotFound(body) => { + GetContainerResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - EditorUsernameGetResponse::GenericError(body) => { + GetContainerResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::EDITOR_USERNAME_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CONTAINER_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1276,12 +1411,12 @@ where Ok(response) }) }, - "EditorUsernameGet", + "GetContainer", ); let api_clone = api.clone(); - router.post( - "/v0/file/batch", + router.get( + "/v0/creator/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -1294,78 +1429,60 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity_list = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - - let param_entity_list: Option> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; - - param_entity_list - } else { - None + // Path parameters + let param_id = { + let param = req.extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.file_batch_post(param_entity_list.as_ref(), context).wait() { + match api.get_creator(param_id, context).wait() { Ok(rsp) => match rsp { - FileBatchPostResponse::CreatedEntities(body) => { + GetCreatorResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_BATCH_POST_CREATED_ENTITIES.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - FileBatchPostResponse::BadRequest(body) => { + GetCreatorResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_BATCH_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - FileBatchPostResponse::NotFound(body) => { + GetCreatorResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_BATCH_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - FileBatchPostResponse::GenericError(body) => { + GetCreatorResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_BATCH_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_CREATOR_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -1382,12 +1499,12 @@ where Ok(response) }) }, - "FileBatchPost", + "GetCreator", ); let api_clone = api.clone(); router.get( - "/v0/file/:id", + "/v0/editgroup/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -1414,43 +1531,43 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - match api.file_id_get(param_id, context).wait() { + match api.get_editgroup(param_id, context).wait() { Ok(rsp) => match rsp { - FileIdGetResponse::FoundEntity(body) => { + GetEditgroupResponse::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::FILE_ID_GET_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - FileIdGetResponse::BadRequest(body) => { + GetEditgroupResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITGROUP_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - FileIdGetResponse::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::FILE_ID_GET_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()))); Ok(response) } - FileIdGetResponse::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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_ID_GET_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()))); @@ -1470,12 +1587,12 @@ where Ok(response) }) }, - "FileIdGet", + "GetEditgroup", ); let api_clone = api.clone(); router.get( - "/v0/file/lookup", + "/v0/editor/:username", move |req: &mut Request| { let mut context = Context::default(); @@ -1488,53 +1605,47 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_sha1 = query_params - .get("sha1") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter sha1".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter sha1 was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter sha1 - doesn't match schema: {}", e))))?; + // Path parameters + let param_username = { + let param = req.extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("username") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))? + }; - match api.file_lookup_get(param_sha1, context).wait() { + match api.get_editor(param_username, context).wait() { Ok(rsp) => match rsp { - FileLookupGetResponse::FoundEntity(body) => { + GetEditorResponse::FoundEditor(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::FILE_LOOKUP_GET_FOUND_ENTITY.clone())); - - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - - Ok(response) - } - FileLookupGetResponse::BadRequest(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_FOUND_EDITOR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - FileLookupGetResponse::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::FILE_LOOKUP_GET_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) } - FileLookupGetResponse::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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_LOOKUP_GET_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()))); @@ -1554,12 +1665,12 @@ where Ok(response) }) }, - "FileLookupGet", + "GetEditor", ); let api_clone = api.clone(); - router.post( - "/v0/file", + router.get( + "/v0/editor/:username/changelog", move |req: &mut Request| { let mut context = Context::default(); @@ -1572,78 +1683,50 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity = if let Some(param_entity_raw) = param_entity { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - - let param_entity: Option = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - - param_entity - } else { - None + // Path parameters + let param_username = { + let param = req.extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("username") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))? }; - let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.file_post(param_entity, context).wait() { + match api.get_editor_changelog(param_username, context).wait() { Ok(rsp) => match rsp { - FilePostResponse::CreatedEntity(body) => { + GetEditorChangelogResponse::FoundMergedChanges(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_POST_CREATED_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_FOUND_MERGED_CHANGES.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) - } - FilePostResponse::BadRequest(body) => { - let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - - let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_POST_BAD_REQUEST.clone())); - context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } Ok(response) } - FilePostResponse::NotFound(body) => { + GetEditorChangelogResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - FilePostResponse::GenericError(body) => { + GetEditorChangelogResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::FILE_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_EDITOR_CHANGELOG_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -1660,96 +1743,78 @@ where Ok(response) }) }, - "FilePost", + "GetEditorChangelog", ); let api_clone = api.clone(); - router.post( - "/v0/release/batch", - move |req: &mut Request| { - let mut context = Context::default(); - - // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). - fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result - where - T: Api, - { - context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); - context.auth_data = req.extensions.remove::(); - context.authorization = req.extensions.remove::(); - - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity_list = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - - let param_entity_list: Option> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; + router.get( + "/v0/file/:id", + move |req: &mut Request| { + let mut context = Context::default(); - param_entity_list - } else { - None + // Helper function to provide a code block to use `?` in (to be replaced by the `catch` block when it exists). + fn handle_request(req: &mut Request, api: &T, context: &mut Context) -> Result + where + T: Api, + { + context.x_span_id = Some(req.headers.get::().map(XSpanId::to_string).unwrap_or_else(|| self::uuid::Uuid::new_v4().to_string())); + context.auth_data = req.extensions.remove::(); + context.authorization = req.extensions.remove::(); + + // Path parameters + let param_id = { + let param = req.extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; - match api.release_batch_post(param_entity_list.as_ref(), context).wait() { + match api.get_file(param_id, context).wait() { Ok(rsp) => match rsp { - ReleaseBatchPostResponse::CreatedEntities(body) => { + GetFileResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_BATCH_POST_CREATED_ENTITIES.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ReleaseBatchPostResponse::BadRequest(body) => { + GetFileResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_BATCH_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ReleaseBatchPostResponse::NotFound(body) => { + GetFileResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_BATCH_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ReleaseBatchPostResponse::GenericError(body) => { + GetFileResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_BATCH_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_FILE_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -1766,7 +1831,7 @@ where Ok(response) }) }, - "ReleaseBatchPost", + "GetFile", ); let api_clone = api.clone(); @@ -1798,43 +1863,43 @@ where .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? }; - match api.release_id_get(param_id, context).wait() { + match api.get_release(param_id, context).wait() { Ok(rsp) => match rsp { - ReleaseIdGetResponse::FoundEntity(body) => { + GetReleaseResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - ReleaseIdGetResponse::BadRequest(body) => { + GetReleaseResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - ReleaseIdGetResponse::NotFound(body) => { + GetReleaseResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - ReleaseIdGetResponse::GenericError(body) => { + GetReleaseResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_ID_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_RELEASE_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1854,12 +1919,12 @@ where Ok(response) }) }, - "ReleaseIdGet", + "GetRelease", ); let api_clone = api.clone(); router.get( - "/v0/release/lookup", + "/v0/work/:id", move |req: &mut Request| { let mut context = Context::default(); @@ -1872,53 +1937,57 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) - let query_params = req.get::().unwrap_or_default(); - let param_doi = query_params - .get("doi") - .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter doi".to_string())))? - .first() - .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter doi was empty".to_string())))? - .parse::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter doi - doesn't match schema: {}", e))))?; + // Path parameters + let param_id = { + let param = req.extensions + .get::() + .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? + .find("id") + .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; + percent_decode(param.as_bytes()) + .decode_utf8() + .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? + .parse() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? + }; - match api.release_lookup_get(param_doi, context).wait() { + match api.get_work(param_id, context).wait() { Ok(rsp) => match rsp { - ReleaseLookupGetResponse::FoundEntity(body) => { + GetWorkResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - ReleaseLookupGetResponse::BadRequest(body) => { + GetWorkResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - ReleaseLookupGetResponse::NotFound(body) => { + GetWorkResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - ReleaseLookupGetResponse::GenericError(body) => { + GetWorkResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_LOOKUP_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::GET_WORK_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -1938,12 +2007,12 @@ where Ok(response) }) }, - "ReleaseLookupGet", + "GetWork", ); let api_clone = api.clone(); - router.post( - "/v0/release", + router.get( + "/v0/container/lookup", move |req: &mut Request| { let mut context = Context::default(); @@ -1956,78 +2025,56 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_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_issnl = query_params + .get("issnl") + .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter issnl".to_string())))? + .first() + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter issnl was empty".to_string())))? + .parse::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter issnl - doesn't match schema: {}", e))))?; - match api.release_post(param_entity, context).wait() { + match api.lookup_container(param_issnl, context).wait() { Ok(rsp) => match rsp { - ReleasePostResponse::CreatedEntity(body) => { + LookupContainerResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_CREATED_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ReleasePostResponse::BadRequest(body) => { + LookupContainerResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ReleasePostResponse::NotFound(body) => { + LookupContainerResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - ReleasePostResponse::GenericError(body) => { + LookupContainerResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::RELEASE_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CONTAINER_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -2044,12 +2091,12 @@ where Ok(response) }) }, - "ReleasePost", + "LookupContainer", ); let api_clone = api.clone(); - router.post( - "/v0/work/batch", + router.get( + "/v0/creator/lookup", move |req: &mut Request| { let mut context = Context::default(); @@ -2062,78 +2109,56 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_entity_list = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - not valid UTF-8: {}", e))))?; - - let mut unused_elements = Vec::new(); - - let param_entity_list = if let Some(param_entity_list_raw) = param_entity_list { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_list_raw); - - let param_entity_list: Option> = - serde_ignored::deserialize(deserializer, |path| { - warn!("Ignoring unknown field in body: {}", path); - unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity_list - doesn't match schema: {}", e))))?; - - param_entity_list - } else { - None - }; - let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?; + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_orcid = query_params + .get("orcid") + .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter orcid".to_string())))? + .first() + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter orcid was empty".to_string())))? + .parse::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter orcid - doesn't match schema: {}", e))))?; - match api.work_batch_post(param_entity_list.as_ref(), context).wait() { + match api.lookup_creator(param_orcid, context).wait() { Ok(rsp) => match rsp { - WorkBatchPostResponse::CreatedEntities(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(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_BATCH_POST_CREATED_ENTITIES.clone())); + 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()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - WorkBatchPostResponse::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::WORK_BATCH_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CREATOR_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - WorkBatchPostResponse::NotFound(body) => { + LookupCreatorResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_BATCH_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_CREATOR_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - WorkBatchPostResponse::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(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_BATCH_POST_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()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -2150,12 +2175,12 @@ where Ok(response) }) }, - "WorkBatchPost", + "LookupCreator", ); let api_clone = api.clone(); router.get( - "/v0/work/:id", + "/v0/file/lookup", move |req: &mut Request| { let mut context = Context::default(); @@ -2168,57 +2193,53 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Path parameters - let param_id = { - let param = req.extensions - .get::() - .ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))? - .find("id") - .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?; - percent_decode(param.as_bytes()) - .decode_utf8() - .map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))? - .parse() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))? - }; + // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response) + let query_params = req.get::().unwrap_or_default(); + let param_sha1 = query_params + .get("sha1") + .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter sha1".to_string())))? + .first() + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter sha1 was empty".to_string())))? + .parse::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter sha1 - doesn't match schema: {}", e))))?; - match api.work_id_get(param_id, context).wait() { + match api.lookup_file(param_sha1, context).wait() { Ok(rsp) => match rsp { - WorkIdGetResponse::FoundEntity(body) => { + LookupFileResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(200), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_FOUND_ENTITY.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - WorkIdGetResponse::BadRequest(body) => { + LookupFileResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - WorkIdGetResponse::NotFound(body) => { + LookupFileResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); Ok(response) } - WorkIdGetResponse::GenericError(body) => { + LookupFileResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_ID_GET_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_FILE_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); @@ -2238,12 +2259,12 @@ where Ok(response) }) }, - "WorkIdGet", + "LookupFile", ); let api_clone = api.clone(); - router.post( - "/v0/work", + router.get( + "/v0/release/lookup", move |req: &mut Request| { let mut context = Context::default(); @@ -2256,78 +2277,56 @@ where context.auth_data = req.extensions.remove::(); context.authorization = req.extensions.remove::(); - // Body parameters (note that non-required body parameters will ignore garbage - // values, rather than causing a 400 response). Produce warning header and logs for - // any unused fields. - - let param_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_doi = query_params + .get("doi") + .ok_or_else(|| Response::with((status::BadRequest, "Missing required query parameter doi".to_string())))? + .first() + .ok_or_else(|| Response::with((status::BadRequest, "Required query parameter doi was empty".to_string())))? + .parse::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse query parameter doi - doesn't match schema: {}", e))))?; - match api.work_post(param_entity, context).wait() { + match api.lookup_release(param_doi, context).wait() { Ok(rsp) => match rsp { - WorkPostResponse::CreatedEntity(body) => { + LookupReleaseResponse::FoundEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); - let mut response = Response::with((status::Status::from_u16(201), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_POST_CREATED_ENTITY.clone())); + let mut response = Response::with((status::Status::from_u16(200), body_string)); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_FOUND_ENTITY.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - WorkPostResponse::BadRequest(body) => { + LookupReleaseResponse::BadRequest(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(400), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_POST_BAD_REQUEST.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_BAD_REQUEST.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - WorkPostResponse::NotFound(body) => { + LookupReleaseResponse::NotFound(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(404), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_POST_NOT_FOUND.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_NOT_FOUND.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } - WorkPostResponse::GenericError(body) => { + LookupReleaseResponse::GenericError(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); let mut response = Response::with((status::Status::from_u16(0), body_string)); - response.headers.set(ContentType(mimetypes::responses::WORK_POST_GENERIC_ERROR.clone())); + response.headers.set(ContentType(mimetypes::responses::LOOKUP_RELEASE_GENERIC_ERROR.clone())); context.x_span_id.as_ref().map(|header| response.headers.set(XSpanId(header.clone()))); - if !unused_elements.is_empty() { - response.headers.set(Warning(format!("Ignoring unknown fields in body: {:?}", unused_elements))); - } + Ok(response) } }, @@ -2344,7 +2343,7 @@ where Ok(response) }) }, - "WorkPost", + "LookupRelease", ); } -- cgit v1.2.3