From 19eb1641eece9f03ca193417cdf244efc1a9da8a Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 27 May 2018 14:45:07 -0700 Subject: swagger spec: body -> entity --- rust/fatcat-api/src/client.rs | 24 ++++---- rust/fatcat-api/src/lib.rs | 48 ++++++++-------- rust/fatcat-api/src/models.rs | 38 ++++++------- rust/fatcat-api/src/server.rs | 128 ++++++++++++++++++++++-------------------- 4 files changed, 121 insertions(+), 117 deletions(-) (limited to 'rust/fatcat-api/src') diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs index 23f6dd21..d81d251f 100644 --- a/rust/fatcat-api/src/client.rs +++ b/rust/fatcat-api/src/client.rs @@ -284,10 +284,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn container_post(&self, param_body: models::ContainerEntity, context: &Context) -> Box + Send> { + fn container_post(&self, param_entity: models::ContainerEntity, context: &Context) -> Box + Send> { let url = format!("{}/v0/container", self.base_path); - let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -472,10 +472,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn creator_post(&self, param_body: models::CreatorEntity, context: &Context) -> Box + Send> { + fn creator_post(&self, param_entity: models::CreatorEntity, context: &Context) -> Box + Send> { let url = format!("{}/v0/creator", self.base_path); - let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -657,10 +657,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn editgroup_post(&self, param_body: models::Editgroup, context: &Context) -> Box + Send> { + fn editgroup_post(&self, param_entity: models::Editgroup, context: &Context) -> Box + Send> { let url = format!("{}/v0/editgroup", self.base_path); - let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -952,10 +952,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn file_post(&self, param_body: models::FileEntity, context: &Context) -> Box + Send> { + fn file_post(&self, param_entity: models::FileEntity, context: &Context) -> Box + Send> { let url = format!("{}/v0/file", self.base_path); - let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -1140,10 +1140,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn release_post(&self, param_body: models::ReleaseEntity, context: &Context) -> Box + Send> { + fn release_post(&self, param_entity: models::ReleaseEntity, context: &Context) -> Box + Send> { let url = format!("{}/v0/release", self.base_path); - let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); @@ -1265,10 +1265,10 @@ impl Api for Client { Box::new(futures::done(result)) } - fn work_post(&self, param_body: models::WorkEntity, context: &Context) -> Box + Send> { + fn work_post(&self, param_entity: models::WorkEntity, context: &Context) -> Box + Send> { let url = format!("{}/v0/work", self.base_path); - let body = serde_json::to_string(¶m_body).expect("impossible to fail to serialize"); + let body = serde_json::to_string(¶m_entity).expect("impossible to fail to serialize"); let hyper_client = (self.hyper_client)(); let request = hyper_client.request(hyper::method::Method::Post, &url); diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs index a21a0751..dca1aa35 100644 --- a/rust/fatcat-api/src/lib.rs +++ b/rust/fatcat-api/src/lib.rs @@ -260,19 +260,19 @@ pub trait Api { fn container_lookup_get(&self, issnl: String, context: &Context) -> Box + Send>; - fn container_post(&self, body: models::ContainerEntity, context: &Context) -> Box + Send>; + fn container_post(&self, entity: models::ContainerEntity, context: &Context) -> Box + Send>; fn creator_id_get(&self, id: String, context: &Context) -> Box + Send>; fn creator_lookup_get(&self, orcid: String, context: &Context) -> Box + Send>; - fn creator_post(&self, body: models::CreatorEntity, context: &Context) -> Box + Send>; + fn creator_post(&self, entity: models::CreatorEntity, context: &Context) -> Box + Send>; fn editgroup_id_accept_post(&self, id: i64, context: &Context) -> Box + Send>; fn editgroup_id_get(&self, id: i64, context: &Context) -> Box + Send>; - fn editgroup_post(&self, body: models::Editgroup, context: &Context) -> Box + Send>; + fn editgroup_post(&self, entity: models::Editgroup, context: &Context) -> Box + Send>; fn editor_username_changelog_get(&self, username: String, context: &Context) -> Box + Send>; @@ -282,17 +282,17 @@ pub trait Api { fn file_lookup_get(&self, sha1: String, context: &Context) -> Box + Send>; - fn file_post(&self, body: models::FileEntity, context: &Context) -> Box + Send>; + fn file_post(&self, entity: models::FileEntity, context: &Context) -> Box + Send>; fn release_id_get(&self, id: String, context: &Context) -> Box + Send>; fn release_lookup_get(&self, doi: String, context: &Context) -> Box + Send>; - fn release_post(&self, body: models::ReleaseEntity, context: &Context) -> Box + Send>; + fn release_post(&self, entity: models::ReleaseEntity, context: &Context) -> Box + Send>; fn work_id_get(&self, id: String, context: &Context) -> Box + Send>; - fn work_post(&self, body: models::WorkEntity, context: &Context) -> Box + Send>; + fn work_post(&self, entity: models::WorkEntity, context: &Context) -> Box + Send>; } /// API without a `Context` @@ -301,19 +301,19 @@ pub trait ApiNoContext { fn container_lookup_get(&self, issnl: String) -> Box + Send>; - fn container_post(&self, body: models::ContainerEntity) -> Box + Send>; + fn container_post(&self, entity: models::ContainerEntity) -> Box + Send>; fn creator_id_get(&self, id: String) -> Box + Send>; fn creator_lookup_get(&self, orcid: String) -> Box + Send>; - fn creator_post(&self, body: models::CreatorEntity) -> Box + Send>; + fn creator_post(&self, entity: models::CreatorEntity) -> Box + Send>; fn editgroup_id_accept_post(&self, id: i64) -> Box + Send>; fn editgroup_id_get(&self, id: i64) -> Box + Send>; - fn editgroup_post(&self, body: models::Editgroup) -> Box + Send>; + fn editgroup_post(&self, entity: models::Editgroup) -> Box + Send>; fn editor_username_changelog_get(&self, username: String) -> Box + Send>; @@ -323,17 +323,17 @@ pub trait ApiNoContext { fn file_lookup_get(&self, sha1: String) -> Box + Send>; - fn file_post(&self, body: models::FileEntity) -> Box + Send>; + fn file_post(&self, entity: models::FileEntity) -> Box + Send>; fn release_id_get(&self, id: String) -> Box + Send>; fn release_lookup_get(&self, doi: String) -> Box + Send>; - fn release_post(&self, body: models::ReleaseEntity) -> Box + Send>; + fn release_post(&self, entity: models::ReleaseEntity) -> Box + Send>; fn work_id_get(&self, id: String) -> Box + Send>; - fn work_post(&self, body: models::WorkEntity) -> Box + Send>; + fn work_post(&self, entity: models::WorkEntity) -> Box + Send>; } /// Trait to extend an API to make it easy to bind it to a context. @@ -360,8 +360,8 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().container_lookup_get(issnl, &self.context()) } - fn container_post(&self, body: models::ContainerEntity) -> Box + Send> { - self.api().container_post(body, &self.context()) + fn container_post(&self, entity: models::ContainerEntity) -> Box + Send> { + self.api().container_post(entity, &self.context()) } fn creator_id_get(&self, id: String) -> Box + Send> { @@ -372,8 +372,8 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().creator_lookup_get(orcid, &self.context()) } - fn creator_post(&self, body: models::CreatorEntity) -> Box + Send> { - self.api().creator_post(body, &self.context()) + fn creator_post(&self, entity: models::CreatorEntity) -> Box + Send> { + self.api().creator_post(entity, &self.context()) } fn editgroup_id_accept_post(&self, id: i64) -> Box + Send> { @@ -384,8 +384,8 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().editgroup_id_get(id, &self.context()) } - fn editgroup_post(&self, body: models::Editgroup) -> Box + Send> { - self.api().editgroup_post(body, &self.context()) + fn editgroup_post(&self, entity: models::Editgroup) -> Box + Send> { + self.api().editgroup_post(entity, &self.context()) } fn editor_username_changelog_get(&self, username: String) -> Box + Send> { @@ -404,8 +404,8 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().file_lookup_get(sha1, &self.context()) } - fn file_post(&self, body: models::FileEntity) -> Box + Send> { - self.api().file_post(body, &self.context()) + fn file_post(&self, entity: models::FileEntity) -> Box + Send> { + self.api().file_post(entity, &self.context()) } fn release_id_get(&self, id: String) -> Box + Send> { @@ -416,16 +416,16 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> { self.api().release_lookup_get(doi, &self.context()) } - fn release_post(&self, body: models::ReleaseEntity) -> Box + Send> { - self.api().release_post(body, &self.context()) + fn release_post(&self, entity: models::ReleaseEntity) -> Box + Send> { + self.api().release_post(entity, &self.context()) } fn work_id_get(&self, id: String) -> Box + Send> { self.api().work_id_get(id, &self.context()) } - fn work_post(&self, body: models::WorkEntity) -> Box + Send> { - self.api().work_post(body, &self.context()) + fn work_post(&self, entity: models::WorkEntity) -> Box + Send> { + self.api().work_post(entity, &self.context()) } } diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs index b05c0fc1..24c66f6b 100644 --- a/rust/fatcat-api/src/models.rs +++ b/rust/fatcat-api/src/models.rs @@ -290,37 +290,37 @@ impl Editor { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct EntityEdit { - #[serde(rename = "extra")] - #[serde(skip_serializing_if = "Option::is_none")] - pub extra: Option, - - #[serde(rename = "editgroup_id")] - pub editgroup_id: i64, + #[serde(rename = "edit_id")] + pub edit_id: i64, - #[serde(rename = "redirect_ident")] - #[serde(skip_serializing_if = "Option::is_none")] - pub redirect_ident: Option, + #[serde(rename = "ident")] + pub ident: String, #[serde(rename = "revision")] #[serde(skip_serializing_if = "Option::is_none")] pub revision: Option, - #[serde(rename = "ident")] - pub ident: String, + #[serde(rename = "redirect_ident")] + #[serde(skip_serializing_if = "Option::is_none")] + pub redirect_ident: Option, - #[serde(rename = "edit_id")] - pub edit_id: i64, + #[serde(rename = "editgroup_id")] + pub editgroup_id: i64, + + #[serde(rename = "extra")] + #[serde(skip_serializing_if = "Option::is_none")] + pub extra: Option, } impl EntityEdit { - pub fn new(editgroup_id: i64, ident: String, edit_id: i64) -> EntityEdit { + pub fn new(edit_id: i64, ident: String, editgroup_id: i64) -> EntityEdit { EntityEdit { - extra: None, - editgroup_id: editgroup_id, - redirect_ident: None, - revision: None, - ident: ident, edit_id: edit_id, + ident: ident, + revision: None, + redirect_ident: None, + editgroup_id: editgroup_id, + extra: None, } } } diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs index ed012478..7fdc5d2a 100644 --- a/rust/fatcat-api/src/server.rs +++ b/rust/fatcat-api/src/server.rs @@ -276,27 +276,27 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_body = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?; + let param_entity = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_body: Option = + 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 body - doesn't match schema: {}", e))))?; + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - param_body + param_entity } else { None }; - let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.container_post(param_body, context).wait() { + match api.container_post(param_entity, context).wait() { Ok(rsp) => match rsp { ContainerPostResponse::CreatedEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -554,26 +554,27 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_body = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?; + let param_entity = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_body: 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 body - 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_body + param_entity } else { None }; - let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.creator_post(param_body, context).wait() { + match api.creator_post(param_entity, context).wait() { Ok(rsp) => match rsp { CreatorPostResponse::CreatedEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -835,26 +836,26 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_body = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?; + let param_entity = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_body: Option = serde_ignored::deserialize(deserializer, |path| { + let param_entity: Option = serde_ignored::deserialize(deserializer, |path| { warn!("Ignoring unknown field in body: {}", path); unused_elements.push(path.to_string()); - }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - doesn't match schema: {}", e))))?; + }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - doesn't match schema: {}", e))))?; - param_body + param_entity } else { None }; - let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.editgroup_post(param_body, context).wait() { + match api.editgroup_post(param_entity, context).wait() { Ok(rsp) => match rsp { EditgroupPostResponse::SuccessfullyCreated(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -1256,26 +1257,27 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_body = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?; + let param_entity = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_body: 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 body - 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_body + param_entity } else { None }; - let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.file_post(param_body, context).wait() { + match api.file_post(param_entity, context).wait() { Ok(rsp) => match rsp { FilePostResponse::CreatedEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -1533,26 +1535,27 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_body = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?; + let param_entity = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_body: 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 body - 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_body + param_entity } else { None }; - let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.release_post(param_body, context).wait() { + match api.release_post(param_entity, context).wait() { Ok(rsp) => match rsp { ReleasePostResponse::CreatedEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); @@ -1726,26 +1729,27 @@ where // values, rather than causing a 400 response). Produce warning header and logs for // any unused fields. - let param_body = req.get::() - .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?; + let param_entity = req.get::() + .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter entity - not valid UTF-8: {}", e))))?; let mut unused_elements = Vec::new(); - let param_body = if let Some(param_body_raw) = param_body { - let deserializer = &mut serde_json::Deserializer::from_str(¶m_body_raw); + let param_entity = if let Some(param_entity_raw) = param_entity { + let deserializer = &mut serde_json::Deserializer::from_str(¶m_entity_raw); - let param_body: 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 body - 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_body + param_entity } else { None }; - let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?; + let param_entity = param_entity.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity".to_string())))?; - match api.work_post(param_body, context).wait() { + match api.work_post(param_entity, context).wait() { Ok(rsp) => match rsp { WorkPostResponse::CreatedEntity(body) => { let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize"); -- cgit v1.2.3