aboutsummaryrefslogtreecommitdiffstats
path: root/rust/fatcat-api/src
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
parent9036469324912eae3eed8cb8645f91f1a68c5857 (diff)
downloadfatcat-0ed087be71b02d9279bd3b131131eae672580d71.tar.gz
fatcat-0ed087be71b02d9279bd3b131131eae672580d71.zip
tweak openapi schema
Diffstat (limited to 'rust/fatcat-api/src')
-rw-r--r--rust/fatcat-api/src/client.rs50
-rw-r--r--rust/fatcat-api/src/lib.rs30
-rw-r--r--rust/fatcat-api/src/models.rs32
-rw-r--r--rust/fatcat-api/src/server.rs37
4 files changed, 72 insertions, 77 deletions
diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs
index 06633ad9..6666d6f4 100644
--- a/rust/fatcat-api/src/client.rs
+++ b/rust/fatcat-api/src/client.rs
@@ -277,18 +277,16 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn container_post(&self, param_body: Option<models::ContainerEntity>, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> {
+ fn container_post(&self, param_body: models::ContainerEntity, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> {
let url = format!("{}/v0/container", self.base_path);
- let body = param_body.map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize"));
+ let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
+
let hyper_client = (self.hyper_client)();
let request = hyper_client.request(hyper::method::Method::Post, &url);
let mut custom_headers = hyper::header::Headers::new();
- let request = match body {
- Some(ref body) => request.body(body),
- None => request,
- };
+ let request = request.body(&body);
custom_headers.set(ContentType(mimetypes::requests::CONTAINER_POST.clone()));
context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone())));
@@ -453,18 +451,16 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn creator_post(&self, param_body: Option<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> {
+ fn creator_post(&self, param_body: models::CreatorEntity, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> {
let url = format!("{}/v0/creator", self.base_path);
- let body = param_body.map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize"));
+ let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
+
let hyper_client = (self.hyper_client)();
let request = hyper_client.request(hyper::method::Method::Post, &url);
let mut custom_headers = hyper::header::Headers::new();
- let request = match body {
- Some(ref body) => request.body(body),
- None => request,
- };
+ let request = request.body(&body);
custom_headers.set(ContentType(mimetypes::requests::CREATOR_POST.clone()));
context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone())));
@@ -909,18 +905,16 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn file_post(&self, param_body: Option<models::FileEntity>, context: &Context) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> {
+ fn file_post(&self, param_body: models::FileEntity, context: &Context) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> {
let url = format!("{}/v0/file", self.base_path);
- let body = param_body.map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize"));
+ let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
+
let hyper_client = (self.hyper_client)();
let request = hyper_client.request(hyper::method::Method::Post, &url);
let mut custom_headers = hyper::header::Headers::new();
- let request = match body {
- Some(ref body) => request.body(body),
- None => request,
- };
+ let request = request.body(&body);
custom_headers.set(ContentType(mimetypes::requests::FILE_POST.clone()));
context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone())));
@@ -1085,18 +1079,16 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn release_post(&self, param_body: Option<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> {
+ fn release_post(&self, param_body: models::ReleaseEntity, context: &Context) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> {
let url = format!("{}/v0/release", self.base_path);
- let body = param_body.map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize"));
+ let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
+
let hyper_client = (self.hyper_client)();
let request = hyper_client.request(hyper::method::Method::Post, &url);
let mut custom_headers = hyper::header::Headers::new();
- let request = match body {
- Some(ref body) => request.body(body),
- None => request,
- };
+ let request = request.body(&body);
custom_headers.set(ContentType(mimetypes::requests::RELEASE_POST.clone()));
context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone())));
@@ -1198,18 +1190,16 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn work_post(&self, param_body: Option<models::WorkEntity>, context: &Context) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> {
+ fn work_post(&self, param_body: models::WorkEntity, context: &Context) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> {
let url = format!("{}/v0/work", self.base_path);
- let body = param_body.map(|ref body| serde_json::to_string(body).expect("impossible to fail to serialize"));
+ let body = serde_json::to_string(&param_body).expect("impossible to fail to serialize");
+
let hyper_client = (self.hyper_client)();
let request = hyper_client.request(hyper::method::Method::Post, &url);
let mut custom_headers = hyper::header::Headers::new();
- let request = match body {
- Some(ref body) => request.body(body),
- None => request,
- };
+ let request = request.body(&body);
custom_headers.set(ContentType(mimetypes::requests::WORK_POST.clone()));
context.x_span_id.as_ref().map(|header| custom_headers.set(XSpanId(header.clone())));
diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs
index a01189ef..151c3a4a 100644
--- a/rust/fatcat-api/src/lib.rs
+++ b/rust/fatcat-api/src/lib.rs
@@ -238,13 +238,13 @@ pub trait Api {
fn container_lookup_get(&self, issn: String, context: &Context) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>;
- fn container_post(&self, body: Option<models::ContainerEntity>, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>;
+ fn container_post(&self, body: models::ContainerEntity, context: &Context) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>;
fn creator_id_get(&self, id: String, context: &Context) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send>;
fn creator_lookup_get(&self, orcid: String, context: &Context) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send>;
- fn creator_post(&self, body: Option<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>;
+ fn creator_post(&self, body: models::CreatorEntity, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>;
fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>;
@@ -260,17 +260,17 @@ pub trait Api {
fn file_lookup_get(&self, sha1: String, context: &Context) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send>;
- fn file_post(&self, body: Option<models::FileEntity>, context: &Context) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>;
+ fn file_post(&self, body: models::FileEntity, context: &Context) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>;
fn release_id_get(&self, id: String, context: &Context) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send>;
fn release_lookup_get(&self, doi: String, context: &Context) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send>;
- fn release_post(&self, body: Option<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>;
+ fn release_post(&self, body: models::ReleaseEntity, context: &Context) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>;
fn work_id_get(&self, id: String, context: &Context) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send>;
- fn work_post(&self, body: Option<models::WorkEntity>, context: &Context) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>;
+ fn work_post(&self, body: models::WorkEntity, context: &Context) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>;
}
/// API without a `Context`
@@ -279,13 +279,13 @@ pub trait ApiNoContext {
fn container_lookup_get(&self, issn: String) -> Box<Future<Item = ContainerLookupGetResponse, Error = ApiError> + Send>;
- fn container_post(&self, body: Option<models::ContainerEntity>) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>;
+ fn container_post(&self, body: models::ContainerEntity) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send>;
fn creator_id_get(&self, id: String) -> Box<Future<Item = CreatorIdGetResponse, Error = ApiError> + Send>;
fn creator_lookup_get(&self, orcid: String) -> Box<Future<Item = CreatorLookupGetResponse, Error = ApiError> + Send>;
- fn creator_post(&self, body: Option<models::CreatorEntity>) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>;
+ fn creator_post(&self, body: models::CreatorEntity) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>;
fn editgroup_id_accept_post(&self, id: i32) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>;
@@ -301,17 +301,17 @@ pub trait ApiNoContext {
fn file_lookup_get(&self, sha1: String) -> Box<Future<Item = FileLookupGetResponse, Error = ApiError> + Send>;
- fn file_post(&self, body: Option<models::FileEntity>) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>;
+ fn file_post(&self, body: models::FileEntity) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send>;
fn release_id_get(&self, id: String) -> Box<Future<Item = ReleaseIdGetResponse, Error = ApiError> + Send>;
fn release_lookup_get(&self, doi: String) -> Box<Future<Item = ReleaseLookupGetResponse, Error = ApiError> + Send>;
- fn release_post(&self, body: Option<models::ReleaseEntity>) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>;
+ fn release_post(&self, body: models::ReleaseEntity) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send>;
fn work_id_get(&self, id: String) -> Box<Future<Item = WorkIdGetResponse, Error = ApiError> + Send>;
- fn work_post(&self, body: Option<models::WorkEntity>) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>;
+ fn work_post(&self, body: models::WorkEntity) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send>;
}
/// Trait to extend an API to make it easy to bind it to a context.
@@ -338,7 +338,7 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().container_lookup_get(issn, &self.context())
}
- fn container_post(&self, body: Option<models::ContainerEntity>) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> {
+ fn container_post(&self, body: models::ContainerEntity) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> {
self.api().container_post(body, &self.context())
}
@@ -350,7 +350,7 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().creator_lookup_get(orcid, &self.context())
}
- fn creator_post(&self, body: Option<models::CreatorEntity>) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> {
+ fn creator_post(&self, body: models::CreatorEntity) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> {
self.api().creator_post(body, &self.context())
}
@@ -382,7 +382,7 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().file_lookup_get(sha1, &self.context())
}
- fn file_post(&self, body: Option<models::FileEntity>) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> {
+ fn file_post(&self, body: models::FileEntity) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> {
self.api().file_post(body, &self.context())
}
@@ -394,7 +394,7 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().release_lookup_get(doi, &self.context())
}
- fn release_post(&self, body: Option<models::ReleaseEntity>) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> {
+ fn release_post(&self, body: models::ReleaseEntity) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> {
self.api().release_post(body, &self.context())
}
@@ -402,7 +402,7 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().work_id_get(id, &self.context())
}
- fn work_post(&self, body: Option<models::WorkEntity>) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> {
+ fn work_post(&self, body: models::WorkEntity) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> {
self.api().work_post(body, &self.context())
}
}
diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs
index 5e5be35f..b6f450aa 100644
--- a/rust/fatcat-api/src/models.rs
+++ b/rust/fatcat-api/src/models.rs
@@ -47,8 +47,7 @@ pub struct ContainerEntity {
pub parent: Option<String>,
#[serde(rename = "name")]
- #[serde(skip_serializing_if = "Option::is_none")]
- pub name: Option<String>,
+ pub name: String,
// Note: inline enums are not fully supported by swagger-codegen
#[serde(rename = "state")]
@@ -73,12 +72,12 @@ pub struct ContainerEntity {
}
impl ContainerEntity {
- pub fn new() -> ContainerEntity {
+ pub fn new(name: String) -> ContainerEntity {
ContainerEntity {
issn: None,
publisher: None,
parent: None,
- name: None,
+ name: name,
state: None,
ident: None,
revision: None,
@@ -95,8 +94,7 @@ pub struct CreatorEntity {
pub orcid: Option<String>,
#[serde(rename = "name")]
- #[serde(skip_serializing_if = "Option::is_none")]
- pub name: Option<String>,
+ pub name: String,
#[serde(rename = "editgroup")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -121,10 +119,10 @@ pub struct CreatorEntity {
}
impl CreatorEntity {
- pub fn new() -> CreatorEntity {
+ pub fn new(name: String) -> CreatorEntity {
CreatorEntity {
orcid: None,
- name: None,
+ name: name,
editgroup: None,
redirect: None,
revision: None,
@@ -137,15 +135,16 @@ impl CreatorEntity {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Editgroup {
#[serde(rename = "id")]
- pub id: isize,
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub id: Option<isize>,
#[serde(rename = "editor_id")]
pub editor_id: isize,
}
impl Editgroup {
- pub fn new(id: isize, editor_id: isize) -> Editgroup {
- Editgroup { id: id, editor_id: editor_id }
+ pub fn new(editor_id: isize) -> Editgroup {
+ Editgroup { id: None, editor_id: editor_id }
}
}
@@ -175,9 +174,9 @@ pub struct EntityEdit {
#[serde(skip_serializing_if = "Option::is_none")]
pub ident: Option<String>,
- #[serde(rename = "id")]
+ #[serde(rename = "edit_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub id: Option<isize>,
+ pub edit_id: Option<isize>,
}
impl EntityEdit {
@@ -186,7 +185,7 @@ impl EntityEdit {
editgroup_id: None,
revision: None,
ident: None,
- id: None,
+ edit_id: None,
}
}
}
@@ -348,10 +347,6 @@ pub struct WorkEntity {
#[serde(skip_serializing_if = "Option::is_none")]
pub work_type: Option<String>,
- #[serde(rename = "title")]
- #[serde(skip_serializing_if = "Option::is_none")]
- pub title: Option<String>,
-
#[serde(rename = "editgroup")]
#[serde(skip_serializing_if = "Option::is_none")]
pub editgroup: Option<isize>,
@@ -378,7 +373,6 @@ impl WorkEntity {
pub fn new() -> WorkEntity {
WorkEntity {
work_type: None,
- title: None,
editgroup: None,
redirect: None,
revision: None,
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 {