aboutsummaryrefslogtreecommitdiffstats
path: root/rust/fatcat-api/src/server.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-15 21:17:09 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-15 21:17:09 -0700
commit0ed087be71b02d9279bd3b131131eae672580d71 (patch)
treeda4bc59d4db19ae466c86992c1e625bf0797584e /rust/fatcat-api/src/server.rs
parent9036469324912eae3eed8cb8645f91f1a68c5857 (diff)
downloadfatcat-0ed087be71b02d9279bd3b131131eae672580d71.tar.gz
fatcat-0ed087be71b02d9279bd3b131131eae672580d71.zip
tweak openapi schema
Diffstat (limited to 'rust/fatcat-api/src/server.rs')
-rw-r--r--rust/fatcat-api/src/server.rs37
1 files changed, 24 insertions, 13 deletions
diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs
index 5e799bd4..94668aa9 100644
--- a/rust/fatcat-api/src/server.rs
+++ b/rust/fatcat-api/src/server.rs
@@ -268,22 +268,25 @@ where
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
- let param_body = req.get::<bodyparser::Raw>().unwrap_or(None);
+ let param_body = req.get::<bodyparser::Raw>()
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - 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(&param_body_raw);
- let param_body: Option<models::ContainerEntity> = serde_ignored::deserialize(deserializer, |path| {
- warn!("Ignoring unknown field in body: {}", path);
- unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ let param_body: Option<models::ContainerEntity> =
+ 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))))?;
param_body
} else {
None
};
+ let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?;
match api.container_post(param_body, context).wait() {
Ok(rsp) => match rsp {
@@ -523,7 +526,8 @@ where
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
- let param_body = req.get::<bodyparser::Raw>().unwrap_or(None);
+ let param_body = req.get::<bodyparser::Raw>()
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?;
let mut unused_elements = Vec::new();
@@ -533,12 +537,13 @@ where
let param_body: Option<models::CreatorEntity> = serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - doesn't match schema: {}", e))))?;
param_body
} else {
None
};
+ let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?;
match api.creator_post(param_body, context).wait() {
Ok(rsp) => match rsp {
@@ -1168,7 +1173,8 @@ where
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
- let param_body = req.get::<bodyparser::Raw>().unwrap_or(None);
+ let param_body = req.get::<bodyparser::Raw>()
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?;
let mut unused_elements = Vec::new();
@@ -1178,12 +1184,13 @@ where
let param_body: Option<models::FileEntity> = serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - doesn't match schema: {}", e))))?;
param_body
} else {
None
};
+ let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?;
match api.file_post(param_body, context).wait() {
Ok(rsp) => match rsp {
@@ -1423,7 +1430,8 @@ where
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
- let param_body = req.get::<bodyparser::Raw>().unwrap_or(None);
+ let param_body = req.get::<bodyparser::Raw>()
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?;
let mut unused_elements = Vec::new();
@@ -1433,12 +1441,13 @@ where
let param_body: Option<models::ReleaseEntity> = serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - doesn't match schema: {}", e))))?;
param_body
} else {
None
};
+ let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?;
match api.release_post(param_body, context).wait() {
Ok(rsp) => match rsp {
@@ -1592,7 +1601,8 @@ where
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
- let param_body = req.get::<bodyparser::Raw>().unwrap_or(None);
+ let param_body = req.get::<bodyparser::Raw>()
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - not valid UTF-8: {}", e))))?;
let mut unused_elements = Vec::new();
@@ -1602,12 +1612,13 @@ where
let param_body: Option<models::WorkEntity> = serde_ignored::deserialize(deserializer, |path| {
warn!("Ignoring unknown field in body: {}", path);
unused_elements.push(path.to_string());
- }).unwrap_or(None);
+ }).map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse body parameter body - doesn't match schema: {}", e))))?;
param_body
} else {
None
};
+ let param_body = param_body.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter body".to_string())))?;
match api.work_post(param_body, context).wait() {
Ok(rsp) => match rsp {